Sha256: 91e292e998fbe64b2f73298e1998a23c90b62f8eeabc7283095ae358a0bc0129

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

module Virtus
  class Attribute

    # Example usage:
    #
    #   class Post
    #     include Virtus
    #
    #     attribute :published_at, Time
    #   end
    #
    #   Post.new(:published_at => Time.now)
    #
    #   # typecasting from a string
    #   Post.new(:published_at => '2011/06/09 11:08')
    #
    #   # typecasting from a hash
    #   Post.new(:published_at => {
    #     :year    => 2011,
    #     :month   => 6,
    #     :day     => 9,
    #     :hour    => 11,
    #     :minutes => 8
    #   })
    #
    #   # typecasting from an object which implements #to_time
    #   Post.new(:published_at => DateTime.now)
    #
    class Time < Object
      primitive ::Time

      # @see Virtus::Typecast::Time.to_time
      #
      # @return [Time]
      #
      # @api private
      def typecast_to_primitive(value)
        Typecast::Time.to_time(value)
      end

    end # class Time
  end # class Attribute
end # module Virtus

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
virtus-0.0.5 lib/virtus/attribute/time.rb