Class: MediaTypes::Scheme::MissingValidation
- Inherits:
-
Object
- Object
- MediaTypes::Scheme::MissingValidation
- Defined in:
- lib/media_types/scheme/missing_validation.rb
Instance Method Summary collapse
- #inspect ⇒ Object
- #keys_to_str(keys) ⇒ Object
- #raise_strict!(key:, backtrace:, strict_keys:, found:) ⇒ Object
- #validate!(_output, options, context:, **_opts) ⇒ Object
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/media_types/scheme/missing_validation.rb', line 30 def inspect '((raise when strict))' end |
#keys_to_str(keys) ⇒ Object
34 35 36 37 |
# File 'lib/media_types/scheme/missing_validation.rb', line 34 def keys_to_str(keys) converted = keys.map { |k| k.is_a?(Symbol) ? ":#{k}" : "'#{k}'" } "[#{converted.join ', '}]" end |
#raise_strict!(key:, backtrace:, strict_keys:, found:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/media_types/scheme/missing_validation.rb', line 15 def raise_strict!(key:, backtrace:, strict_keys:, found:) raise StrictValidationError, format( "Unknown key %<key>s in data.\n" \ "\tFound at: %<backtrace>s\n" \ "\tExpected:\n\n" \ "%<strict_keys>s\n\n" \ "\tBut I Found:\n\n" \ '%<found>s', key: key.inspect, backtrace: backtrace.join('->'), strict_keys: keys_to_str(strict_keys.keys), found: (found.respond_to? :keys) ? keys_to_str(found.keys) : found.class.name ) end |
#validate!(_output, options, context:, **_opts) ⇒ Object
9 10 11 12 13 |
# File 'lib/media_types/scheme/missing_validation.rb', line 9 def validate!(_output, , context:, **_opts) # Check that no unknown keys are present return true unless .strict raise_strict!(key: context.key, strict_keys: context.rules, backtrace: .backtrace, found: .scoped_output) end |