Class: Super::Query::FormObject
- Inherits:
-
Object
- Object
- Super::Query::FormObject
- Defined in:
- lib/super/query/form_object.rb
Instance Attribute Summary collapse
-
#addons ⇒ Object
readonly
Returns the value of attribute addons.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add(klass, namespace:, **additional_initialization_arguments) ⇒ Object
- #apply_changes(records) ⇒ Object
-
#initialize(model:, params:, namespace:, current_path:) ⇒ FormObject
constructor
A new instance of FormObject.
- #to_partial_path ⇒ Object
Constructor Details
#initialize(model:, params:, namespace:, current_path:) ⇒ FormObject
Returns a new instance of FormObject.
6 7 8 9 10 11 12 13 |
# File 'lib/super/query/form_object.rb', line 6 def initialize(model:, params:, namespace:, current_path:) @model = model @all_params = params.dup @namespace = namespace @params = params[namespace] || ActionController::Parameters.new @path = current_path @addons = {} end |
Instance Attribute Details
#addons ⇒ Object (readonly)
Returns the value of attribute addons.
17 18 19 |
# File 'lib/super/query/form_object.rb', line 17 def addons @addons end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
15 16 17 |
# File 'lib/super/query/form_object.rb', line 15 def namespace @namespace end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/super/query/form_object.rb', line 16 def path @path end |
Instance Method Details
#add(klass, namespace:, **additional_initialization_arguments) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/super/query/form_object.rb', line 19 def add(klass, namespace:, **additional_initialization_arguments) instance = klass.new( model: @model, params: params_dig(namespace), **additional_initialization_arguments ) addons[namespace] = instance end |
#apply_changes(records) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/super/query/form_object.rb', line 29 def apply_changes(records) addons.each_value do |addon| records = addon.apply_changes(records) end records end |
#to_partial_path ⇒ Object
37 38 39 |
# File 'lib/super/query/form_object.rb', line 37 def to_partial_path "query" end |