Class: Occi::Core::Resource
Overview
Implements the base class for all OCCI resources, this class can be used directly to create resource instances.
Direct Known Subclasses
Infrastructure::Compute, Infrastructure::Network, Infrastructure::Storage, InfrastructureExt::SecurityGroup
Constant Summary
Constants inherited from Entity
Constants included from Helpers::Renderable
Helpers::Renderable::RENDERER_FACTORY_CLASS
Instance Attribute Summary collapse
-
#links ⇒ Set
set of links associated with this resource instance.
-
#summary ⇒ String
Resource summary.
Attributes inherited from Entity
#actions, #attributes, #id, #kind, #location, #mixins, #title
Instance Method Summary collapse
-
#<<(object) ⇒ Object
:nodoc:.
-
#add_link(link) ⇒ Object
Adds the given link to this instance.
-
#links_by_kind(kind) ⇒ Object
:nodoc:.
-
#links_by_kind_identifier(kind_identifier) ⇒ Object
:nodoc:.
-
#links_by_klass(klass) ⇒ Object
:nodoc:.
-
#remove(object) ⇒ Object
:nodoc:.
-
#remove_link(link) ⇒ Object
Removes the given link from this instance.
-
#valid! ⇒ Object
See ‘#valid!` on `Occi::Core::Entity`.
Methods inherited from Entity
#add_action, #add_mixin, #added_attributes, #availability_zone, #availability_zones, #base_attributes, #disable_action, #enable_action, #identify!, #initialize, #kind_identifier, #region, #regions, #remove_action, #remove_mixin, #replace_mixin, #valid?
Methods included from Helpers::MixinSelector
#dependent_term, #dependent_term!, #dependent_terms, #select_mixin, #select_mixin!, #select_mixins
Methods included from Helpers::InstanceAttributeResetter
#attribute_names, #remove_undef_attributes, #reset_added_attributes, #reset_added_attributes!, #reset_attribute, #reset_attributes, #reset_attributes!, #reset_base_attributes, #reset_base_attributes!
Methods included from Helpers::InstanceAttributesAccessor
Methods included from Helpers::Locatable
Methods included from Helpers::Renderable
extended, included, #render, #renderer_factory, renderer_factory, renderer_factory_class, #renderer_for
Constructor Details
This class inherits a constructor from Occi::Core::Entity
Instance Attribute Details
#links ⇒ Set
set of links associated with this resource instance
10 11 12 |
# File 'lib/occi/core/resource.rb', line 10 def links @links end |
#summary ⇒ String
Returns resource summary.
10 11 12 |
# File 'lib/occi/core/resource.rb', line 10 def summary @summary end |
Instance Method Details
#<<(object) ⇒ Object
:nodoc:
35 36 37 38 39 40 41 42 43 |
# File 'lib/occi/core/resource.rb', line 35 def <<(object) case object when Occi::Core::Link add_link(object) return self end super end |
#add_link(link) ⇒ Object
Adds the given link to this instance.
59 60 61 62 63 64 65 |
# File 'lib/occi/core/resource.rb', line 59 def add_link(link) raise Occi::Core::Errors::MandatoryArgumentError, 'Cannot add a non-existent link' unless link link.source = location link.source_kind = kind links << link end |
#links_by_kind(kind) ⇒ Object
:nodoc:
92 93 94 |
# File 'lib/occi/core/resource.rb', line 92 def links_by_kind(kind) links.select { |l| l.kind == kind } end |
#links_by_kind_identifier(kind_identifier) ⇒ Object
:nodoc:
97 98 99 |
# File 'lib/occi/core/resource.rb', line 97 def links_by_kind_identifier(kind_identifier) links.select { |l| l.kind_identifier == kind_identifier } end |
#links_by_klass(klass) ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/occi/core/resource.rb', line 87 def links_by_klass(klass) links.select { |l| l.is_a?(klass) } end |
#remove(object) ⇒ Object
:nodoc:
46 47 48 49 50 51 52 53 54 |
# File 'lib/occi/core/resource.rb', line 46 def remove(object) case object when Occi::Core::Link remove_link(object) return self end super end |
#remove_link(link) ⇒ Object
Removes the given link from this instance.
70 71 72 73 74 75 76 |
# File 'lib/occi/core/resource.rb', line 70 def remove_link(link) raise Occi::Core::Errors::MandatoryArgumentError, 'Cannot remove a non-existent link' unless link link.source = nil link.source_kind = nil links.delete link end |
#valid! ⇒ Object
See ‘#valid!` on `Occi::Core::Entity`.
79 80 81 82 83 84 |
# File 'lib/occi/core/resource.rb', line 79 def valid! super raise Occi::Core::Errors::InstanceValidationError, 'Missing valid links' unless links links.each(&:valid!) end |