Tests whether the value in the record is contained in the expected set for the Comparison, where expected is an Array, Range, or Set.
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
@return [String]
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 713 713: def comparator_string 714: 'IN' 715: end
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
Overloads AbtractComparison#expected
@return [Array
@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
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 597 597: def match_property?(record) 598: super(record, :include?) 599: end
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 672 672: def typecast_collection(collection) 673: collection 674: end
@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
@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
@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
@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
@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
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 667 667: def typecast_resource(resource) 668: resource.collection_for_self 669: end
@api private
# File lib/dm-core/query/conditions/comparison.rb, line 620 620: def valid_collection?(collection) 621: valid_for_subject?(collection) 622: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.