Class: Formalism::Form
- Inherits:
-
Action
show all
- Includes:
- Fields
- Defined in:
- lib/formalism/form.rb,
lib/formalism/form/fields.rb,
lib/formalism/form/filling.rb,
lib/formalism/form/outcome.rb,
lib/formalism/form/coercion.rb,
lib/formalism/form/coercion/date.rb,
lib/formalism/form/coercion/hash.rb,
lib/formalism/form/coercion/time.rb,
lib/formalism/form/coercion/_base.rb,
lib/formalism/form/coercion/array.rb,
lib/formalism/form/coercion/class.rb,
lib/formalism/form/coercion/float.rb,
lib/formalism/form/coercion/object.rb,
lib/formalism/form/coercion/string.rb,
lib/formalism/form/coercion/symbol.rb,
lib/formalism/form/coercion/boolean.rb,
lib/formalism/form/coercion/integer.rb,
lib/formalism/form/validation_error.rb,
lib/formalism/form/coercion/_numeric.rb,
lib/formalism/form/coercion/bigdecimal.rb
Overview
Defined Under Namespace
Modules: Fields
Classes: Coercion, NoCoercionError, Outcome, ValidationError
Instance Attribute Summary collapse
Attributes inherited from Action
#params, #runnable
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Fields
#fields, #to_params
Methods inherited from Action
run
Constructor Details
#initialize(params_or_instance = {}) ⇒ Form
22
23
24
25
26
27
28
29
30
31
32
|
# 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
|
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
14
15
16
|
# File 'lib/formalism/form.rb', line 14
def instance
@instance
end
|
Class Method Details
.inherited(child) ⇒ Object
16
17
18
19
20
|
# File 'lib/formalism/form.rb', line 16
def self.inherited(child)
super
child.fields_and_nested_forms.merge!(fields_and_nested_forms)
end
|
Instance Method Details
#run ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/formalism/form.rb', line 53
def run
return unless runnable
return Outcome.new(errors) unless valid?
Outcome.new(errors, super)
end
|
#valid? ⇒ Boolean
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# 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
|