Module: Occi::Api::Client::Base::MixinMethods
- Included in:
- ClientBase
- Defined in:
- lib/occi/api/client/base/mixin_methods.rb
Instance Method Summary collapse
-
#describe_mixin(name, type = nil) ⇒ Occi::Core::Mixin?
Looks up a mixin using its name and, optionally, a type as well.
-
#describe_mixin_w_type(name, type) ⇒ Occi::Core::Mixin
Looks up a mixin with a specific type, will return mixin's full description.
-
#describe_mixin_wo_type(name) ⇒ Occi::Core::Mixin
Looks up a mixin in all available mixin types, will return mixin's full description.
-
#get_mixin(name, type = nil, describe = false) ⇒ String, ...
Looks up a mixin using its name and, optionally, a type as well.
-
#get_mixin_type_identifier(type) ⇒ String?
Retrieves available mixin type identifier for the given mixin type.
-
#get_mixin_type_identifiers ⇒ Array<String>
Retrieves available mixin type identifiers.
-
#get_mixin_types ⇒ Array<String>
Retrieves available mixin types.
-
#get_mixins(type = nil, include_self = false) ⇒ Occi::Core::Mixins
Retrieves available mixins of a specified type or all available mixins if the type wasn't specified.
-
#get_os_templates ⇒ Occi::Core::Mixins
(also: #get_os_tpls)
Retrieves available os_tpls from the model.
-
#get_resource_templates ⇒ Occi::Core::Mixins
(also: #get_resource_tpls)
Retrieves available resource_tpls from the model.
-
#list_mixin(name, type = nil) ⇒ String?
Looks up a mixin using its name and, optionally, a type as well.
-
#list_mixins(type = nil, include_self = false) ⇒ Array<String>
Retrieves available mixins of a specified type or all available mixins if the type wasn't specified.
Instance Method Details
#describe_mixin(name, type = nil) ⇒ Occi::Core::Mixin?
Looks up a mixin using its name and, optionally, a type as well. Will return mixin's full description.
47 48 49 50 51 52 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 47 def describe_mixin(name, type = nil) mixins = get_mixins(type) mixins = mixins.to_a.select { |m| m.term == name } mixins.any? ? mixins.first : nil end |
#describe_mixin_w_type(name, type) ⇒ Occi::Core::Mixin
Looks up a mixin with a specific type, will return mixin's full description.
60 61 62 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 60 def describe_mixin_w_type(name, type) describe_mixin(name, type) end |
#describe_mixin_wo_type(name) ⇒ Occi::Core::Mixin
Looks up a mixin in all available mixin types, will return mixin's full description. Returns always the first match found, search will start in os_tpl.
70 71 72 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 70 def describe_mixin_wo_type(name) describe_mixin(name, nil) end |
#get_mixin(name, type = nil, describe = false) ⇒ String, ...
Looks up a mixin using its name and, optionally, a type as well. Will return mixin's full location (a link) or a description.
22 23 24 25 26 27 28 29 30 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 22 def get_mixin(name, type = nil, describe = false) # TODO: mixin fix Occi::Api::Log.debug "Looking for mixin #{name.inspect} #{type.inspect} " \ "#{describe.inspect}" # TODO: extend this code to support multiple matches and regex filters # should we look for links or descriptions? describe ? describe_mixin(name, type) : list_mixin(name, type) end |
#get_mixin_type_identifier(type) ⇒ String?
Retrieves available mixin type identifier for the given mixin type.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 187 def get_mixin_type_identifier(type) return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/')) mixins = @model.mixins.to_a.select { |m| m.term == type } tis = mixins.collect { |m| m.type_identifier } tis.uniq! if tis.length > 1 raise Occi::Api::Client::Errors::AmbiguousNameError, "Mixin type #{type.inspect} is ambiguous, use a type identifier!" end tis.first end |
#get_mixin_type_identifiers ⇒ Array<String>
Retrieves available mixin type identifiers.
175 176 177 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 175 def get_mixin_type_identifiers list_mixins(nil) end |
#get_mixin_types ⇒ Array<String>
Retrieves available mixin types. Mixin types are presented in a shortened format (i.e. not as type identifiers).
163 164 165 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 163 def get_mixin_types get_mixins.to_a.collect { |m| m.term } end |
#get_mixins(type = nil, include_self = false) ⇒ Occi::Core::Mixins
Retrieves available mixins of a specified type or all available mixins if the type wasn't specified. Mixins are returned in the form of mixin instances.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 109 def get_mixins(type = nil, include_self = false) unless type.blank? type_id = get_mixin_type_identifier(type) unless type_id raise ArgumentError, "There is no such mixin type registered in the model! #{type.inspect}" end mixins = @model.mixins.to_a.select { |m| m.(type_id) } # drop the type mixin itself mixins.delete_if { |m| m.type_identifier == type_id } unless include_self else # we did not get a type, return all mixins mixins = Occi::Core::Mixins.new(@model.mixins) end unless mixins.kind_of? Occi::Core::Mixins col = Occi::Core::Mixins.new mixins.each { |m| col << m } else col = mixins end col end |
#get_os_templates ⇒ Occi::Core::Mixins Also known as: get_os_tpls
Retrieves available os_tpls from the model.
208 209 210 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 208 def get_os_templates get_mixins Occi::Infrastructure::OsTpl.mixin.type_identifier end |
#get_resource_templates ⇒ Occi::Core::Mixins Also known as: get_resource_tpls
Retrieves available resource_tpls from the model.
219 220 221 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 219 def get_resource_templates get_mixins Occi::Infrastructure::ResourceTpl.mixin.type_identifier end |
#list_mixin(name, type = nil) ⇒ String?
Looks up a mixin using its name and, optionally, a type as well. Will return mixin's full location.
89 90 91 92 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 89 def list_mixin(name, type = nil) mixin = describe_mixin(name, type) mixin ? mixin.type_identifier : nil end |
#list_mixins(type = nil, include_self = false) ⇒ Array<String>
Retrieves available mixins of a specified type or all available mixins if the type wasn't specified. Mixins are returned in the form of mixin identifiers.
151 152 153 154 |
# File 'lib/occi/api/client/base/mixin_methods.rb', line 151 def list_mixins(type = nil, include_self = false) mixins = get_mixins(type, include_self) mixins.to_a.collect { |m| m.type_identifier } end |