Sha256: d113e069d71f91b465db21260c6d94923dc5c2a1ec17ecf38696a9b86ecfcf71

Contents?: true

Size: 584 Bytes

Versions: 1

Compression:

Stored size: 584 Bytes

Contents

require 'faker'

module JSONAPIonify::Types
  class DateStringType < BaseType
    def load(value)
      Date.parse value
    end

    def dump(value)
      case value
      when Date
        JSON.load JSON.dump(value.to_date)
      else
        raise TypeError, "#{value} is not a valid JSON #{name}."
      end
    end

    def sample(field_name)
      field_name = field_name.to_s
      if field_name.to_s.end_with?('ed_at') || field_name.include?('start')
        Faker::Date.backward
      elsif field_name.include?('end')
        Faker::Date.forward
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonapionify-0.9.0 lib/jsonapionify/types/date_string_type.rb