Module: Roda::RodaPlugins::FormeSet::InstanceMethods
- Defined in:
- lib/roda/plugins/forme_set.rb
Instance Method Summary collapse
-
#form(obj = nil, attr = {}, opts = {}, &block) ⇒ Object
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.
-
#forme_parse(obj) ⇒ Object
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.
-
#forme_set(obj) ⇒ Object
Set fields on the object based on submitted parameters, as well as validations for associated object values.
Instance Method Details
#form(obj = nil, attr = {}, opts = {}, &block) ⇒ Object
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.
44 45 46 47 48 49 50 |
# File 'lib/roda/plugins/forme_set.rb', line 44 def form(obj=nil, attr={}, opts={}, &block) if obj.is_a?(Sequel::Plugins::FormeSet::InstanceMethods) obj.isolate_forme_inputs{super} else super end end |
#forme_parse(obj) ⇒ Object
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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/roda/plugins/forme_set.rb', line 55 def forme_parse(obj) h = _forme_parse(obj) params = h.delete(:params) columns = h.delete(:columns) h[:validations] ||= {} values = h[:values] = {} columns.each do |col| values[col.to_sym] = params[col] end h end |
#forme_set(obj) ⇒ Object
Set fields on the object based on submitted parameters, as well as validations for associated object values.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/roda/plugins/forme_set.rb', line 72 def forme_set(obj) h = _forme_parse(obj) obj.set_fields(h[:params], h[:columns]) if h[:validations] obj.forme_validations.merge!(h[:validations]) end if block_given? yield h[:form_version], obj end obj end |