Class: Occi::Core::Resource
Direct Known Subclasses
Infrastructure::Compute, Infrastructure::Network, Infrastructure::Storage
Instance Attribute Summary collapse
-
#links ⇒ Object
Returns the value of attribute links.
Attributes inherited from Entity
#actions, #attributes, #id, #kind, #mixins, #model
Instance Method Summary collapse
-
#as_json(options = { }) ⇒ Hashie::Mash
Link as Hashie::Mash to be parsed into a JSON object.
- #initialize(kind = self.kind, mixins = [], attributes = { }, actions = [], links = []) ⇒ Occi::Core::Resource constructor
- #link(target, kind = Occi::Core::Link.kind, mixins = [], attributes = Occi::Core::Attributes.new, rel = Occi::Core::Resource.type_identifier) ⇒ Object
- #model=(model) ⇒ Object
-
#summary ⇒ String
Summary attribute of the resource.
-
#summary=(summary) ⇒ Object
set summary attribute of resource.
-
#to_header ⇒ Hash
Hash containing the HTTP headers of the text/occi rendering.
-
#to_text ⇒ String
Text representation.
Methods inherited from Entity
check, #check, #inspect, #location, new, #title, #title=, #to_s, type_identifier
Constructor Details
#initialize(kind = self.kind, mixins = [], attributes = { }, actions = [], links = []) ⇒ Occi::Core::Resource
20 21 22 23 |
# File 'lib/occi/core/resource.rb', line 20 def initialize(kind=self.kind, mixins=[], attributes={ }, actions=[], links=[]) super(kind, mixins, attributes, actions) @links = Occi::Core::Links.new(links) end |
Instance Attribute Details
#links ⇒ Object
Returns the value of attribute links.
5 6 7 |
# File 'lib/occi/core/resource.rb', line 5 def links @links end |
Instance Method Details
#as_json(options = { }) ⇒ Hashie::Mash
Returns link as Hashie::Mash to be parsed into a JSON object.
67 68 69 70 71 72 |
# File 'lib/occi/core/resource.rb', line 67 def as_json(={ }) resource = super link_strings = @links.collect { |link| link.to_s if link.to_s }.compact resource.links = link_strings unless link_strings.empty? resource end |
#link(target, kind = Occi::Core::Link.kind, mixins = [], attributes = Occi::Core::Attributes.new, rel = Occi::Core::Resource.type_identifier) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/occi/core/resource.rb', line 41 def link(target, kind=Occi::Core::Link.kind, mixins=[], attributes=Occi::Core::Attributes.new, rel=Occi::Core::Resource.type_identifier) link = kind.entity_type.new link.rel = rel link.attributes = attributes link.target = target link.source = self link.mixins = mixins @links << link link end |
#model=(model) ⇒ Object
25 26 27 28 |
# File 'lib/occi/core/resource.rb', line 25 def model=(model) super model @links.model = model end |
#summary ⇒ String
Returns summary attribute of the resource.
31 32 33 |
# File 'lib/occi/core/resource.rb', line 31 def summary self.attributes.occi.core.summary if @attributes.occi.core if @attributes.occi end |
#summary=(summary) ⇒ Object
set summary attribute of resource
37 38 39 |
# File 'lib/occi/core/resource.rb', line 37 def summary=(summary) self.attributes.occi!.core!.summary = summary end |
#to_header ⇒ Hash
Returns hash containing the HTTP headers of the text/occi rendering.
60 61 62 63 |
# File 'lib/occi/core/resource.rb', line 60 def to_header header = super header['Links'] = @links.join(',') end |
#to_text ⇒ String
Returns text representation.
53 54 55 56 57 |
# File 'lib/occi/core/resource.rb', line 53 def to_text text = super @links.each { |link| text << link.to_text_link + "\n" } text end |