Module: FileDb::Query

Included in:
Model
Defined in:
lib/file_db/query.rb

Instance Method Summary collapse

Instance Method Details

#allObject



22
23
24
# File 'lib/file_db/query.rb', line 22

def all
  table.all.map{ |entry| new entry }
end

#find(id) ⇒ Object



4
5
6
7
8
# File 'lib/file_db/query.rb', line 4

def find id
  found_element = table.find(id)
  return unless found_element
  new found_element
end

#find_by(attribute, search_value) ⇒ Object



30
31
32
# File 'lib/file_db/query.rb', line 30

def find_by attribute, search_value
  where("#{attribute}".to_sym => search_value).first
end

#firstObject



10
11
12
13
14
# File 'lib/file_db/query.rb', line 10

def first
  found_element = table.first
  return unless found_element
  new found_element
end

#lastObject



16
17
18
19
20
# File 'lib/file_db/query.rb', line 16

def last
  found_element = table.last
  return unless found_element
  new found_element
end

#where(conditions) ⇒ Object



26
27
28
# File 'lib/file_db/query.rb', line 26

def where conditions
  table.where(conditions).map{ |entry| new entry }
end