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.



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

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#add(condition, *values) ⇒ Object



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

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

#clauseObject



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

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