Class: Sentiero::Stores::SQLite::Where
- Inherits:
-
Object
- Object
- Sentiero::Stores::SQLite::Where
- 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
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #add(condition, *values) ⇒ Object
- #clause ⇒ Object
-
#initialize ⇒ Where
constructor
A new instance of Where.
Constructor Details
#initialize ⇒ Where
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
#params ⇒ Object (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 |
#clause ⇒ Object
41 42 43 |
# File 'lib/sentiero/stores/sqlite.rb', line 41 def clause @conditions.empty? ? "" : "WHERE #{@conditions.join(" AND ")}" end |