Class: SimpleStack::Entity

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

Direct Known Subclasses

Disk, Guest, Host, Network, NetworkInterface, Snapshot, Storage

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/simple_stack/entity.rb', line 35

def method_missing(method, *args, &block)
  entity_info = info
  if entity_info.keys.include?(method.to_s)
    entity_info[method.to_s]
  else
    super
  end
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



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

def connection
  hypervisor.connection
end

#deleteObject



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

def delete
  response = hypervisor.delete url
  parent.reload if cacheable?
  response
end

#infoObject



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

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

#inspectObject



27
28
29
# File 'lib/simple_stack/entity.rb', line 27

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