Class: SimpleStack::Entity

Inherits:
Object
  • Object
show all
Includes:
Cacheable
Defined in:
lib/simple_stack/entity.rb

Direct Known Subclasses

Guest, Snapshot

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cacheable

#cacheable?, #cached_attributes, #reload

Constructor Details

#initialize(hypervisor, parent, url) ⇒ Entity

Returns a new instance of Entity.



7
8
9
10
11
# File 'lib/simple_stack/entity.rb', line 7

def initialize(hypervisor, parent, url)
  self.hypervisor = hypervisor
  self.parent = parent
  self.url = url.to_s
end

Instance Attribute Details

#hypervisorObject

Returns the value of attribute hypervisor.



5
6
7
# File 'lib/simple_stack/entity.rb', line 5

def hypervisor
  @hypervisor
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/simple_stack/entity.rb', line 5

def parent
  @parent
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/simple_stack/entity.rb', line 5

def url
  @url
end

Instance Method Details

#connectionObject



34
35
36
# File 'lib/simple_stack/entity.rb', line 34

def connection
  hypervisor.connection
end

#deleteObject



21
22
23
24
25
26
27
28
# File 'lib/simple_stack/entity.rb', line 21

def delete
  response = hypervisor.delete url
  if cacheable?
    parent.cached_attributes[:items] ||= []
    parent.cached_attributes[:items].delete self
  end
  response
end

#infoObject



13
14
15
# File 'lib/simple_stack/entity.rb', line 13

def info
  cached_attributes[:info] ||= hypervisor.get url
end

#inspectObject



30
31
32
# File 'lib/simple_stack/entity.rb', line 30

def inspect
  "#<#{self.class} info=#{info.to_json}>"
end

#update(attributes = {}) ⇒ Object



17
18
19
# File 'lib/simple_stack/entity.rb', line 17

def update(attributes = {})
  hypervisor.put url, attributes
end