Module: Searchable

Included in:
SQLObject
Defined in:
lib/easy_save/searchable.rb

Instance Method Summary collapse

Instance Method Details

#where(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/easy_save/searchable.rb', line 4

def where(params)

  where_line = params.keys.map do |key|
    "#{key} = ?"
  end.join(" AND ")

  sql = <<-SQL
    SELECT
      *
    FROM
      #{table_name}
    WHERE
      #{where_line}
  SQL

  results = DBConnection.execute(sql, params.values)

  results.inject([]) { |final, res|  final.push(new(res)) } 
end