Module: Occi::Api::Client::Base::EntityMethods
- Included in:
- ClientBase
- Defined in:
- lib/occi/api/client/base/entity_methods.rb
Instance Method Summary collapse
-
#get_entity_type_identifier(type) ⇒ String?
Retrieves available entity type identifier for the given entity type.
-
#get_entity_type_identifiers ⇒ Array<String>
Retrieves all available entity type identifiers.
-
#get_entity_types ⇒ Array<String>
Retrieves all available entity types.
-
#get_link(link_type) ⇒ Occi::Core::Link
Creates a new link instance, link should be specified by its name or identifier.
-
#get_link_type_identifier(type) ⇒ String?
Retrieves available link type identifier for the given link type.
-
#get_link_type_identifiers ⇒ Array<String>
Retrieves all available link type identifiers.
-
#get_link_types ⇒ Array<String>
Retrieves all available link types.
-
#get_resource(resource_type) ⇒ Occi::Core::Resource
Creates a new resource instance, resource should be specified by its name or identifier.
-
#get_resource_type_identifier(type) ⇒ String?
Retrieves available resource type identifier for the given resource type.
-
#get_resource_type_identifiers ⇒ Array<String>
Retrieves all available resource type identifiers.
-
#get_resource_types ⇒ Array<String>
Retrieves all available resource types.
- #get_type_identifier(type, related_to) ⇒ Object private
- #get_types(related_to) ⇒ Object private
Instance Method Details
#get_entity_type_identifier(type) ⇒ String?
Retrieves available entity type identifier for the given entity type.
82 83 84 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 82 def get_entity_type_identifier(type) get_type_identifier(type, Occi::Core::Entity.kind) end |
#get_entity_type_identifiers ⇒ Array<String>
Retrieves all available entity type identifiers.
70 71 72 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 70 def get_entity_type_identifiers Occi::Core::Entity.kind.type_identifier end |
#get_entity_types ⇒ Array<String>
Retrieves all available entity types.
57 58 59 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 57 def get_entity_types get_types(Occi::Core::Entity.kind) end |
#get_link(link_type) ⇒ Occi::Core::Link
Creates a new link instance, link should be specified by its name or identifier.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 39 def get_link(link_type) Occi::Api::Log.debug("Instantiating #{link_type.inspect}") type_id = get_link_type_identifier(link_type) raise "Unknown link type! #{link_type.inspect}" unless type_id new_link = Occi::Core::Link.new(type_id) new_link.model = @model new_link end |
#get_link_type_identifier(type) ⇒ String?
Retrieves available link type identifier for the given link type.
151 152 153 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 151 def get_link_type_identifier(type) get_type_identifier(type, Occi::Core::Link.kind) end |
#get_link_type_identifiers ⇒ Array<String>
Retrieves all available link type identifiers.
139 140 141 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 139 def get_link_type_identifiers Occi::Core::Link.kind.type_identifier end |
#get_link_types ⇒ Array<String>
Retrieves all available link types.
127 128 129 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 127 def get_link_types get_types(Occi::Core::Link.kind) end |
#get_resource(resource_type) ⇒ Occi::Core::Resource
Creates a new resource instance, resource should be specified by its name or identifier.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 17 def get_resource(resource_type) Occi::Api::Log.debug("Instantiating #{resource_type.inspect}") type_id = get_resource_type_identifier(resource_type) raise "Unknown resource type! #{resource_type.inspect}" unless type_id new_resource = Occi::Core::Resource.new(type_id) new_resource.model = @model new_resource end |
#get_resource_type_identifier(type) ⇒ String?
Retrieves available resource type identifier for the given resource type.
117 118 119 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 117 def get_resource_type_identifier(type) get_type_identifier(type, Occi::Core::Resource.kind) end |
#get_resource_type_identifiers ⇒ Array<String>
Retrieves all available resource type identifiers.
105 106 107 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 105 def get_resource_type_identifiers Occi::Core::Resource.kind.type_identifier end |
#get_resource_types ⇒ Array<String>
Retrieves all available resource types.
92 93 94 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 92 def get_resource_types get_types(Occi::Core::Resource.kind) end |
#get_type_identifier(type, related_to) ⇒ Object (private)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 157 def get_type_identifier(type, ) return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/')) collection = @model.get(.type_identifier) e_kinds = collection.kinds.to_a.select { |e| e.term == type } tis = e_kinds.collect { |e| e.type_identifier } tis.uniq! if tis.length > 1 raise Occi::Api::Client::Errors::AmbiguousNameError, "#{.type_identifier.split('#').capitalize} type " \ "#{type.inspect} is ambiguous, use a type identifier!" end tis.first end |
#get_types(related_to) ⇒ Object (private)
174 175 176 177 |
# File 'lib/occi/api/client/base/entity_methods.rb', line 174 def get_types() collection = @model.get(.type_identifier) collection ? collection.kinds.to_a.collect { |kind| kind.term } : [] end |