Class: Criteria::Criterion
- Inherits:
-
Object
- Object
- Criteria::Criterion
- Defined in:
- lib/criteria.rb
Direct Known Subclasses
Constant Summary collapse
- NOT_EQUAL =
"<>"
- EQUAL =
"="
- GREATER_THAN =
">"
- GREATER_THAN_OR_EQUAL =
">="
- LESS_THAN =
"<"
- LESS_THAN_OR_EQUAL =
"<="
- IN =
"IN"
- NOT_IN =
"NOT IN"
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#&(criterion) ⇒ Object
AND this with another criterion.
- #associations ⇒ Object
-
#columns ⇒ Object
Return a list of columns associated with this criterion, always an array with one element.
-
#initialize(column, operator = nil, value = nil, opts = {}) ⇒ Criterion
constructor
Create a new criteria.
- #not ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
-
#to_where_sql ⇒ Object
Convert this criterion into WHERE SQL.
-
#|(criterion) ⇒ Object
OR this with another criterion.
Constructor Details
#initialize(column, operator = nil, value = nil, opts = {}) ⇒ Criterion
Create a new criteria. Generally, you will not call this directly, rather create it via the Column instance.
The constructor takes a Column instance, an operator string and an optional value
426 427 428 429 430 431 |
# File 'lib/criteria.rb', line 426 def initialize(column, operator=nil, value=nil, opts={}) @column = column @operator = operator @value = value @opts = opts end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
411 412 413 |
# File 'lib/criteria.rb', line 411 def column @column end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
411 412 413 |
# File 'lib/criteria.rb', line 411 def operator @operator end |
#value ⇒ Object
Returns the value of attribute value.
410 411 412 |
# File 'lib/criteria.rb', line 410 def value @value end |
Instance Method Details
#&(criterion) ⇒ Object
AND this with another criterion
446 447 448 449 450 451 452 453 |
# File 'lib/criteria.rb', line 446 def &(criterion) if !criterion.nil? c = Criteria.new c.and self c.and criterion c end end |
#associations ⇒ Object
433 434 435 436 437 438 439 |
# File 'lib/criteria.rb', line 433 def associations if @column.is_a? Association [@column.association_name] else [] end end |
#columns ⇒ Object
Return a list of columns associated with this criterion, always an array with one element
466 467 468 |
# File 'lib/criteria.rb', line 466 def columns [@column] end |
#not ⇒ Object
441 442 443 |
# File 'lib/criteria.rb', line 441 def not NotCriterion.new(self) end |
#to_hash ⇒ Object
475 476 477 478 479 480 |
# File 'lib/criteria.rb', line 475 def to_hash { :include => self.associations, :conditions => to_where_sql } end |
#to_s ⇒ Object
482 483 484 |
# File 'lib/criteria.rb', line 482 def to_s "#{self.class}(#{to_where_sql})" end |
#to_where_sql ⇒ Object
Convert this criterion into WHERE SQL
471 472 473 |
# File 'lib/criteria.rb', line 471 def to_where_sql "#{@column.to_sql_name} #{@operator} #{@column.quote_value(@value)}" end |