class Dashing::Db::History

Public Class Methods

new(connection) click to toggle source
# File lib/dashing/db.rb, line 7
def initialize(connection)
  @connection = connection
  troubleshoot_connection
end

Public Instance Methods

[](key) click to toggle source
# 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) click to toggle source
# 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
all() click to toggle source
# 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) click to toggle source
# File lib/dashing/db.rb, line 33
def each(&block)
  all.each(&block)
end

Private Instance Methods

setup_schema() click to toggle source
# File lib/dashing/db.rb, line 53
def setup_schema
  @connection.create_table :items do
    String :key, :primary_key => true
    File :value
  end
end
table() click to toggle source
# File lib/dashing/db.rb, line 40
def table
  @connection[:items]
end
troubleshoot_connection() click to toggle source
# File lib/dashing/db.rb, line 44
def troubleshoot_connection
  begin
    table.first
  rescue Exception => e
    setup_schema
  end
  table.first
end