Class: Occi::Core::Resource

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

Instance Attribute Summary collapse

Attributes inherited from Entity

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

Instance Method Summary collapse

Methods inherited from Entity

#check, check, new, #title, #title=, #to_s, type_identifier

Methods included from Helpers::Inspect

#inspect

Constructor Details

#initialize(kind = self.kind, mixins = [], attributes = {}, actions = [], links = [], location = nil) ⇒ Occi::Core::Resource

Parameters:

  • kind (String) (defaults to: self.kind)
  • mixins (Array) (defaults to: [])
  • attributes (Occi::Core::Attributes, Hash) (defaults to: {})
  • links (Array) (defaults to: [])

21
22
23
24
# File 'lib/occi/core/resource.rb', line 21

def initialize(kind=self.kind, mixins=[], attributes={}, actions=[], links=[], location=nil)
  super(kind, mixins, attributes, actions, location)
  @links = Occi::Core::Links.new(links)
end

Instance Attribute Details

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

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hashie::Mash)

    link as Hashie::Mash to be parsed into a JSON object


68
69
70
71
72
73
# File 'lib/occi/core/resource.rb', line 68

def as_json(options={})
  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

42
43
44
45
46
47
48
49
50
51
# File 'lib/occi/core/resource.rb', line 42

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


26
27
28
29
# File 'lib/occi/core/resource.rb', line 26

def model=(model)
  super model
  @links.model = model
end

#summaryString

Returns summary attribute of the resource

Returns:

  • (String)

    summary attribute of the resource


32
33
34
# File 'lib/occi/core/resource.rb', line 32

def summary
  self.attributes.occi.core.summary if @attributes.occi.core if @attributes.occi
end

#summary=(summary) ⇒ Object

set summary attribute of resource

Parameters:

  • summary (String)

38
39
40
# File 'lib/occi/core/resource.rb', line 38

def summary=(summary)
  self.attributes.occi!.core!.summary = summary
end

#to_headerHash

Returns hash containing the HTTP headers of the text/occi rendering

Returns:

  • (Hash)

    hash containing the HTTP headers of the text/occi rendering


61
62
63
64
# File 'lib/occi/core/resource.rb', line 61

def to_header
  header = super
  header['Links'] = @links.join(',')
end

#to_textString

Returns text representation

Returns:

  • (String)

    text representation


54
55
56
57
58
# File 'lib/occi/core/resource.rb', line 54

def to_text
  text = super
  @links.each { |link| text << link.to_text_link + "\n" }
  text
end