Class: Sentiero::Stores::SQLite::Where

Inherits:
Object
  • Object
show all
Defined in:
lib/sentiero/stores/sqlite.rb

Overview

Accumulates "column op ?" fragments and their bind params for a WHERE clause, so the six list/count methods below don't hand-roll the same conditions/params pair. #clause is "" (no WHERE) when nothing was added.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWhere

Returns a new instance of Where.



30
31
32
33
# File 'lib/sentiero/stores/sqlite.rb', line 30

def initialize
  @conditions = []
  @params = []
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



28
29
30
# File 'lib/sentiero/stores/sqlite.rb', line 28

def params
  @params
end

Instance Method Details

#add(condition, *values) ⇒ Object



35
36
37
38
39
# File 'lib/sentiero/stores/sqlite.rb', line 35

def add(condition, *values)
  @conditions << condition
  @params.concat(values)
  self
end

#clauseObject



41
42
43
# File 'lib/sentiero/stores/sqlite.rb', line 41

def clause
  @conditions.empty? ? "" : "WHERE #{@conditions.join(" AND ")}"
end