Sha256: 06a9435357a6ba5ffe38b5495abce2ad008393f9bfbe71d6f7752165a2037eba

Contents?: true

Size: 1.37 KB

Versions: 27

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Extensions
    module Float

      # Converts the float into a time as the number of seconds since the epoch.
      #
      # @example Convert the float into a time.
      #   1335532685.117847.__mongoize_time__
      #
      # @return [ Time | ActiveSupport::TimeWithZone ] The time.
      #
      # @since 3.0.0
      def __mongoize_time__
        ::Time.configured.at(self)
      end

      # Is the float a number?
      #
      # @example Is the object a number?.
      #   object.numeric?
      #
      # @return [ true ] Always true.
      #
      # @since 3.0.0
      def numeric?
        true
      end

      module ClassMethods

        # Turn the object from the ruby type we deal with to a Mongo friendly
        # type.
        #
        # @example Mongoize the object.
        #   Float.mongoize("123.11")
        #
        # @param [ Object ] object The object to mongoize.
        #
        # @return [ String ] The object mongoized.
        #
        # @since 3.0.0
        def mongoize(object)
          unless object.blank?
            __numeric__(object).to_f rescue 0.0
          else
            nil
          end
        end
        alias :demongoize :mongoize
      end
    end
  end
end

::Float.__send__(:include, Mongoid::Extensions::Float)
::Float.extend(Mongoid::Extensions::Float::ClassMethods)

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/extensions/float.rb
mongoid-7.3.4 lib/mongoid/extensions/float.rb
mongoid-7.1.11 lib/mongoid/extensions/float.rb
mongoid-7.2.6 lib/mongoid/extensions/float.rb
mongoid-7.3.3 lib/mongoid/extensions/float.rb
mongoid-7.3.2 lib/mongoid/extensions/float.rb
mongoid-7.2.5 lib/mongoid/extensions/float.rb
mongoid-7.1.10 lib/mongoid/extensions/float.rb
mongoid-7.1.9 lib/mongoid/extensions/float.rb
mongoid-7.2.4 lib/mongoid/extensions/float.rb
mongoid-7.3.1 lib/mongoid/extensions/float.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/extensions/float.rb
mongoid-7.3.0 lib/mongoid/extensions/float.rb
mongoid-7.2.3 lib/mongoid/extensions/float.rb
mongoid-7.1.8 lib/mongoid/extensions/float.rb
mongoid-7.2.2 lib/mongoid/extensions/float.rb
mongoid-7.2.1 lib/mongoid/extensions/float.rb
mongoid-7.1.7 lib/mongoid/extensions/float.rb
mongoid-7.2.0 lib/mongoid/extensions/float.rb
mongoid-7.1.6 lib/mongoid/extensions/float.rb