Class: ObStore::Data
Instance Attribute Summary collapse
-
#data ⇒ Object
custom getter for retrieving data from the data hash.
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
-
#fetch ⇒ Object
returns the object you had saved.
-
#initialize(data = nil, options = {}) ⇒ Data
constructor
A new instance of Data.
-
#save(data) ⇒ Object
Saves the object.
-
#stale? ⇒ Boolean
returns boolean value if data has expired.
-
#ts ⇒ Object
helper method to return the timestamp as an int.
Methods included from Lockable
Constructor Details
#initialize(data = nil, options = {}) ⇒ Data
Returns a new instance of Data.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/obstore/data.rb', line 19 def initialize(data=nil, ={}) @expiry = [:expiry] # in seconds @data = {} store_data_by_key :data, data @updated = Time.now if [:metadata] [:metadata].each do |key, value| store_data_by_key key, value end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
81 82 83 84 85 86 87 88 89 |
# File 'lib/obstore/data.rb', line 81 def method_missing(meth, *args, &block) if meth.to_s =~ /^(.+)=$/ store_data_by_key($1, *args) elsif meth.to_s =~ /^(.+)$/ fetch_data_by_key($1) else super end end |
Instance Attribute Details
#data ⇒ Object
custom getter for retrieving data from the data hash
57 58 59 |
# File 'lib/obstore/data.rb', line 57 def data @data end |
#expiry ⇒ Object
Returns the value of attribute expiry.
16 17 18 |
# File 'lib/obstore/data.rb', line 16 def expiry @expiry end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
17 18 19 |
# File 'lib/obstore/data.rb', line 17 def updated @updated end |
Instance Method Details
#fetch ⇒ Object
returns the object you had saved
32 33 34 |
# File 'lib/obstore/data.rb', line 32 def fetch fetch_data_by_key(:data) end |
#save(data) ⇒ Object
Saves the object
47 48 49 |
# File 'lib/obstore/data.rb', line 47 def save(data) self.data=data end |
#stale? ⇒ Boolean
returns boolean value if data has expired
37 38 39 40 41 42 43 44 |
# File 'lib/obstore/data.rb', line 37 def stale? if @expiry if ts < Time.now.to_i - @expiry return true end end return false end |
#ts ⇒ Object
helper method to return the timestamp as an int
62 63 64 |
# File 'lib/obstore/data.rb', line 62 def ts with_mutex { @updated.to_i } end |