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, options, type = nil) ⇒ Attribute

Returns a new instance of Attribute.



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

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

  extract_options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



114
115
116
# File 'lib/simple_form_object.rb', line 114

def name
  @name
end

#optionsObject

Returns the value of attribute options.



114
115
116
# File 'lib/simple_form_object.rb', line 114

def options
  @options
end

#typeObject

Returns the value of attribute type.



114
115
116
# File 'lib/simple_form_object.rb', line 114

def type
  @type
end

Instance Method Details

#apply_default_to(form) ⇒ Object



120
121
122
123
124
# File 'lib/simple_form_object.rb', line 120

def apply_default_to(form)
  return unless form.send(@name).nil?

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

#fake_columnObject



116
117
118
# File 'lib/simple_form_object.rb', line 116

def fake_column
  self
end