Class: Appfuel::Validation::Validator
- Inherits:
-
Object
- Object
- Appfuel::Validation::Validator
- Defined in:
- lib/appfuel/validation/validator.rb
Overview
Any validator that is run for an action or command will be created with this class. It service to abstract away Dry::Validation, the library we use from the system that runs all the validators. This allows us to use validators along side things like validator pipes without the system having to care.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#call(inputs) ⇒ Dry::Validation::Result
Delegate’s to the Dry::Validation schema to validate the inputs.
-
#disable_fail_fast ⇒ Bool
Ensures the system will continue validating when errors exist.
-
#enable_fail_fast ⇒ Bool
Ensures the system will stop validating when this validator fails.
- #fail_fast? ⇒ Bool
- #initialize(name, schema, fail_fast: false) ⇒ Validator constructor
-
#pipe? ⇒ Boolean
Tell this system this is not a validation pipe.
Constructor Details
#initialize(name, schema, fail_fast: false) ⇒ Validator
15 16 17 18 19 20 21 22 23 |
# File 'lib/appfuel/validation/validator.rb', line 15 def initialize(name, schema, fail_fast: false) @name = name unless schema.respond_to?(:call) fail ArgumentError, "schema must implement :call" end @schema = schema fail_fast == true ? enable_fail_fast : disable_fail_fast end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/appfuel/validation/validator.rb', line 9 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
9 10 11 |
# File 'lib/appfuel/validation/validator.rb', line 9 def schema @schema end |
Instance Method Details
#call(inputs) ⇒ Dry::Validation::Result
Delegate’s to the Dry::Validation schema to validate the inputs
49 50 51 |
# File 'lib/appfuel/validation/validator.rb', line 49 def call(inputs) schema.call(inputs) end |
#disable_fail_fast ⇒ Bool
Ensures the system will continue validating when errors exist
35 36 37 |
# File 'lib/appfuel/validation/validator.rb', line 35 def disable_fail_fast @fail_fast = false end |
#enable_fail_fast ⇒ Bool
Ensures the system will stop validating when this validator fails
28 29 30 |
# File 'lib/appfuel/validation/validator.rb', line 28 def enable_fail_fast @fail_fast = true end |
#fail_fast? ⇒ Bool
40 41 42 |
# File 'lib/appfuel/validation/validator.rb', line 40 def fail_fast? @fail_fast end |
#pipe? ⇒ Boolean
Tell this system this is not a validation pipe
54 55 56 |
# File 'lib/appfuel/validation/validator.rb', line 54 def pipe? false end |