Class: Lark::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#key ⇒ Object



138
139
140
# File 'lib/lark.rb', line 138

def key
  Lark.key(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