Class: Openstack::Client::Resource
- Inherits:
-
Object
- Object
- Openstack::Client::Resource
- Defined in:
- lib/openstack-client/base.rb
Direct Known Subclasses
Keystone::V2_0::EC2, Keystone::V2_0::Tenant, Keystone::V2_0::Token
Instance Attribute Summary collapse
-
#info ⇒ Object
Returns the value of attribute info.
-
#loaded ⇒ Object
Returns the value of attribute loaded.
-
#manager ⇒ Object
Returns the value of attribute manager.
Class Method Summary collapse
Instance Method Summary collapse
- #add_details(info) ⇒ Object
- #get ⇒ Object
-
#initialize(manager, info, loaded = nil) ⇒ Resource
constructor
A new instance of Resource.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(manager, info, loaded = nil) ⇒ Resource
Returns a new instance of Resource.
21 22 23 24 25 26 27 |
# File 'lib/openstack-client/base.rb', line 21 def initialize manager, info, loaded=nil self.manager = manager self.info = info self.loaded = loaded self.add_details(info) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/openstack-client/base.rb', line 44 def method_missing(name, *args) self.get unless self.loaded return self.send(name, *args) if self.respond_to?(name) super end |
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
6 7 8 |
# File 'lib/openstack-client/base.rb', line 6 def info @info end |
#loaded ⇒ Object
Returns the value of attribute loaded.
7 8 9 |
# File 'lib/openstack-client/base.rb', line 7 def loaded @loaded end |
#manager ⇒ Object
Returns the value of attribute manager.
5 6 7 |
# File 'lib/openstack-client/base.rb', line 5 def manager @manager end |
Class Method Details
.delegate(methods, options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/openstack-client/base.rb', line 9 def self.delegate methods, to = [:to] methods.each do |method| module_eval <<-EOM def #{method.to_s} *args, &block args.unshift(self) self.#{to.to_s}.send(:#{method.to_s}, *args, &block) end EOM end end |
Instance Method Details
#add_details(info) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/openstack-client/base.rb', line 29 def add_details info info.each do |name, v| unless self.respond_to?(name.to_sym) self.instance_eval <<-EOM def #{name} self.info['#{name}'] end def #{name}= val self.info['#{name}'] = val end EOM end end end |
#get ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/openstack-client/base.rb', line 51 def get self.loaded = true res = self.manager.get(self.id) self.info = res.info self.add_details(self.info) return self end |