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, #mixins, #model

Instance Method Summary collapse

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

Parameters:

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


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

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



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

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


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

#summaryString

Returns summary attribute of the resource.

Returns:

  • (String)

    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

Parameters:

  • summary (String)


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

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



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

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

#to_textString

Returns text representation.

Returns:

  • (String)

    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