class SimpleFormObject::Attribute

Attributes

name[RW]
options[RW]
type[RW]

Public Class Methods

new(name, type = nil, options) click to toggle source
# File lib/simple_form_object.rb, line 93
def initialize(name, type = nil, options)
  @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 107
def apply_default_to(form)
  if form.send(@name).nil?
    form.send("#{@name}=", default_value(form)) if @apply_default
  end
end
fake_column() click to toggle source
# File lib/simple_form_object.rb, line 103
def fake_column
  self
end

Private Instance Methods

default_value(context) click to toggle source
# File lib/simple_form_object.rb, line 115
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 123
def extract_options
  @apply_default = true
  @default = options.fetch(:default) { @apply_default = false; nil }
  @skip_validations = options.fetch(:skip_validations, false)
end