Module: RecordFinders

Included in:
LessActiveRecord
Defined in:
lib/less_active_record/record_finders.rb

Instance Method Summary collapse

Instance Method Details

#allObject



2
3
4
# File 'lib/less_active_record/record_finders.rb', line 2

def all
  where({})
end

#find(id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/less_active_record/record_finders.rb', line 6

def find(id)
  if record = _adapter.search(id: id).first
    new(record).tap { |item| item.send(:id=, id) }
  else
    raise 'Record not found!'
  end
end

#where(attributes) ⇒ Object



14
15
16
17
18
# File 'lib/less_active_record/record_finders.rb', line 14

def where(attributes)
  _adapter.search(attributes).map do |record|
    new(record).tap { |item| item.send(:id=, record[:id]) }
  end
end