Class: WhereClause

Inherits:
Object show all
Defined in:
lib/activeleopard/query_clauses/where_clause.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = []) ⇒ WhereClause

Returns a new instance of WhereClause.



4
5
6
7
8
9
10
# File 'lib/activeleopard/query_clauses/where_clause.rb', line 4

def initialize(options = [])
  unless options.is_a?(Array) && options.length <= 2
    raise InvalidInput, "Where takes 1 or 2 arguments"
  end

  @conditions = parse_conditions(options)
end

Instance Method Details

#append(options) ⇒ Object Also known as: <<



21
22
23
# File 'lib/activeleopard/query_clauses/where_clause.rb', line 21

def append(options)
  conditions.merge!(parse_conditions(options))
end

#as_sqlObject



16
17
18
19
# File 'lib/activeleopard/query_clauses/where_clause.rb', line 16

def as_sql
  return "" if conditions.empty?
  " WHERE " + conditions_as_sql
end

#valuesObject



12
13
14
# File 'lib/activeleopard/query_clauses/where_clause.rb', line 12

def values
  conditions.values.flatten
end