Class: Occi::Core::Resource

Inherits:
Entity
  • Object
show all
Defined in:
lib/occi/core/resource.rb

Overview

Implements the base class for all OCCI resources, this class can be used directly to create resource instances.

Author:

Constant Summary

Constants inherited from Entity

Entity::ERRORS

Constants included from Helpers::Renderable

Helpers::Renderable::RENDERER_FACTORY_CLASS

Instance Attribute Summary collapse

Attributes inherited from Entity

#actions, #attributes, #id, #kind, #location, #mixins, #title

Instance Method Summary collapse

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

#[], #[]=, #attribute?

Methods included from Helpers::Locatable

#location

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

set of links associated with this resource instance


10
11
12
# File 'lib/occi/core/resource.rb', line 10

def links
  @links
end

#summaryString


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

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

:nodoc:


92
93
94
# File 'lib/occi/core/resource.rb', line 92

def links_by_kind(kind)
  links.select { |l| l.kind == kind }
end

: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

: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

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