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(<<-SQL, *params.values)
    SELECT
      *
    FROM
      #{table_name}
    WHERE
      #{where_line}
  SQL

  results.each { |result| search_results << self.new(result) }

  search_results
end