Class: Lafcadio::Query::ObjectFieldImpostor
- Inherits:
-
Object
- Object
- Lafcadio::Query::ObjectFieldImpostor
show all
- Defined in:
- lib/lafcadio/query.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(domainObjectImpostor, class_field) ⇒ ObjectFieldImpostor
Returns a new instance of ObjectFieldImpostor.
727
728
729
730
731
|
# File 'lib/lafcadio/query.rb', line 727
def initialize( domainObjectImpostor, class_field )
@domainObjectImpostor = domainObjectImpostor
@class_field = class_field
@field_name = class_field.name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methId, *args) ⇒ Object
737
738
739
740
741
742
743
744
|
# File 'lib/lafcadio/query.rb', line 737
def method_missing( methId, *args )
methodName = methId.id2name
if self.class.comparators.keys.include?( methodName )
compare_condition( methodName, *args )
else
super
end
end
|
Instance Attribute Details
#class_field ⇒ Object
Returns the value of attribute class_field.
725
726
727
|
# File 'lib/lafcadio/query.rb', line 725
def class_field
@class_field
end
|
Class Method Details
.comparators ⇒ Object
721
722
723
|
# File 'lib/lafcadio/query.rb', line 721
def self.comparators
{ 'lt' => :lt, 'lte' => :lte, 'gte' => :gte, 'gt' => :gt }
end
|
Instance Method Details
#&(condition) ⇒ Object
733
|
# File 'lib/lafcadio/query.rb', line 733
def &( condition ); Query.And( to_condition, condition ); end
|
#compare_condition(compareStr, searchTerm) ⇒ Object
746
747
748
749
|
# File 'lib/lafcadio/query.rb', line 746
def compare_condition( compareStr, searchTerm)
compareVal = ObjectFieldImpostor.comparators[compareStr]
Compare.new( @field_name, searchTerm, domain_class, compareVal )
end
|
#domain_class ⇒ Object
751
|
# File 'lib/lafcadio/query.rb', line 751
def domain_class; @domainObjectImpostor.domain_class; end
|
#equals(searchTerm) ⇒ Object
753
754
755
756
757
|
# File 'lib/lafcadio/query.rb', line 753
def equals( searchTerm )
Equals.new(
@field_name, field_or_field_name( searchTerm ), domain_class
)
end
|
#field_or_field_name(search_term) ⇒ Object
759
760
761
762
763
764
765
|
# File 'lib/lafcadio/query.rb', line 759
def field_or_field_name( search_term )
if search_term.is_a? ObjectFieldImpostor
search_term.class_field
else
search_term
end
end
|
#in(*searchTerms) ⇒ Object
786
787
788
|
# File 'lib/lafcadio/query.rb', line 786
def in( *searchTerms )
Query::In.new( @field_name, searchTerms, domain_class )
end
|
#include?(search_term) ⇒ Boolean
767
768
769
770
771
772
773
|
# File 'lib/lafcadio/query.rb', line 767
def include?( search_term )
if @class_field.is_a?( TextListField )
Include.new( @field_name, search_term, domain_class )
else
raise ArgumentError
end
end
|
#like(regexp) ⇒ Object
775
776
777
778
779
780
781
782
783
784
|
# File 'lib/lafcadio/query.rb', line 775
def like( regexp )
if regexp.is_a?( Regexp )
Query::Like.new( @field_name, regexp, domain_class )
else
raise(
ArgumentError, "#{ @field_name }#like needs to receive a Regexp",
caller
)
end
end
|
#nil? ⇒ Boolean
790
|
# File 'lib/lafcadio/query.rb', line 790
def nil?; equals( nil ); end
|
#not ⇒ Object
800
|
# File 'lib/lafcadio/query.rb', line 800
def not; to_condition.not; end
|
#to_condition ⇒ Object
792
793
794
795
796
797
798
|
# File 'lib/lafcadio/query.rb', line 792
def to_condition
if @class_field.instance_of?( BooleanField )
Query::Equals.new( @field_name, true, domain_class )
else
raise
end
end
|
#|(condition) ⇒ Object
735
|
# File 'lib/lafcadio/query.rb', line 735
def |( condition ); Query.Or( to_condition, condition ); end
|