lib/search_cop.rb in search_cop-1.1.0 vs lib/search_cop.rb in search_cop-1.2.0
- old
+ new
@@ -1,7 +1,7 @@
-
require "search_cop/version"
+require "search_cop/helpers"
require "search_cop/search_scope"
require "search_cop/query_info"
require "search_cop/query_builder"
require "search_cop/grammar_parser"
require "search_cop/hash_parser"
@@ -21,11 +21,11 @@
class ParseError < RuntimeError; end
module Parser
def self.parse(query, query_info, query_options = {})
if query.is_a?(Hash)
- SearchCop::HashParser.new(query_info).parse(query)
+ SearchCop::HashParser.new(query_info).parse(query, query_options)
else
SearchCop::GrammarParser.new(query_info).parse(query, query_options)
end
end
end
@@ -42,20 +42,20 @@
self.search_scopes = search_scopes.dup
search_scopes[name] = SearchScope.new(name, self)
search_scopes[name].instance_exec(&block)
- self.send(:define_singleton_method, name) { |query, query_options={}| search_cop query, name, query_options }
- self.send(:define_singleton_method, "unsafe_#{name}") { |query, query_options={}| unsafe_search_cop query, name, query_options }
+ send(:define_singleton_method, name) { |query, query_options = {}| search_cop(query, name, query_options) }
+ send(:define_singleton_method, "unsafe_#{name}") { |query, query_options = {}| unsafe_search_cop(query, name, query_options) }
end
def search_reflection(scope_name)
search_scopes[scope_name].reflection
end
def search_cop(query, scope_name, query_options)
- unsafe_search_cop query, scope_name, query_options
+ unsafe_search_cop(query, scope_name, query_options)
rescue SearchCop::RuntimeError
respond_to?(:none) ? none : where("1 = 0")
end
def unsafe_search_cop(query, scope_name, query_options)
@@ -67,24 +67,6 @@
scope ||= eager_load(query_builder.associations) if query_builder.associations.any?
(scope || self).where(query_builder.sql)
end
end
-
- module Helpers
- def self.sanitize_default_operator(hash, delete_hash_option=false)
- default_operator = :and
- if hash.member?(:default_operator)
- unless [:and, :or].include?(hash[:default_operator])
- raise(SearchCop::UnknownDefaultOperator, "Unknown default operator value #{hash[:default_operator]}")
- end
-
- default_operator = hash[:default_operator]
- end
-
- hash.delete(:default_operator) if delete_hash_option
-
- default_operator
- end
- end
end
-