Class: ArFinderForm::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_finder_form/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.extract_options!
  @static_values = args.empty? ? nil : args
end

Instance Attribute Details

#form_attrObject (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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ar_finder_form/column.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/ar_finder_form/column.rb', line 4

def options
  @options
end

#tableObject (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

Returns:

  • (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_columnObject



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

#setupObject



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

def setup
  send("setup_#{setup_type}")
end

#static?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ar_finder_form/column.rb', line 20

def static?
  !!@static_values
end

#typeObject



38
39
40
# File 'lib/ar_finder_form/column.rb', line 38

def type
  @options[:type] || model_column.type
end