Class: Lafcadio::Query::CompoundCondition
- Defined in:
- lib/lafcadio/query/CompoundCondition.rb
Overview
:nodoc:
Constant Summary collapse
- AND =
1
- OR =
2
Instance Attribute Summary
Attributes inherited from Condition
Instance Method Summary collapse
-
#initialize(*conditions) ⇒ CompoundCondition
constructor
A new instance of CompoundCondition.
- #objectMeets(anObj) ⇒ Object
- #toSql ⇒ Object
Methods inherited from Condition
#dbFieldName, #getField, #not, #primaryKeyField?, searchTermType
Constructor Details
#initialize(*conditions) ⇒ CompoundCondition
Returns a new instance of CompoundCondition.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lafcadio/query/CompoundCondition.rb', line 9 def initialize(*conditions) if( [ AND, OR ].index(conditions.last) ) @compoundType = conditions.last conditions.pop else @compoundType = AND end @conditions = conditions @objectType = conditions[0].objectType end |
Instance Method Details
#objectMeets(anObj) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lafcadio/query/CompoundCondition.rb', line 26 def objectMeets(anObj) if @compoundType == AND om = true @conditions.each { |cond| om = om && cond.objectMeets(anObj) } om else om = false @conditions.each { |cond| om = om || cond.objectMeets(anObj) } om end end |
#toSql ⇒ Object
20 21 22 23 24 |
# File 'lib/lafcadio/query/CompoundCondition.rb', line 20 def toSql booleanString = @compoundType == AND ? 'and' : 'or' subSqlStrings = @conditions.collect { |cond| cond.toSql } "(#{ subSqlStrings.join(" #{ booleanString } ") })" end |