Module: E9Rails::ActiveRecord::AttributeSearchable::ClassMethods

Defined in:
lib/e9_rails/active_record/attribute_searchable.rb

Instance Method Summary collapse

Instance Method Details

#any_attrs_like_scope_conditions(*args) ⇒ Object



16
17
18
19
20
# File 'lib/e9_rails/active_record/attribute_searchable.rb', line 16

def any_attrs_like_scope_conditions(*args)
  opts   = args.extract_options!
  string = args.pop
  args.flatten.map {|attr_name| attr_like_scope_condition(attr_name, string, opts) }.inject(&:or)
end

#attr_like_scope_condition(attr_name, string, opts = {}) ⇒ Object



11
12
13
14
# File 'lib/e9_rails/active_record/attribute_searchable.rb', line 11

def attr_like_scope_condition(attr_name, string, opts = {})
  matcher = opts.delete(:matcher) || "%%%s%%"
  arel_table[attr_name].matches(matcher % string)
end