Module: Reform::Form::Validate::Update
- Defined in:
- lib/reform/form/validate.rb
Instance Method Summary collapse
-
#from_hash ⇒ Object
Go through all nested forms and call form.update!(hash).
Instance Method Details
#from_hash ⇒ Object
Go through all nested forms and call form.update!(hash).
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/reform/form/validate.rb', line 8 def from_hash(*) nested_forms do |attr| attr.merge!( # set parse_strategy: sync> # DISCUSS: that kills the :setter directive, which usually sucks. at least document this in :populator. :collection => attr[:collection], # TODO: Def#merge! doesn't consider :collection if it's already set in attr YET. :parse_strategy => :sync, # just use nested objects as they are. # :getter grabs nested forms directly from fields bypassing the reader method which could possibly be overridden for presentation. :getter => lambda { || fields.send(.binding.name) }, :deserialize => lambda { |object, params, args| object.update!(params) }, ) # TODO: :populator now is just an alias for :instance. handle in ::property. attr.merge!(:instance => attr[:populator]) if attr[:populator] attr.merge!(:instance => Populator::PopulateIfEmpty.new) if attr[:populate_if_empty] end # FIXME: solve this with a dedicated Populate Decorator per Form. representable_attrs.each do |attr| attr.merge!(:parse_filter => Representable::Coercion::Coercer.new(attr[:coercion_type])) if attr[:coercion_type] end super end |