Class: ArFinderForm::Attr::Simple

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

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) ⇒ Simple

Returns a new instance of Simple.



6
7
8
9
# File 'lib/ar_finder_form/attr/simple.rb', line 6

def initialize(column, name, options)
  super(column, name, options)
  @operator = options.delete(:operator).to_s.downcase.to_sym
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



5
6
7
# File 'lib/ar_finder_form/attr/simple.rb', line 5

def operator
  @operator
end

Instance Method Details

#build(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ar_finder_form/attr/simple.rb', line 15

def build(context)
  return unless match?(context)
  case operator
  when :in then
    context.add_condition("#{column_name(context)} IN (?)",
      form_value_array(context))
  else
    context.add_condition(
      "#{column_name(context)} #{operator} ?",
      form_value(context))
  end
end

#setupObject



11
12
13
# File 'lib/ar_finder_form/attr/simple.rb', line 11

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