class QuickSearch::Adapters::MongoidAdapter
Public Class Methods
new(cls)
click to toggle source
# File lib/quick-search/adapters/mongoid_adapter.rb, line 4 def initialize(cls) @cls = cls end
Public Instance Methods
default_quick_search_fields()
click to toggle source
# File lib/quick-search/adapters/mongoid_adapter.rb, line 12 def default_quick_search_fields @cls.fields.select { |_, f| f.type == String }.map(&:first) end
make_clauses_for_token(s, token, fields)
click to toggle source
# File lib/quick-search/adapters/mongoid_adapter.rb, line 8 def make_clauses_for_token(s, token, fields) s.and '$or' => fields.map { |f| { to_field_name(f) => /#{Regexp.escape token}/i } } end
Private Instance Methods
to_field_name(f)
click to toggle source
# File lib/quick-search/adapters/mongoid_adapter.rb, line 18 def to_field_name(f) case f when Hash head = f.first "#{head.first}.#{to_field_name(head.last)}" when String, Symbol f else raise "Unrecognized input: #{f}" end end