Class: Rebels::Fakes::FakeDB
- Inherits:
-
Object
- Object
- Rebels::Fakes::FakeDB
- Defined in:
- lib/rebels/fakes/fake_db.rb
Defined Under Namespace
Classes: NonNullFinder
Instance Method Summary collapse
-
#initialize ⇒ FakeDB
constructor
A new instance of FakeDB.
- #insert(table, record) ⇒ Object
- #update(table, id, attrs) ⇒ Object
- #where(table, filters) ⇒ Object
Constructor Details
#initialize ⇒ FakeDB
Returns a new instance of FakeDB.
8 9 10 11 |
# File 'lib/rebels/fakes/fake_db.rb', line 8 def initialize @tables = {} @ids = {} end |
Instance Method Details
#insert(table, record) ⇒ Object
17 18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 27 28 29 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/rebels/fakes/fake_db.rb', line 13 def where(table, filters) @tables[table].select(&NonNullFinder.new(filters)) end |