module Roda::RodaPlugins::FormeSet::InstanceMethods

  1. lib/roda/plugins/forme_set.rb

Methods

Public Instance

  1. form
  2. forme_parse
  3. forme_set

Public Instance methods

form(obj=nil, attr={}, opts={}, &block)

If a Sequel::Model object that supports forme_set is passed, isolate the inputs so that each form only includes metadata for inputs on the form, and not inputs for earlier forms on the same page.

[show source]
   # File lib/roda/plugins/forme_set.rb
44 def form(obj=nil, attr={}, opts={}, &block)
45   if obj.is_a?(Sequel::Plugins::FormeSet::InstanceMethods)
46     obj.isolate_forme_inputs{super}
47   else
48     super
49   end
50 end
forme_parse(obj)

Return hash based on submitted parameters, with :values key being submitted values for the object, and :validations key being a hash of validation metadata for the object.

[show source]
   # File lib/roda/plugins/forme_set.rb
55 def forme_parse(obj)
56   h = _forme_parse(obj)
57   
58   params = h.delete(:params)
59   columns = h.delete(:columns)
60   h[:validations] ||= {}
61 
62   values = h[:values] = {}
63   columns.each do |col|
64     values[col.to_sym] = params[col]
65   end
66 
67   h
68 end
forme_set(obj)

Set fields on the object based on submitted parameters, as well as validations for associated object values.

[show source]
   # File lib/roda/plugins/forme_set.rb
72 def forme_set(obj)
73   h = _forme_parse(obj)
74 
75   obj.set_fields(h[:params], h[:columns])
76 
77   if h[:validations]
78     obj.forme_validations.merge!(h[:validations])
79   end
80 
81   if block_given?
82     yield h[:form_version], obj
83   end
84 
85   obj
86 end