Module: Occi::Api::Client::Base::KindMethods

Included in:
ClientBase
Defined in:
lib/occi/api/client/base/kind_methods.rb

Instance Method Summary collapse

Instance Method Details

#get_kind_type_identifier(type) ⇒ String?

Retrieves available kind type identifier for the given kind type.

Examples:

client.get_kind_type_identifier("compute")
 # => 'http://schemas.ogf.org/occi/infrastructure#compute'

Parameters:

  • type (String)

    short kind type

Returns:

  • (String, nil)

    kind type identifier for the given kind type


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/occi/api/client/base/kind_methods.rb', line 53

def get_kind_type_identifier(type)
  return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))

  kinds = @model.kinds.to_a.select { |k| k.term == type }
  tis = kinds.collect { |k| k.type_identifier }
  tis.uniq!

  if tis.length > 1
    raise Occi::Api::Client::Errors::AmbiguousNameError,
          "Kind type #{type.inspect} is ambiguous, use a type identifier!"
  end

  tis.first
end

#get_kind_type_identifiersArray<String>

Retrieves all available kind type identifiers.

Examples:

client.get_kind_type_identifiers
# => [ "http://schemas.ogf.org/occi/core#entity",
#      "http://schemas.ogf.org/occi/core#resource",
#      "http://schemas.ogf.org/occi/core#link" ]

Returns:

  • (Array<String>)

    list of available kind type identifiers


41
42
43
# File 'lib/occi/api/client/base/kind_methods.rb', line 41

def get_kind_type_identifiers
  @model.kinds.to_a.collect { |kind| kind.type_identifier }
end

Retrieves all kind type identifiers related to a given type identifier

Examples:

client.get_kind_type_identifiers_related_to 'http://schemas.ogf.org/occi/infrastructure#network'
# => [ "http://schemas.ogf.org/occi/infrastructure#network",
#      "http://schemas.ogf.org/occi/infrastructure#ipnetwork" ]

Parameters:

  • type_identifier (String)

    type identifier

Returns:

  • (Array<String>)

    list of available kind type identifiers related to the given type identifier


16
17
18
19
20
# File 'lib/occi/api/client/base/kind_methods.rb', line 16

def get_kind_type_identifiers_related_to(type_identifier)
  Occi::Api::Log.debug("Getting kind type identifiers related to #{type_identifier.inspect}")
  collection = @model.get(type_identifier)
  collection.kinds.to_a.collect { |kind| kind.type_identifier }
end

#get_kind_typesArray<String>

Retrieves all available kind types.

Examples:

client.get_kind_types # => [ "entity", "resource", "link" ]

Returns:

  • (Array<String>)

    list of available kind types in a human-readable format


28
29
30
# File 'lib/occi/api/client/base/kind_methods.rb', line 28

def get_kind_types
  @model.kinds.to_a.collect { |kind| kind.term }
end