Class: Formalist::Form
- Inherits:
-
Object
- Object
- Formalist::Form
- Extended by:
- Dry::Configurable
- Includes:
- Dry::Core::Constants
- Defined in:
- lib/formalist/form.rb,
lib/formalist/form/validity_check.rb
Defined Under Namespace
Classes: ValidityCheck
Class Attribute Summary collapse
-
.definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Class Method Summary collapse
Instance Method Summary collapse
-
#fill(input: {}, errors: {}) ⇒ Object
-
#initialize(elements: Undefined, input: {}, errors: {}, **dependencies) ⇒ Form
constructor
A new instance of Form.
-
#to_ast ⇒ Object
-
#with(**new_dependencies) ⇒ Object
Constructor Details
#initialize(elements: Undefined, input: {}, errors: {}, **dependencies) ⇒ Form
Returns a new instance of Form.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/formalist/form.rb', line 26 def initialize(elements: Undefined, input: {}, errors: {}, **dependencies) @input = input @errors = errors @elements = if elements == Undefined Definition.new(self, self.class.config, &self.class.definition).elements else elements end @dependencies = dependencies end |
Class Attribute Details
.definition ⇒ Object (readonly)
Returns the value of attribute definition.
14 15 16 |
# File 'lib/formalist/form.rb', line 14 def definition @definition end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
24 25 26 |
# File 'lib/formalist/form.rb', line 24 def dependencies @dependencies end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
21 22 23 |
# File 'lib/formalist/form.rb', line 21 def elements @elements end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
23 24 25 |
# File 'lib/formalist/form.rb', line 23 def errors @errors end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
22 23 24 |
# File 'lib/formalist/form.rb', line 22 def input @input end |
Class Method Details
.define(&block) ⇒ Object
16 17 18 |
# File 'lib/formalist/form.rb', line 16 def define(&block) @definition = block end |
Instance Method Details
#fill(input: {}, errors: {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/formalist/form.rb', line 40 def fill(input: {}, errors: {}) return self if input == @input && errors == @errors self.class.new( elements: @elements.map { |element| element.fill(input: input, errors: errors) }, input: input, errors: errors, **@dependencies, ) end |
#to_ast ⇒ Object
60 61 62 |
# File 'lib/formalist/form.rb', line 60 def to_ast elements.map(&:to_ast) end |
#with(**new_dependencies) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/formalist/form.rb', line 51 def with(**new_dependencies) self.class.new( elements: @elements, input: @input, errors: @errors, **@dependencies.merge(new_dependencies) ) end |