Class: Reform::Form::Populator
- Inherits:
-
Object
- Object
- Reform::Form::Populator
- Defined in:
- lib/reform/form/populator.rb
Overview
Implements the :populator option.
populator: -> (fragment:, model:, :binding)
populator: -> (fragment:, collection:, index:, binding:)
For collections, the entire collection and the currently deserialised index is passed in.
Defined Under Namespace
Classes: External, IfEmpty, Sync
Instance Method Summary collapse
- #call(input, options) ⇒ Object
-
#initialize(user_proc) ⇒ Populator
constructor
A new instance of Populator.
Constructor Details
#initialize(user_proc) ⇒ Populator
Returns a new instance of Populator.
8 9 10 11 |
# File 'lib/reform/form/populator.rb', line 8 def initialize(user_proc) @user_proc = user_proc # the actual `populator: ->{}` block from the user, via ::property. @value = ::Representable::Option(user_proc) # we can now process Callable, procs, :symbol. end |
Instance Method Details
#call(input, options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/reform/form/populator.rb', line 13 def call(input, ) model = get() twin = call!(.merge(model: model, collection: model)) return twin if twin == Representable::Pipeline::Stop # this kinda sucks. the proc may call self.composer = Artist.new, but there's no way we can # return the twin instead of the model from the #composer= setter. twin = get() unless [:binding].array? # we always need to return a twin/form here so we can call nested.deserialize(). handle_fail(twin, ) twin end |