Class: Acfs::Resource::Attributes::DateTime

Inherits:
Base
  • Object
show all
Defined in:
lib/acfs/resource/attributes/date_time.rb

Overview

DateTime attribute type. Use it in your model as an attribute type:

Examples:

class User < Acfs::Resource
  attribute :name, :date_time
end

Instance Attribute Summary

Attributes inherited from Base

#default

Instance Method Summary collapse

Methods inherited from Base

#cast, #default_value, #initialize

Constructor Details

This class inherits a constructor from Acfs::Resource::Attributes::Base

Instance Method Details

#cast_value(value) ⇒ DateTime

Cast given object to DateTime.

Parameters:

  • value (Object)

    Object to cast.

Returns:

  • (DateTime)

    Casted object as DateTime.



22
23
24
25
26
27
28
29
30
# File 'lib/acfs/resource/attributes/date_time.rb', line 22

def cast_value(value)
  if value.blank?
    nil
  elsif !value.is_a?(::String) && value.respond_to?(:to_datetime)
    value.to_datetime
  else
    ::DateTime.iso8601 value
  end
end