Class: RegexpValidation
- Inherits:
-
Validation
- Object
- Validation
- RegexpValidation
- Defined in:
- lib/json_patterns.rb
Constant Summary
Constants included from Inspectable
Instance Attribute Summary collapse
-
#regexp ⇒ Object
Returns the value of attribute regexp.
Instance Method Summary collapse
Methods inherited from Validation
#as_object_members, #expects_an_object?, memoized_new_from_pattern, new_from_pattern, #shallow_describe, #shallow_match?, #validate_from_root
Methods included from HashInitialized
Methods included from DeepEquality
Methods included from Inspectable
Instance Attribute Details
#regexp ⇒ Object
Returns the value of attribute regexp.
959 960 961 |
# File 'lib/json_patterns.rb', line 959 def regexp @regexp end |
Instance Method Details
#to_s ⇒ Object
977 978 979 |
# File 'lib/json_patterns.rb', line 977 def to_s @regexp.inspect end |
#validate(path, data) ⇒ Object
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
# File 'lib/json_patterns.rb', line 961 def validate(path, data) if data.is_a? String if data =~ regexp return [] else return [ValidationUnexpected.new( path: path, expected: "string matching #{@regexp.inspect}", found: data.inspect, )] end else return [ValidationUnexpected.new(path: path, expected: 'string', found: json_type_name(data))] end end |