Class: Rebels::RailsAdapters::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/rebels/rails_adapters/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(tables) ⇒ Database

Returns a new instance of Database.



2
3
4
# File 'lib/rebels/rails_adapters/database.rb', line 2

def initialize(tables)
  @tables = tables
end

Instance Method Details

#insert(table, record) ⇒ Object



5
6
7
# File 'lib/rebels/rails_adapters/database.rb', line 5

def insert(table, record)
  @tables[table].first.create!(record.attributes)
end

#update(table, id, attrs) ⇒ Object



15
16
17
# File 'lib/rebels/rails_adapters/database.rb', line 15

def update(table, id, attrs)
  @tables[table].first.find(id).update_attributes(attrs)
end

#where(table, filters) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/rebels/rails_adapters/database.rb', line 8

def where(table, filters)
  @tables[table].first.where(filters).map do |ar|
    keys = @tables[table].last.with({}).attributes.keys
    attrs = keys.reduce({}){|m,e| m.merge(e => ar.attributes[e.to_s])}
    @tables[table].last.with(attrs)
  end
end