Class: Snapi::JsonValidator
- Inherits:
-
Object
- Object
- Snapi::JsonValidator
- Defined in:
- lib/snapi/validator.rb
Overview
Provide an object to validate JSON with a =~ method that mirrors Regexp.=~. The existing validation code relies on the fact that Regexp.=~ will return the index for which the string matches the regex. We return 0 if the JSON is parsable, since the JSON string will always start at index 0.
Class Method Summary collapse
Class Method Details
.=~(obj) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/snapi/validator.rb', line 131 def self.=~(obj) begin JSON.parse(obj) 0 rescue nil end end |