Class: Dashing::Db::History

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dashing/db.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ History

Returns a new instance of History.



7
8
9
10
# File 'lib/dashing/db.rb', line 7

def initialize(connection)
  @connection = connection
  troubleshoot_connection
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
15
16
# File 'lib/dashing/db.rb', line 12

def [](key)
  v = table.where(:key => key).select(:value)
  return nil if v.nil?
  v[:value]
end

#[]=(key, value) ⇒ Object



18
19
20
21
22
23
# File 'lib/dashing/db.rb', line 18

def []=(key, value)
  updated_count = table.where(:key => key).update(:value => value)
  if updated_count == 0
    table.insert(:key => key, :value => value)
  end
end

#allObject



25
26
27
28
29
30
31
# File 'lib/dashing/db.rb', line 25

def all
  {}.tap do |all|
    table.each do |item|
      all[item[:key]] = item[:value]
    end
  end
end

#each(&block) ⇒ Object



33
34
35
# File 'lib/dashing/db.rb', line 33

def each(&block)
  all.each(&block)
end