Sha256: 0a119bd348bbcdfdcc6504f9b5b49dea831c1edfe4cfee6facf66c36d04987ec
Contents?: true
Size: 842 Bytes
Versions: 1
Compression:
Stored size: 842 Bytes
Contents
module ActiveEnumerable # @private class Finder def initialize(record) @method_caller = MethodCaller.new(record) end def is_of(conditions={}) conditions.all? do |col, match| if match.is_a? Hash hash_match(col, match) elsif match.is_a? ::Enumerable any_match(col, match) else compare(col, match) end end end private def hash_match(col, match) next_record = @method_caller.call(col) if next_record.is_a? Array next_record.any? { |record| Finder.new(record).is_of(match) } else Finder.new(next_record).is_of(match) end end def any_match(col, match) match.any? { |m| compare(col, m) } end def compare(col, match) @method_caller.call(col) == match end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_enumerable-0.1.1 | lib/active_enumerable/finder.rb |