Class: Lafcadio::Query::Compare
- Defined in:
- lib/lafcadio/query.rb
Overview
:nodoc:
Constant Summary collapse
- @@comparators =
{ :lt => '<', :lte => '<=', :gte => '>=', :gt => '>' }
- @@mockComparators =
{ :lt => Proc.new { |d1, d2| d1 < d2 }, :lte => Proc.new { |d1, d2| d1 <= d2 }, :gte => Proc.new { |d1, d2| d1 >= d2 }, :gt => Proc.new { |d1, d2| d1 > d2 } }
Instance Attribute Summary
Attributes inherited from Condition
Instance Method Summary collapse
- #dobj_satisfies?(anObj) ⇒ Boolean
-
#initialize(fieldName, searchTerm, domain_class, compareType) ⇒ Compare
constructor
A new instance of Compare.
- #to_sql ⇒ Object
Methods inherited from Condition
#&, #db_field_name, #eql?, #field, #implies?, #not, #one_pk_id?, #primary_key_field?, #query, search_term_type, #to_condition, #|
Constructor Details
#initialize(fieldName, searchTerm, domain_class, compareType) ⇒ Compare
Returns a new instance of Compare.
417 418 419 420 |
# File 'lib/lafcadio/query.rb', line 417 def initialize(fieldName, searchTerm, domain_class, compareType) super fieldName, searchTerm, domain_class @compareType = compareType end |
Instance Method Details
#dobj_satisfies?(anObj) ⇒ Boolean
422 423 424 425 426 427 428 429 430 |
# File 'lib/lafcadio/query.rb', line 422 def dobj_satisfies?(anObj) value = anObj.send @fieldName value = value.pk_id if value.class <= DomainObject if value @@mockComparators[@compareType].call(value, @searchTerm) else false end end |
#to_sql ⇒ Object
432 433 434 435 436 437 438 439 440 |
# File 'lib/lafcadio/query.rb', line 432 def to_sql if ( field.kind_of?( DomainObjectField ) && !@searchTerm.respond_to?( :pk_id ) ) search_val = @searchTerm.to_s else search_val = field.value_for_sql( @searchTerm ).to_s end "#{ db_field_name } #{ @@comparators[@compareType] } #{ search_val }" end |