Class: Nexter::Query::Section
- Inherits:
-
Object
- Object
- Nexter::Query::Section
- Defined in:
- lib/nexter/query/section.rb
Overview
Iterates over the columns, extracts their values and builds query part that says :
> “col1 = value1” > “col2 = value2”
then joins them with AND :
> “col1 = value1 AND col2 = value2”
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#compass ⇒ Object
readonly
Returns the value of attribute compass.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(columns) ⇒ Section
constructor
TODO : check if compass is needed (don’t think so!).
- #iterate ⇒ Object (also: #sql)
Constructor Details
#initialize(columns) ⇒ Section
TODO : check if compass is needed (don’t think so!)
17 18 19 20 |
# File 'lib/nexter/query/section.rb', line 17 def initialize(columns) @columns = columns @compass = compass end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
14 15 16 |
# File 'lib/nexter/query/section.rb', line 14 def columns @columns end |
#compass ⇒ Object (readonly)
Returns the value of attribute compass.
14 15 16 |
# File 'lib/nexter/query/section.rb', line 14 def compass @compass end |
Instance Method Details
#blank? ⇒ Boolean
33 34 35 |
# File 'lib/nexter/query/section.rb', line 33 def blank? iterate.blank? end |
#iterate ⇒ Object Also known as: sql
22 23 24 25 26 27 28 29 30 |
# File 'lib/nexter/query/section.rb', line 22 def iterate @where ||= columns.map do |column| if column[:val] "#{column[:col]} = #{quote(column[:val])}" else "#{column[:col]} IS NULL" end end.join(' AND ') end |