class Rebels::Fakes::FakeDB
Public Class Methods
new()
click to toggle source
# File lib/rebels/fakes/fake_db.rb, line 8 def initialize @tables = {} @ids = {} end
Public Instance Methods
insert(table, record)
click to toggle source
# File lib/rebels/fakes/fake_db.rb, line 17 def insert(table, record) @tables[table] ||= [] record = record.with(id: next_id(table)) @tables[table] << record record end
update(table, id, attrs)
click to toggle source
# File lib/rebels/fakes/fake_db.rb, line 24 def update(table, id, attrs) record = @tables[table].detect{|r| r.id == id} idx = @tables[table].index(record) @tables[table][idx] = record.with(attrs) nil end
where(table, filters)
click to toggle source
# File lib/rebels/fakes/fake_db.rb, line 13 def where(table, filters) @tables[table].select(&NonNullFinder.new(filters)) end
Private Instance Methods
next_id(table)
click to toggle source
# File lib/rebels/fakes/fake_db.rb, line 32 def next_id(table) @ids[table] ||= 0 @ids[table] += 1 @ids[table] end