Class: ArFinderForm::Column
- Inherits:
-
Object
- Object
- ArFinderForm::Column
- Defined in:
- lib/ar_finder_form/column.rb
Instance Attribute Summary collapse
-
#form_attr ⇒ Object
readonly
Returns the value of attribute form_attr.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #build(context) ⇒ Object
- #foreign_key? ⇒ Boolean
-
#initialize(table, name, *args) ⇒ Column
constructor
A new instance of Column.
- #model_column ⇒ Object
- #setup ⇒ Object
- #static? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(table, name, *args) ⇒ Column
Returns a new instance of Column.
6 7 8 9 10 |
# File 'lib/ar_finder_form/column.rb', line 6 def initialize(table, name, *args) @table, @name = table, name @options = args. @static_values = args.empty? ? nil : args end |
Instance Attribute Details
#form_attr ⇒ Object (readonly)
Returns the value of attribute form_attr.
5 6 7 |
# File 'lib/ar_finder_form/column.rb', line 5 def form_attr @form_attr end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ar_finder_form/column.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/ar_finder_form/column.rb', line 4 def @options end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
4 5 6 |
# File 'lib/ar_finder_form/column.rb', line 4 def table @table end |
Instance Method Details
#build(context) ⇒ Object
16 17 18 |
# File 'lib/ar_finder_form/column.rb', line 16 def build(context) @form_attr.build(context) end |
#foreign_key? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/ar_finder_form/column.rb', line 24 def foreign_key? name = self.name.to_s table.model_class.reflections. any?{|key, ref| ref.primary_key_name == name} end |
#model_column ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ar_finder_form/column.rb', line 30 def model_column result = table.model_column_for(name) unless result.is_a?(ActiveRecord::ConnectionAdapters::Column) raise "Unsupported column object for #{table.name}.#{name}: #{result.inspect}" end result end |
#setup ⇒ Object
12 13 14 |
# File 'lib/ar_finder_form/column.rb', line 12 def setup send("setup_#{setup_type}") end |
#static? ⇒ Boolean
20 21 22 |
# File 'lib/ar_finder_form/column.rb', line 20 def static? !!@static_values end |
#type ⇒ Object
38 39 40 |
# File 'lib/ar_finder_form/column.rb', line 38 def type @options[:type] || model_column.type end |