Class: ArFinderForm::Attr::Like

Inherits:
Base
  • Object
show all
Defined in:
lib/ar_finder_form/attr/like.rb

Constant Summary collapse

MATCHERS =
{
  :forward => '%s%%',
  :backward => '%%%s',
  :partial => '%%%s%%'
}

Instance Attribute Summary collapse

Attributes inherited from Base

#array_separator, #column, #name, #nil_available, #options

Instance Method Summary collapse

Methods inherited from Base

#client_class_eval, #column_name, #column_type_cast, #form_value, #form_value_array, #match?, #nil_available?, #table

Constructor Details

#initialize(column, name, options) ⇒ Like

Returns a new instance of Like.



13
14
15
16
# File 'lib/ar_finder_form/attr/like.rb', line 13

def initialize(column, name, options)
  super(column, name, options)
  @mathcer = MATCHERS[options[:match]] || MATCHERS[:partial]
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



12
13
14
# File 'lib/ar_finder_form/attr/like.rb', line 12

def operator
  @operator
end

Instance Method Details

#build(context) ⇒ Object



22
23
24
25
26
27
# File 'lib/ar_finder_form/attr/like.rb', line 22

def build(context)
  return unless match?(context)
  context.add_condition(
    "#{column_name(context)} LIKE ?",
    @mathcer % form_value(context).to_s)
end

#setupObject



18
19
20
# File 'lib/ar_finder_form/attr/like.rb', line 18

def setup
  client_class_eval("attr_accessor :#{name}")
end