Sha256: 9b8aca62d0dfb25ae2f8c0eb7452bea4011546e85d3336018b2801e06aa0048e

Contents?: true

Size: 680 Bytes

Versions: 1

Compression:

Stored size: 680 Bytes

Contents

# prepopulate!(options)
# prepopulator: ->(model, user_options)
module Reform::Form::Prepopulate
  def prepopulate!(options={})
    prepopulate_local!(options)  # call #prepopulate! on local properties.
    prepopulate_nested!(options) # THEN call #prepopulate! on nested forms.

    self
  end

private
  def prepopulate_local!(options)
    schema.each do |dfn|
      next unless block = dfn[:prepopulator]
      Declarative::Option(block, instance_exec: true).(self, options)
    end
  end

  def prepopulate_nested!(options)
    schema.each(twin: true) do |dfn|
      Disposable::Twin::PropertyProcessor.new(dfn, self).() { |form| form.prepopulate!(options) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reform-2.2.4 lib/reform/form/prepopulate.rb