Class: Reform::Form::Populator::IfEmpty

Inherits:
Reform::Form::Populator show all
Defined in:
lib/reform/form/populator.rb

Overview

Populator

Instance Method Summary collapse

Methods inherited from Reform::Form::Populator

#call, #initialize

Constructor Details

This class inherits a constructor from Reform::Form::Populator

Instance Method Details

#call!(form, fragment, twin, *args) ⇒ Object

FIXME: the optional index parameter SUCKS.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/reform/form/populator.rb', line 46

def call!(form, fragment, twin, *args)
  options = args.last

  if options.binding.array? # FIXME: ifs suck.
    index = args.first
    item = twin.original[index] and return item

    twin.insert(index, run!(form, fragment, options)) # form.songs.insert(Song.new)
  else
    return if twin

    form.send(options.binding.setter, run!(form, fragment, options)) # form.artist=(Artist.new)
  end
end