class Formalism::Form
Class for forms
Attributes
instance[R]
Public Class Methods
inherited(child)
click to toggle source
Calls superclass method
# File lib/formalism/form.rb, line 16 def self.inherited(child) super child.fields_and_nested_forms.merge!(fields_and_nested_forms) end
new(params_or_instance = {})
click to toggle source
Calls superclass method
Formalism::Action::new
# File lib/formalism/form.rb, line 22 def initialize(params_or_instance = {}) if params_or_instance.is_a?(Hash) super else super({}) @instance = params_or_instance end fill_fields_and_nested_forms end
Public Instance Methods
run()
click to toggle source
Calls superclass method
Formalism::Action::run
# File lib/formalism/form.rb, line 50 def run return unless runnable return Outcome.new(errors) unless valid? Outcome.new(errors, super) end
valid?()
click to toggle source
# File lib/formalism/form.rb, line 34 def valid? return unless runnable errors.clear nested_forms.each_value(&:valid?) validate merge_errors_of_nested_forms return false if errors.any? true end
Protected Instance Methods
errors()
click to toggle source
# File lib/formalism/form.rb, line 60 def errors @errors ||= Set.new end
Private Instance Methods
instance_public_send(name)
click to toggle source
# File lib/formalism/form.rb, line 74 def instance_public_send(name) return false unless defined? @instance @instance.public_send(name) end
instance_respond_to?(name)
click to toggle source
# File lib/formalism/form.rb, line 68 def instance_respond_to?(name) return false unless defined? @instance @instance.respond_to?(name) end
merge_errors_of_nested_form(_name, nested_form)
click to toggle source
# File lib/formalism/form.rb, line 91 def merge_errors_of_nested_form(_name, nested_form) errors.merge nested_form.errors end
merge_errors_of_nested_forms()
click to toggle source
# File lib/formalism/form.rb, line 80 def merge_errors_of_nested_forms nested_forms.each do |name, nested_form| should_be_merged = self.class.fields_and_nested_forms[name].fetch(:merge_errors, true) should_be_merged = instance_exec(&should_be_merged) if should_be_merged.is_a?(Proc) next unless should_be_merged && nested_form.errors.any? merge_errors_of_nested_form name, nested_form end end
validate()
click to toggle source
# File lib/formalism/form.rb, line 66 def validate; end