Module: Searchable

Included in:
WORMY::Base
Defined in:
lib/wormy/searchable.rb

Instance Method Summary collapse

Instance Method Details

#where(params = {}) ⇒ Object



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

def where(params = {})
  return all if params == {}

  search_results = []
  where_line = params.keys.map { |key| "#{key} = ?" }.join(" AND ")

  results = WORMY::DBConnection.execute("    SELECT\n      *\n    FROM\n      \#{table_name}\n    WHERE\n      \#{where_line}\n  SQL\n\n  results.each { |result| search_results << self.new(result) }\n\n  search_results\nend\n", *params.values)