Sha256: d074aa8917c98a01655d821792bc488d8a27b1e7444e30da966f078469bb3541

Contents?: true

Size: 1.14 KB

Versions: 12

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

# A class which sends values to the database as Strings but returns them to the user as Symbols.
module Mongoid
  class StringifiedSymbol
    class << self
      # Convert the object from its mongo friendly ruby type to this type.
      #
      # @example Demongoize the object.
      #   Symbol.demongoize(object)
      #
      # @param [ Object ] object The object to demongoize.
      #
      # @return [ Symbol ] The object.
      #
      # @api private
      def demongoize(object)
        if object.nil?
          object
        else
          object.to_s.to_sym
        end
      end

      # Turn the object from the ruby type we deal with to a Mongo friendly
      # type.
      #
      # @example Mongoize the object.
      #   Symbol.mongoize("123.11")
      #
      # @param [ Object ] object The object to mongoize.
      #
      # @return [ Symbol ] The object mongoized.
      #
      # @api private
      def mongoize(object)
        if object.nil?
          object
        else
          object.to_s
        end
      end

      # @api private
      def evolve(object)
        mongoize(object)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rocketjob-6.3.1 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.3.0 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.2.0 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.1.1 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.1.0 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.3 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.2 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.1 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.0 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.0.rc3 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.0.rc2 lib/rocket_job/extensions/mongoid/stringified_symbol.rb
rocketjob-6.0.0.rc1 lib/rocket_job/extensions/mongoid/stringified_symbol.rb