class Shaf::Formable::Builder
Constants
- DELEGATES
- InstanceAccessorType
Attributes
form[R]
forms[R]
Public Class Methods
new(&block)
click to toggle source
# File lib/shaf/formable/builder.rb, line 11 def initialize(&block) @forms = [] @instance_accessors = {} exec_with_form(block) end
Public Instance Methods
instance_accessor_for(form)
click to toggle source
# File lib/shaf/formable/builder.rb, line 18 def instance_accessor_for(form) @instance_accessors[form.action] end
Private Instance Methods
exec_with_form(block, action: nil)
click to toggle source
# File lib/shaf/formable/builder.rb, line 26 def exec_with_form(block, action: nil) current, @form = form, new_form form.action = action if action instance_exec(&block) ensure @form = current end
field(name, opts = {})
click to toggle source
# File lib/shaf/formable/builder.rb, line 49 def field(name, opts = {}) form.add_field(name, opts) end
instance_accessor(prefill: true)
click to toggle source
# File lib/shaf/formable/builder.rb, line 38 def instance_accessor(prefill: true) acc = InstanceAccessorType.new(prefill) @instance_accessors[form.action] = acc end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/shaf/formable/builder.rb, line 53 def method_missing(method, *args, &block) return super unless args.empty? && block exec_with_form(block, action: method) end
new_form()
click to toggle source
# File lib/shaf/formable/builder.rb, line 34 def new_form (form&.dup || Formable::Form.new).tap { |f| @forms << f } end
respond_to_missing?(*)
click to toggle source
# File lib/shaf/formable/builder.rb, line 58 def respond_to_missing?(*) true end