Class: Operations::Form
- Inherits:
-
Object
- Object
- Operations::Form
- Includes:
- Dry::Core::Constants
- Defined in:
- lib/operations/form.rb
Overview
Configures and defines a form object factory. Forms can be defined on top of commants and used in the user-facing controllers. Form objects are Rails-specific and support everything that is needed for Rails’ form rendering helpers. They are designed to replace direct usage of ActiveRecord models in controllers and views and act as an integration bridge from Rails application to the Operations framework.
Defined Under Namespace
Classes: Attribute, Base, Builder, DeprecatedLegacyModelMapImplementation
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
We need to make deprecated inheritance from Operations::Form act exactly the same way as from Operations::Form::Base.
Instance Method Summary collapse
- #build(params = EMPTY_HASH, **context) ⇒ Object
- #form_class ⇒ Object
- #persist(params = EMPTY_HASH, **context) ⇒ Object
Class Method Details
.inherited(subclass) ⇒ Object
We need to make deprecated inheritance from Operations::Form act exactly the same way as from Operations::Form::Base. In order to do this, we are encapsulating all the inheritable functionality in 2 modules and removing methods defined in Operations::Form from the result class.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/operations/form.rb', line 31 def self.inherited(subclass) super return unless self == Operations::Form ActiveSupport::Deprecation.new.warn("Inheritance from Operations::Form is deprecated and will be " \ "removed in 1.0.0. Please inherit from Operations::Form::Base instead") (Operations::Form.instance_methods - Object.instance_methods).each do |method| subclass.undef_method(method) end subclass.extend Operations::Form::Base::ClassMethods subclass.prepend Operations::Form::Base::InstanceMethods end |
Instance Method Details
#build(params = EMPTY_HASH, **context) ⇒ Object
57 58 59 |
# File 'lib/operations/form.rb', line 57 def build(params = EMPTY_HASH, **context) instantiate_form(command.callable(transform_params(params, **context), **context)) end |
#form_class ⇒ Object
65 66 67 68 |
# File 'lib/operations/form.rb', line 65 def form_class @form_class ||= Operations::Form::Builder.new(base_class: base_class) .build(key_map: key_map, model_map: model_map, model_name: model_name) end |
#persist(params = EMPTY_HASH, **context) ⇒ Object
61 62 63 |
# File 'lib/operations/form.rb', line 61 def persist(params = EMPTY_HASH, **context) instantiate_form(command.call(transform_params(params, **context), **context)) end |