Class: ArFinderForm::Attr::Base
- Inherits:
-
Object
- Object
- ArFinderForm::Attr::Base
show all
- Defined in:
- lib/ar_finder_form/attr/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(column, name, options) ⇒ Base
Returns a new instance of Base.
7
8
9
10
11
12
13
|
# File 'lib/ar_finder_form/attr/base.rb', line 7
def initialize(column, name, options)
@column, @name = column, name
@nil_available = options.delete(:nil_available)
@options = options
@attr_filter = options[:attr_filter] || method(:column_type_cast)
@array_separator = options.delete(:array_separator) || /[\s\,]/
end
|
Instance Attribute Details
#array_separator ⇒ Object
Returns the value of attribute array_separator.
6
7
8
|
# File 'lib/ar_finder_form/attr/base.rb', line 6
def array_separator
@array_separator
end
|
#column ⇒ Object
Returns the value of attribute column.
5
6
7
|
# File 'lib/ar_finder_form/attr/base.rb', line 5
def column
@column
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/ar_finder_form/attr/base.rb', line 5
def name
@name
end
|
#nil_available ⇒ Object
Returns the value of attribute nil_available.
6
7
8
|
# File 'lib/ar_finder_form/attr/base.rb', line 6
def nil_available
@nil_available
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/ar_finder_form/attr/base.rb', line 5
def options
@options
end
|
Instance Method Details
#client_class_eval(script, &block) ⇒ Object
22
23
24
25
26
|
# File 'lib/ar_finder_form/attr/base.rb', line 22
def client_class_eval(script, &block)
klass = column.table.root_table.client_class
klass.module_eval(&block) if block
klass.module_eval(script) if script
end
|
#column_name(context) ⇒ Object
18
19
20
|
# File 'lib/ar_finder_form/attr/base.rb', line 18
def column_name(context)
context.single_table? ? column.name : "#{table.name}.#{column.name}"
end
|
#column_type_cast(value) ⇒ Object
43
44
45
|
# File 'lib/ar_finder_form/attr/base.rb', line 43
def column_type_cast(value)
column.model_column.type_cast(value)
end
|
32
33
34
35
|
# File 'lib/ar_finder_form/attr/base.rb', line 32
def form_value(context)
result = context.form.send(name)
@attr_filter ? @attr_filter.call(result) : result
end
|
37
38
39
40
41
|
# File 'lib/ar_finder_form/attr/base.rb', line 37
def form_value_array(context)
values = context.form.send(name)
values = values.to_s.split(array_separator) unless values.is_a?(Array)
@attr_filter ? values.map{|v| @attr_filter.call(v)} : values
end
|
#match?(context) ⇒ Boolean
28
29
30
|
# File 'lib/ar_finder_form/attr/base.rb', line 28
def match?(context)
nil_available? ? true : !!context.form.send(name)
end
|
#nil_available? ⇒ Boolean
16
|
# File 'lib/ar_finder_form/attr/base.rb', line 16
def nil_available?; !!@nil_available; end
|
#table ⇒ Object
15
|
# File 'lib/ar_finder_form/attr/base.rb', line 15
def table; column.table; end
|