Sha256: a888943f753a55e16e9f46f1cb5770c76f6065af8c4b985c3b2ca2e8cdcd2b76

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

module Virtus
  class Attribute

    # Example usage:
    #
    #   class Post
    #     include Virtus
    #
    #     attribute :published_on, Date
    #   end
    #
    #   Post.new(:published_on => Date.today)
    #
    #   # typecasting from a string
    #   Post.new(:published_on => '2011/06/09')
    #
    #   # typecasting from a hash
    #   Post.new(:published_on => { :year => 2011, :month => 6, :day => 9 })
    #
    #   # typecasting from an object which implements #to_date
    #   Post.new(:published_on => DateTime.now)
    #
    class Date < Object
      primitive ::Date

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

    end # class Date
  end # class Attribute
end # module Virtus

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
virtus-0.0.5 lib/virtus/attribute/date.rb
virtus-0.0.4 lib/virtus/attribute/date.rb