Class: ModernSearchlogic::Search
- Inherits:
-
Object
- Object
- ModernSearchlogic::Search
show all
- Defined in:
- lib/modern_searchlogic/search.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(model_class, options = {}) ⇒ Search
Returns a new instance of Search.
14
15
16
|
# File 'lib/modern_searchlogic/search.rb', line 14
def initialize(model_class, options = {})
@model_class, @options = model_class, options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/modern_searchlogic/search.rb', line 73
def method_missing(method, *args, &block)
if search_scope_method?(method)
applied_args = args.many? ? args : args.first
if method.to_s.ends_with?('=')
apply_search(method.to_s.chomp('='), applied_args)
else
if args.present? || model_class.searchlogic_method_arity(method).zero?
self.class.new(model_class, options.merge(method => args.present? ? applied_args : true))
else
get_search_value(method)
end
end
elsif searchlogic_default_scope.respond_to?(method)
materialize_scope.__send__(method, *args, &block)
else
super
end
end
|
Class Method Details
.search(model_class, options = {}) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/modern_searchlogic/search.rb', line 5
def self.search(model_class, options = {})
new(model_class).tap do |s|
options.each do |k, v|
k = k.to_sym
s.apply_search(k, v)
end
end
end
|
Instance Method Details
#apply_search(scope_name, value) ⇒ Object
24
25
26
|
# File 'lib/modern_searchlogic/search.rb', line 24
def apply_search(scope_name, value)
options.merge!(scope_name.to_sym => value)
end
|
#get_search_value(scope_name) ⇒ Object
28
29
30
|
# File 'lib/modern_searchlogic/search.rb', line 28
def get_search_value(scope_name)
options[scope_name]
end
|
#order ⇒ Object
36
37
38
|
# File 'lib/modern_searchlogic/search.rb', line 36
def order
options[:order]
end
|
#order=(new_order) ⇒ Object
32
33
34
|
# File 'lib/modern_searchlogic/search.rb', line 32
def order=(new_order)
options[:order] = new_order
end
|
#respond_to_missing?(method) ⇒ Boolean
18
19
20
21
22
|
# File 'lib/modern_searchlogic/search.rb', line 18
def respond_to_missing?(method, *)
super ||
searchlogic_default_scope.respond_to?(method) ||
search_scope_method?(method)
end
|