Class: Restspec::Schema::Types::DateTimeType

Inherits:
BasicType
  • Object
show all
Defined in:
lib/restspec/schema/types/datetime_type.rb

Instance Method Summary collapse

Methods inherited from BasicType

#initialize, #of, #to_s, #totally_valid?, #|

Constructor Details

This class inherits a constructor from Restspec::Schema::Types::BasicType

Instance Method Details

#example_for(attribute) ⇒ Object



3
4
5
# File 'lib/restspec/schema/types/datetime_type.rb', line 3

def example_for(attribute)
  Faker::Time.between(initial_example_interval, final_example_interval).iso8601
end

#valid?(attribute, value) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
# File 'lib/restspec/schema/types/datetime_type.rb', line 7

def valid?(attribute, value)
  return false unless value.present?
  allowed_date_time_formats.any? do |format|
    DateTime.parse(value).strftime(format) == value
  end
rescue ArgumentError
  false
end