Sha256: 121a207511a966955c26b0d941b00f1a46bc12c8f4658ac03f9bfd24387dd087

Contents?: true

Size: 1.5 KB

Versions: 28

Compression:

Stored size: 1.5 KB

Contents

# encoding: utf-8
module Mongoid
  module Extensions
    module TimeWithZone

      # Turn the object from the ruby type we deal with to a Mongo friendly
      # type.
      #
      # @example Mongoize the object.
      #   date_time.mongoize
      #
      # @return [ Time ] The object mongoized.
      #
      # @since 3.0.0
      def mongoize
        ::ActiveSupport::TimeWithZone.mongoize(self)
      end

      module ClassMethods

        # Convert the object from its mongo friendly ruby type to this type.
        #
        # @example Demongoize the object.
        #   TimeWithZone.demongoize(object)
        #
        # @param [ Time ] object The time from Mongo.
        #
        # @return [ TimeWithZone ] The object as a date.
        #
        # @since 3.0.0
        def demongoize(object)
          return nil if object.blank?
          ::Time.demongoize(object).in_time_zone
        end

        # Turn the object from the ruby type we deal with to a Mongo friendly
        # type.
        #
        # @example Mongoize the object.
        #   TimeWithZone.mongoize("2012-1-1")
        #
        # @param [ Object ] object The object to convert.
        #
        # @return [ Time ] The object mongoized.
        #
        # @since 3.0.0
        def mongoize(object)
          ::Time.mongoize(object)
        end
      end
    end
  end
end

::ActiveSupport::TimeWithZone.__send__(:include, Mongoid::Extensions::TimeWithZone)
::ActiveSupport::TimeWithZone.__send__(:extend, Mongoid::Extensions::TimeWithZone::ClassMethods)

Version data entries

28 entries across 28 versions & 5 rubygems

Version Path
mongoid-3.1.7 lib/mongoid/extensions/time_with_zone.rb
mongoid-4.0.0.alpha1 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.6 lib/mongoid/extensions/time_with_zone.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/extensions/time_with_zone.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.5 lib/mongoid/extensions/time_with_zone.rb
mongoid_heroku_stable-4.0.0 lib/mongoid/extensions/time_with_zone.rb
mongoid_rails4-4.0.0 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.4 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.3 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.2 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.23 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.1 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.1.0 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.22 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.21 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.20 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.19 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.18 lib/mongoid/extensions/time_with_zone.rb
mongoid-3.0.17 lib/mongoid/extensions/time_with_zone.rb