Class: Super::Query::FormObject

Inherits:
Object
  • Object
show all
Defined in:
lib/super/query/form_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#addonsObject (readonly)

Returns the value of attribute addons.



17
18
19
# File 'lib/super/query/form_object.rb', line 17

def addons
  @addons
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



15
16
17
# File 'lib/super/query/form_object.rb', line 15

def namespace
  @namespace
end

#pathObject (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_pathObject



37
38
39
# File 'lib/super/query/form_object.rb', line 37

def to_partial_path
  "query"
end