Sha256: 34ed250126f0154576e1c09ade4fe5b1b68a293685044b0059fd5c315ebdfb04

Contents?: true

Size: 518 Bytes

Versions: 21

Compression:

Stored size: 518 Bytes

Contents

require 'active_support/core_ext/date/conversions'
require 'active_support/core_ext/string/conversions'

module MongoModel
  module Types
    class Date < Object
      def cast(value)
        case value
        when ::Array
          ::Date.new(*value)
        else
          value.to_date
        end
      rescue
        nil
      end
      
      def to_mongo(value)
        value.strftime("%Y/%m/%d") if value
      end
      
      def from_mongo(value)
        value.to_date if value
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mongomodel-0.4.3 lib/mongomodel/support/types/date.rb
mongomodel-0.4.2 lib/mongomodel/support/types/date.rb
mongomodel-0.4.1 lib/mongomodel/support/types/date.rb
mongomodel-0.4.0 lib/mongomodel/support/types/date.rb
mongomodel-0.3.6 lib/mongomodel/support/types/date.rb
mongomodel-0.3.5 lib/mongomodel/support/types/date.rb
mongomodel-0.3.4 lib/mongomodel/support/types/date.rb
mongomodel-0.3.3 lib/mongomodel/support/types/date.rb
mongomodel-0.3.2 lib/mongomodel/support/types/date.rb
mongomodel-0.3.1 lib/mongomodel/support/types/date.rb
mongomodel-0.3.0 lib/mongomodel/support/types/date.rb
mongomodel-0.2.20 lib/mongomodel/support/types/date.rb
mongomodel-0.2.19 lib/mongomodel/support/types/date.rb
mongomodel-0.2.18 lib/mongomodel/support/types/date.rb
mongomodel-0.2.17 lib/mongomodel/support/types/date.rb
mongomodel-0.2.16 lib/mongomodel/support/types/date.rb
mongomodel-0.2.15 lib/mongomodel/support/types/date.rb
mongomodel-0.2.14 lib/mongomodel/support/types/date.rb
mongomodel-0.2.13 lib/mongomodel/support/types/date.rb
mongomodel-0.2.12 lib/mongomodel/support/types/date.rb