Class: Caisson::Helpers::Form::Builder::FieldBuilder::Nature

Inherits:
Object
  • Object
show all
Defined in:
lib/caisson/helpers/form/builder/field_builder/nature.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, name) ⇒ Nature

************************************************************************************* CONSTRUCTOR *************************************************************************************



9
10
11
12
# File 'lib/caisson/helpers/form/builder/field_builder/nature.rb', line 9

def initialize(record, name)
  @record = record
  @name = name.to_s
end

Class Method Details

.allObject

************************************************************************************* PUBLIC CLASS METHODS *************************************************************************************



18
19
20
21
22
# File 'lib/caisson/helpers/form/builder/field_builder/nature.rb', line 18

def self.all
  ['checkbox', 'password', 'percent', 'select', 'text', 'textarea']
  #TODO
  #'autocomplete', 'check-icon', 'country', 'file', 'money', 'static', 'switch', 'radio', 'upload', 'ticklist', 'time_field'
end

Instance Method Details

#get(options = {}) ⇒ Object

************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/caisson/helpers/form/builder/field_builder/nature.rb', line 28

def get(options={})
  options.reverse_merge!(force: nil)

  if options[:force]
    return force(options[:force])
  elsif @record.fields[@name]
    return case @record.fields[@name].options[:type].to_s.downcase
      when 'array' then 'ticklist'
      when 'boolean' then 'checkbox'
      when 'percent' then 'percent'
      when 'time' then 'time_field'
      else nature_by_name
    end
  else
    return nature_by_name
  end
end