Class: Reform::Form::Dry::NewApi::Validations::Group
- Inherits:
-
Object
- Object
- Reform::Form::Dry::NewApi::Validations::Group
- Includes:
- InputHash
- Defined in:
- lib/reform/form/dry/new_api.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#schema_inject_params ⇒ Object
readonly
Returns the value of attribute schema_inject_params.
-
#validator ⇒ Object
readonly
Returns the value of attribute validator.
Instance Method Summary collapse
- #call(form) ⇒ Object
-
#initialize(options = {}) ⇒ Group
constructor
A new instance of Group.
- #instance_exec(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Group
23 24 25 26 |
# File 'lib/reform/form/dry/new_api.rb', line 23 def initialize( = {}) @validator = .fetch(:schema, Contract) @schema_inject_params = .fetch(:with, {}) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
28 29 30 |
# File 'lib/reform/form/dry/new_api.rb', line 28 def block @block end |
#schema_inject_params ⇒ Object (readonly)
Returns the value of attribute schema_inject_params.
28 29 30 |
# File 'lib/reform/form/dry/new_api.rb', line 28 def schema_inject_params @schema_inject_params end |
#validator ⇒ Object (readonly)
Returns the value of attribute validator.
28 29 30 |
# File 'lib/reform/form/dry/new_api.rb', line 28 def validator @validator end |
Instance Method Details
#call(form) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/reform/form/dry/new_api.rb', line 34 def call(form) # when passing options[:schema] the class instance is already created so we just need to call # "call" return validator.call(input_hash(form)) unless validator.is_a?(Class) && @validator <= ::Dry::Validation::Contract = { form: form } = schema_inject_params.merge() validator.build(, &block).call(input_hash(form)) end |
#instance_exec(&block) ⇒ Object
30 31 32 |
# File 'lib/reform/form/dry/new_api.rb', line 30 def instance_exec(&block) @block = block end |