class SimpleFormObject::Attribute
Attributes
name[RW]
options[RW]
type[RW]
Public Class Methods
new(name, options, type = nil)
click to toggle source
# File lib/simple_form_object.rb, line 106 def initialize(name, options, type = nil) @name = name @type = type || :string @options = options extract_options end
Public Instance Methods
apply_default_to(form)
click to toggle source
# 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_column()
click to toggle source
# File lib/simple_form_object.rb, line 116 def fake_column self end
Private Instance Methods
default_value(context)
click to toggle source
# File lib/simple_form_object.rb, line 128 def default_value(context) if @default.respond_to?(:call) context.instance_eval(&@default) else @default end end
extract_options()
click to toggle source
# File lib/simple_form_object.rb, line 136 def extract_options @apply_default = true @default = options.fetch(:default) do @apply_default = false nil end @skip_validations = options.fetch(:skip_validations, false) end