Class: Ukiryu::Validation::TypeConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- Ukiryu::Validation::TypeConstraint
- Defined in:
- lib/ukiryu/validation/constraints.rb
Overview
Validates type constraints using the Type module
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#validation_options ⇒ Object
readonly
Returns the value of attribute validation_options.
Instance Method Summary collapse
-
#initialize(attribute_name, type, validation_options: {}) ⇒ TypeConstraint
constructor
A new instance of TypeConstraint.
- #validate(value, _context = {}) ⇒ Object
Methods inherited from Constraint
Constructor Details
#initialize(attribute_name, type, validation_options: {}) ⇒ TypeConstraint
Returns a new instance of TypeConstraint.
119 120 121 122 123 |
# File 'lib/ukiryu/validation/constraints.rb', line 119 def initialize(attribute_name, type, validation_options: {}) @attribute_name = attribute_name @type = type @validation_options = end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
114 115 116 |
# File 'lib/ukiryu/validation/constraints.rb', line 114 def attribute_name @attribute_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
114 115 116 |
# File 'lib/ukiryu/validation/constraints.rb', line 114 def type @type end |
#validation_options ⇒ Object (readonly)
Returns the value of attribute validation_options.
114 115 116 |
# File 'lib/ukiryu/validation/constraints.rb', line 114 def @validation_options end |
Instance Method Details
#validate(value, _context = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ukiryu/validation/constraints.rb', line 126 def validate(value, _context = {}) return if value.nil? begin Type.validate(value, @type, @validation_options) rescue Ukiryu::Errors::ValidationError => e raise ValidationIssue.new(@attribute_name, :type, "#{@attribute_name}: #{e.}") end end |