Class: Respect::UTCTimeSchema

Inherits:
NumericSchema show all
Defined in:
lib/respect/utc_time_schema.rb

Overview

A UTC time. It creates a Time object.

Instance Attribute Summary

Attributes inherited from Schema

#last_error, #options, #sanitized_object

Instance Method Summary (collapse)

Methods included from HasConstraints

#validate, #validate_constraints

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!, #validate?

Methods included from DocHelper

#description, #title

Constructor Details

This class inherits a constructor from Respect::Schema

Instance Method Details

- (Object) validate_type(object)



5
6
7
8
9
10
11
12
13
14
# File 'lib/respect/utc_time_schema.rb', line 5

def validate_type(object)
  value = super
  unless value.nil?
    if value < 0
      raise ValidationError,
            "UTC time value #{value} cannot be negative"
    end
    Time.at(value)
  end
end