Class: SimpleFormObject::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type = nil, options) ⇒ Attribute

Returns a new instance of Attribute.



93
94
95
96
97
98
99
# File 'lib/simple_form_object.rb', line 93

def initialize(name, type = nil, options)
  @name = name
  @type = type || :string
  @options = options

  extract_options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



101
102
103
# File 'lib/simple_form_object.rb', line 101

def name
  @name
end

#optionsObject

Returns the value of attribute options.



101
102
103
# File 'lib/simple_form_object.rb', line 101

def options
  @options
end

#typeObject

Returns the value of attribute type.



101
102
103
# File 'lib/simple_form_object.rb', line 101

def type
  @type
end

Instance Method Details

#apply_default_to(form) ⇒ Object



107
108
109
110
111
# File 'lib/simple_form_object.rb', line 107

def apply_default_to(form)
  if form.send(@name).nil?
    form.send("#{@name}=", default_value(form)) if @apply_default
  end
end

#fake_columnObject



103
104
105
# File 'lib/simple_form_object.rb', line 103

def fake_column
  self
end