Class: MMS::Resource
- Inherits:
-
Object
- Object
- MMS::Resource
- Defined in:
- lib/mms/resource.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Cluster, Group, RestoreJob, Snapshot
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #from_hash(data) ⇒ Object
-
#initialize(id, data = nil) ⇒ Resource
constructor
A new instance of Resource.
- #load ⇒ Object
- #save(data) ⇒ Object
Constructor Details
#initialize(id, data = nil) ⇒ Resource
Returns a new instance of Resource.
8 9 10 11 12 13 |
# File 'lib/mms/resource.rb', line 8 def initialize(id, data = nil) @id = id @data = data load end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/mms/resource.rb', line 6 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/mms/resource.rb', line 5 def id @id end |
Instance Method Details
#from_hash(data) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/mms/resource.rb', line 15 def from_hash(data) unless data.nil? @id = data['id'] _from_hash data end end |
#load ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mms/resource.rb', line 22 def load _data = MMS::Cache.instance.get "Class::#{self.class.name}:#{@id}" if _data.nil? and @data.nil? _data = _load(@id) unless @id.nil? if _data.nil? raise "Cannot load data for #{self.class.name}, id `#{@id}`" end end save _data || @data end |
#save(data) ⇒ Object
36 37 38 39 |
# File 'lib/mms/resource.rb', line 36 def save(data) from_hash data MMS::Cache.instance.set "Class::#{self.class.name}:#{@id}", data end |