Class: BaseFormObject
- Inherits:
-
Object
- Object
- BaseFormObject
- 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.
Direct Known Subclasses
Instance Method Summary collapse
-
#attributes ⇒ Hash{Symbol => Object}
Return symbol-keyed hash for backward compatibility with code that does attributes[:foo] or attributes.reject { |k, _| k.in?(%i[...]) }.
-
#initialize(attributes = {}) ⇒ BaseFormObject
constructor
Builds the form object from the given attributes.
-
#persisted? ⇒ Boolean
Form objects are never persisted records.
Constructor Details
#initialize(attributes = {}) ⇒ BaseFormObject
Builds the form object from the given attributes.
28 29 30 |
# File 'app/forms/base_form_object.rb', line 28 def initialize(attributes = {}) super end |
Instance Method Details
#attributes ⇒ Hash{Symbol => Object}
Return symbol-keyed hash for backward compatibility with code that does
attributes[:foo] or attributes.reject { |k, _| k.in?(%i[...]) }.
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.
21 22 23 |
# File 'app/forms/base_form_object.rb', line 21 def persisted? false end |