Class: Respect::NullSchema

Inherits:
Schema
  • Object
show all
Defined in:
lib/respect/null_schema.rb

Instance Attribute Summary

Attributes inherited from Schema

#last_error, #options, #sanitized_object

Instance Method Summary (collapse)

Methods inherited from Schema

#==, #allow_nil?, def_class, def_class_name, #default, default_options, define, #documentation, #documented?, #has_default?, #initialize, #initialize_copy, #inspect, #non_default_options, #optional?, #required?, #sanitize!, #sanitize_object!, statement_name, #to_h, #to_json, #to_s, #validate!, #validate?

Methods included from DocHelper

#description, #title

Constructor Details

This class inherits a constructor from Respect::Schema

Instance Method Details

- (Object) validate(object)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/respect/null_schema.rb', line 6

def validate(object)
  case object
  when String
    if object == "null"
      self.sanitized_object = nil
      true
    else
      raise ValidationError,
            "expected 'null' value but got '#{object}:#{object.class}'"
    end
  when NilClass
    self.sanitized_object = nil
    true
  else
    raise ValidationError,
          "object is not of null type but a #{object.class}"
  end
end