Included Modules

Class Index [+]

Quicksearch

DataMapper::Query::Conditions::InclusionComparison

Tests whether the value in the record is contained in the expected set for the Comparison, where expected is an Array, Range, or Set.

Public Instance Methods

valid?() click to toggle source

Checks that the Comparison is valid

@see DataMapper::Query::Conditions::AbstractComparison#valid?

@return [Boolean]

@api semipublic

     # File lib/dm-core/query/conditions/comparison.rb, line 583
583:         def valid?
584:           loaded_value = self.loaded_value
585:           case loaded_value
586:             when Collection then valid_collection?(loaded_value)
587:             when Range      then valid_range?(loaded_value)
588:             when Enumerable then valid_enumerable?(loaded_value)
589:             else
590:               false
591:           end
592:         end

Private Instance Methods

comparator_string() click to toggle source

@return [String]

@see AbstractComparison#to_s

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 713
713:         def comparator_string
714:           'IN'
715:         end
dump() click to toggle source

Dumps the given val using subject#

@return [Array]

@see AbtractComparison#dump

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 697
697:         def dump
698:           loaded_value = self.loaded_value
699:           if subject.respond_to?(:dump) && loaded_value.respond_to?(:map) && !loaded_value.kind_of?(Range)
700:             dumped_value = loaded_value.map { |value| dump_property(value) }
701:             dumped_value.uniq!
702:             dumped_value
703:           else
704:             super
705:           end
706:         end
expected() click to toggle source

Overloads AbtractComparison#expected

@return [Array] @see AbtractComparison#expected

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 607
607:         def expected
608:           loaded_value = self.loaded_value
609:           if loaded_value.kind_of?(Range)
610:             typecast_range(loaded_value)
611:           elsif loaded_value.respond_to?(:map)
612:             # FIXME: causes a lazy load when a Collection
613:             loaded_value.map { |val| super(val) }
614:           else
615:             super
616:           end
617:         end
match_property?(record) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 597
597:         def match_property?(record)
598:           super(record, :include?)
599:         end
typecast_collection(collection) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 672
672:         def typecast_collection(collection)
673:           collection
674:         end
typecast_enumerable(enumerable) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 677
677:         def typecast_enumerable(enumerable)
678:           collection = nil
679:           enumerable.each do |entry|
680:             typecasted = typecast_relationship(entry)
681:             if collection
682:               collection |= typecasted
683:             else
684:               collection = typecasted
685:             end
686:           end
687:           collection
688:         end
typecast_hash(hash) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 661
661:         def typecast_hash(hash)
662:           subject = self.subject
663:           subject.target_model.all(subject.query.merge(hash))
664:         end
typecast_property(value) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 635
635:         def typecast_property(value)
636:           if value.kind_of?(Range)
637:             typecast_range(value)
638:           elsif value.respond_to?(:map) && !value.kind_of?(String)
639:             value.map { |entry| super(entry) }
640:           else
641:             super
642:           end
643:         end
typecast_range(range) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 646
646:         def typecast_range(range)
647:           range.class.new(typecast_property(range.first), typecast_property(range.last), range.exclude_end?)
648:         end
typecast_relationship(value) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 651
651:         def typecast_relationship(value)
652:           case value
653:             when Hash       then typecast_hash(value)
654:             when Resource   then typecast_resource(value)
655:             when Collection then typecast_collection(value)
656:             when Enumerable then typecast_enumerable(value)
657:           end
658:         end
typecast_resource(resource) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 667
667:         def typecast_resource(resource)
668:           resource.collection_for_self
669:         end
valid_collection?(collection) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 620
620:         def valid_collection?(collection)
621:           valid_for_subject?(collection)
622:         end
valid_enumerable?(enumerable) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 630
630:         def valid_enumerable?(enumerable)
631:           (!enumerable.empty? || negated?) && enumerable.all? { |entry| valid_for_subject?(entry) }
632:         end
valid_range?(range) click to toggle source

@api private

     # File lib/dm-core/query/conditions/comparison.rb, line 625
625:         def valid_range?(range)
626:           (range.any? || negated?) && valid_for_subject?(range.first) && valid_for_subject?(range.last)
627:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.