Class: BaseFormObject

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Validations::Callbacks, StripAttributes
Defined in:
app/forms/base_form_object.rb

Overview

Base class for form objects.

Combines ActiveModel::Model, ActiveModel::Attributes, attribute
stripping, and validation callbacks so subclasses can model
non-persisted forms with typed attributes and validations.

See Also:

  • StripAttributes

Direct Known Subclasses

Image::Transform, Lead

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ BaseFormObject

Builds the form object from the given attributes.

Parameters:

  • attributes (Hash) (defaults to: {})

    attribute names and values to assign



28
29
30
# File 'app/forms/base_form_object.rb', line 28

def initialize(attributes = {})
  super
end

Instance Method Details

#attributesHash{Symbol => Object}

Return symbol-keyed hash for backward compatibility with code that does
attributes[:foo] or attributes.reject { |k, _| k.in?(%i[...]) }.

Returns:

  • (Hash{Symbol => Object})

    attributes keyed by symbol



36
37
38
# File 'app/forms/base_form_object.rb', line 36

def attributes
  super.transform_keys(&:to_sym)
end

#persisted?Boolean

Form objects are never persisted records.

Returns:

  • (Boolean)

    always false



21
22
23
# File 'app/forms/base_form_object.rb', line 21

def persisted?
  false
end