Sha256: a2b5507b5bd3fcc7d553edbe351d2c13dba071d1e30f65ae8618080e0a520573

Contents?: true

Size: 1.52 KB

Versions: 60

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Fields #:nodoc:
    module Internal #:nodoc:

      # Defines the behaviour for big decimal fields.
      class BigDecimal
        include Serializable

        # Deserialize this field from the type stored in MongoDB to the type
        # defined on the model.
        #
        # @example Deserialize the field.
        #   field.deserialize(object)
        #
        # @param [ Object ] object The object to cast.
        #
        # @return [ BigDecimal ] The converted big decimal.
        #
        # @since 2.1.0
        def deserialize(object)
          object ? ::BigDecimal.new(object) : object
        end

        # Special case to serialize the object.
        #
        # @example Convert to a selection.
        #   field.selection(object)
        #
        # @param [ Object ] The object to convert.
        #
        # @return [ Object ] The converted object.
        #
        # @since 2.4.0
        def selection(object)
          return object if object.is_a?(::Hash)
          serialize(object)
        end

        # Serialize the object from the type defined in the model to a MongoDB
        # compatible object to store.
        #
        # @example Serialize the field.
        #   field.serialize(object)
        #
        # @param [ Object ] object The object to cast.
        #
        # @return [ String ] The converted string.
        #
        # @since 2.1.0
        def serialize(object)
          object ? object.to_s : object
        end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 3 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/big_decimal.rb