Class: Lark::Base
- Inherits:
-
Object
- Object
- Lark::Base
- Defined in:
- lib/lark.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #data ⇒ Object
- #destroy ⇒ Object
-
#initialize(_id, _group, _data = nil) ⇒ Base
constructor
A new instance of Base.
- #key ⇒ Object
- #pool(&blk) ⇒ Object
- #save_data ⇒ Object
- #set(new_data) ⇒ Object
Constructor Details
#initialize(_id, _group, _data = nil) ⇒ Base
Returns a new instance of Base.
131 132 133 134 135 136 |
# File 'lib/lark.rb', line 131 def initialize(_id, _group, _data = nil) @id = _id @group = _group @data = _data save_data if @data end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
129 130 131 |
# File 'lib/lark.rb', line 129 def group @group end |
#id ⇒ Object
Returns the value of attribute id.
129 130 131 |
# File 'lib/lark.rb', line 129 def id @id end |
Instance Method Details
#data ⇒ Object
154 155 156 |
# File 'lib/lark.rb', line 154 def data @data ||= (Lark.load_data(key) || {}) end |
#destroy ⇒ Object
158 159 160 |
# File 'lib/lark.rb', line 158 def destroy Lark.destroy(id, group) end |
#pool(&blk) ⇒ Object
162 163 164 |
# File 'lib/lark.rb', line 162 def pool(&blk) self.class.pool(&blk) end |
#save_data ⇒ Object
147 148 149 150 151 152 |
# File 'lib/lark.rb', line 147 def save_data data[:created_on] ||= Time.new.to_i data[:updated_on] = Time.new.to_i data[:id] = id Lark.save_data(id, group, data) end |
#set(new_data) ⇒ Object
142 143 144 145 |
# File 'lib/lark.rb', line 142 def set(new_data) data.merge!(new_data) save_data end |