12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/searchlight/adapters/mongoid.rb', line 12
def searches(*attributes_names)
super
attributes_names.map do |attribute_name|
method_name = "search_#{attribute_name}"
if field?(attribute_name)
define_method method_name do
search.where(attribute_name.to_s => public_send(attribute_name))
end
else
define_method method_name do
raise Searchlight::Adapters::Mongoid::UndefinedColumn,
"Class `#{self.class.model_class}` has no field `#{attribute_name}`; please define `search_#{attribute_name}` on `#{self.class}` to clarify what you intend to search for"
end
end
end
end
|