Class: Ippon::Validate::Step
Overview
Step is the common class for all schemas that does actual validation and transformation on the value (as opposed to just combining other schemas).
Every Step class take a props
Hash in their constructor and you are free to store arbitrary data here. You can later access this data from the StepError object (through StepError#step) and for instance use it to customize error reporting.
The :message
property will override the default error message produced by StepError#message and #message.
Instance Attribute Summary collapse
-
#props ⇒ Hash
readonly
Properties for this step.
Instance Method Summary collapse
-
#initialize(props = {}, &processor) ⇒ Step
constructor
A new instance of Step.
-
#message ⇒ String
The error message for this step.
-
#process(result) ⇒ Object
Implements the Ippon::Validate::Schema#process interface.
-
#type ⇒ String?
The type of this step.
Methods inherited from Schema
#&, #unhalt, #validate, #validate!, #|
Constructor Details
#initialize(props = {}, &processor) ⇒ Step
Returns a new instance of Step.
792 793 794 795 |
# File 'lib/ippon/validate.rb', line 792 def initialize(props = {}, &processor) @props = props.freeze @processor = processor end |
Instance Attribute Details
#props ⇒ Hash (readonly)
Returns properties for this step.
789 790 791 |
# File 'lib/ippon/validate.rb', line 789 def props @props end |
Instance Method Details
#message ⇒ String
The error message for this step.
This will return the :message
property, failing back to “must be valid” if it’s missing.
803 804 805 |
# File 'lib/ippon/validate.rb', line 803 def @props.fetch(:message, "must be valid") end |
#process(result) ⇒ Object
Implements the Ippon::Validate::Schema#process interface.
818 819 820 |
# File 'lib/ippon/validate.rb', line 818 def process(result) @processor.call(result) end |
#type ⇒ String?
The type of this step.
This will return the :type
property, failing back to nil
if it’s missing.
813 814 815 |
# File 'lib/ippon/validate.rb', line 813 def type @props[:type] end |