Module: ActionForm::SchemaDSL::ClassMethods
- Defined in:
- lib/action_form/schema_dsl.rb
Overview
rubocop:disable Style/Documentation
Instance Method Summary collapse
- #params_class ⇒ Object
-
#params_definition ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Instance Method Details
#params_class ⇒ Object
11 12 13 |
# File 'lib/action_form/schema_dsl.rb', line 11 def params_class EasyParams::Base end |
#params_definition ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_form/schema_dsl.rb', line 15 def params_definition(*) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength schema = Class.new(params_class) elements.each do |name, element_definition| if element_definition < ActionForm::SubformsCollection # nested forms are passed as a hash that looks like this: # { "0" => { "id" => "1" }, "1" => { "id" => "2" } } # it is coercing to an array of hashes: # [['0', { "id" => "1" }], ['1', { "id" => "2" }]] # we need to normalize it to an array of hashes: # [ { "id" => "1" }, { " # id" => "2" } ] schema.each(:"#{name}_attributes", element_definition.subform_definition.params_definition, normalize: ->(value) { value.flatten.select { |v| v.is_a?(Hash) } }, default: element_definition.default) elsif element_definition < ActionForm::Subform schema.has(:"#{name}_attributes", element_definition.params_definition, default: element_definition.default) elsif element_definition < ActionForm::Element = element_definition..dup method_name = .delete(:type) schema.public_send(method_name, name, **) end end schema end |