class Kingfisher::SqlLite3Backend
Attributes
db[R]
Public Class Methods
new(file)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 5 def initialize(file) @db = Sequel.connect("sqlite://#{file}") end
Public Instance Methods
all(model)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 9 def all(model) db[table_name(model)].to_a end
create(model, params)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 13 def create(model, params) id = db[table_name(model)].insert(params) attributes = symbolize_keys(params).merge(id: id) model.new(attributes) end
find(model, id)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 19 def find(model, id) find_by(model, id: id) end
find_by(model, attributes)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 23 def find_by(model, attributes) model.new(db[table_name(model)][**attributes]) end
Private Instance Methods
symbolize_keys(hash)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 34 def symbolize_keys(hash) hash.each_with_object({}) do |(key, value), new_hash| new_hash[key.to_sym] = value end end
table_name(model)
click to toggle source
# File lib/kingfisher/sqlite3_backend.rb, line 30 def table_name(model) model.name.downcase.to_sym end