Class: Reform::Form::Populator
- Inherits:
-
Object
- Object
- Reform::Form::Populator
- Includes:
- Uber::Callable
- Defined in:
- lib/reform/form/populator.rb
Overview
Implements the :populator option.
populator: -> (fragment, twin, options)
populator: -> (fragment, collection[twin], index, options)
For collections, the entire collection and the currently deserialised index is passed in.
Defined Under Namespace
Instance Method Summary collapse
- #call(form, fragment, *args) ⇒ Object
-
#initialize(user_proc) ⇒ Populator
constructor
A new instance of Populator.
Constructor Details
#initialize(user_proc) ⇒ Populator
Returns a new instance of Populator.
10 11 12 13 |
# File 'lib/reform/form/populator.rb', line 10 def initialize(user_proc) @user_proc = user_proc # the actual `populator: ->{}` block from the user, via ::property. @value = Uber::Options::Value.new(user_proc) # we can now process Callable, procs, :symbol. end |
Instance Method Details
#call(form, fragment, *args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/reform/form/populator.rb', line 15 def call(form, fragment, *args) = args.last # FIXME: the optional index parameter SUCKS. twin = call!(form, fragment, .binding.get, *args) # 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 = .binding.get unless .binding.array? # since Populator#call is invoked as :instance, we always need to return a twin/form here. handle_fail(twin, ) twin end |