Sha256: 033a8f887980e12b28fa256b628f90d0c26f3259b33c67831d65cd87dd54990b

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module Mongoid
  module Extensions
    module Integer

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

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

      # Is the object not to be converted to bson on criteria creation?
      #
      # @example Is the object unconvertable?
      #   object.unconvertable_to_bson?
      #
      # @return [ true ] If the object is unconvertable.
      def unconvertable_to_bson?
        true
      end

      module ClassMethods

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongoid-7.5.4 lib/mongoid/extensions/integer.rb
mongoid-7.5.3 lib/mongoid/extensions/integer.rb
mongoid-7.5.2 lib/mongoid/extensions/integer.rb
mongoid-7.5.1 lib/mongoid/extensions/integer.rb
mongoid-7.4.3 lib/mongoid/extensions/integer.rb
mongoid-7.5.0 lib/mongoid/extensions/integer.rb
mongoid-7.4.1 lib/mongoid/extensions/integer.rb
mongoid-7.4.0 lib/mongoid/extensions/integer.rb