Sha256: 5db6adbe49b5052aec1d233d9b75e5af6e376e386d64337a4df8fba8a6477ace

Contents?: true

Size: 1.45 KB

Versions: 163

Compression:

Stored size: 1.45 KB

Contents

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

      # Defines the behaviour for set fields.
      class Set
        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 [ Set ] The converted set.
        #
        # @since 2.1.0
        def deserialize(object)
          ::Set.new(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 unless object.is_a?(::Set)
          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 [ Array ] The converted array.
        #
        # @since 2.1.0
        def serialize(object)
          object.to_a
        end
      end
    end
  end
end

Version data entries

163 entries across 71 versions & 3 rubygems

Version Path
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
classiccms-0.5.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/fields/internal/set.rb
classiccms-0.5.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/set.rb
classiccms-0.5.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
mongoid-2.4.12 lib/mongoid/fields/internal/set.rb
classiccms-0.4.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/fields/internal/set.rb
classiccms-0.4.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
classiccms-0.4.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/set.rb
classiccms-0.4.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
classiccms-0.4.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/set.rb
classiccms-0.4.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/fields/internal/set.rb
classiccms-0.4.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
classiccms-0.4.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/set.rb
classiccms-0.4.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/fields/internal/set.rb
classiccms-0.3.9 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
classiccms-0.3.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/set.rb
classiccms-0.3.9 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/fields/internal/set.rb
classiccms-0.3.8 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/fields/internal/set.rb
classiccms-0.3.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/fields/internal/set.rb
classiccms-0.3.8 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/fields/internal/set.rb