Class: GraphQL::Schema::Validator::FormatValidator
- Inherits:
-
GraphQL::Schema::Validator
- Object
- GraphQL::Schema::Validator
- GraphQL::Schema::Validator::FormatValidator
- Defined in:
- lib/graphql/schema/validator/format_validator.rb
Overview
Use this to assert that string values match (or don’t match) the given RegExp.
Constant Summary
Constants included from FindInheritedValue::EmptyObjects
FindInheritedValue::EmptyObjects::EMPTY_ARRAY, FindInheritedValue::EmptyObjects::EMPTY_HASH
Instance Attribute Summary
Attributes inherited from GraphQL::Schema::Validator
Instance Method Summary collapse
-
#initialize(with: nil, without: nil, message: "%{validated} is invalid", **default_options) ⇒ FormatValidator
constructor
A new instance of FormatValidator.
-
#validate(_object, _context, value) ⇒ Object
Methods inherited from GraphQL::Schema::Validator
from_config, install, #partial_format, #permitted_empty_value?, uninstall, validate!
Constructor Details
#initialize(with: nil, without: nil, message: "%{validated} is invalid", **default_options) ⇒ FormatValidator
Returns a new instance of FormatValidator.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/schema/validator/format_validator.rb', line 28 def initialize( with: nil, without: nil, message: "%{validated} is invalid", ** ) @with_pattern = with @without_pattern = without @message = super(**) end |
Instance Method Details
#validate(_object, _context, value) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/graphql/schema/validator/format_validator.rb', line 40 def validate(_object, _context, value) if value.nil? || (@with_pattern && !value.match?(@with_pattern)) || (@without_pattern && value.match?(@without_pattern)) @message end end |