Sha256: 37cc4bbd75540b6ac8eb62f7d2949c00fda916c22d5594426da0b765fd9f3cef
Contents?: true
Size: 1003 Bytes
Versions: 9
Compression:
Stored size: 1003 Bytes
Contents
class SearchCop::HashParser attr_reader :query_info def initialize(query_info) @query_info = query_info end def parse(hash) res = hash.collect do |key, value| case key when :and value.collect { |val| parse val }.inject(:and) when :or value.collect { |val| parse val }.inject(:or) when :not parse(value).not when :query SearchCop::Parser.parse value, query_info else parse_attribute key, value end end res.inject :and end private def parse_attribute(key, value) collection = SearchCopGrammar::Attributes::Collection.new(query_info, key.to_s) if value.is_a?(Hash) raise(SearchCop::ParseError, "Unknown operator #{value.keys.first}") unless [:matches, :eq, :not_eq, :gt, :gteq, :lt, :lteq].include?(value.keys.first) collection.send value.keys.first, value.values.first.to_s else collection.send :matches, value.to_s end end end
Version data entries
9 entries across 9 versions & 1 rubygems