Sha256: d8ecc8de1a3a878fbc83d9cbb60c8169a2673eb3aa5b93f616906e4dfc4efdf8

Contents?: true

Size: 1.31 KB

Versions: 35

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
module Mongoid
  class Criteria
    module Marshalable

      # Provides the data needed to Marshal.dump a criteria.
      #
      # @example Dump the criteria.
      #   Marshal.dump(criteria)
      #
      # @return [ Array<Object> ] The dumped data.
      #
      # @since 3.0.15
      def marshal_dump
        data = [ klass, driver, inclusions, documents, strategy, negating ]
        data.push(scoping_options).push(dump_hash(:selector)).push(dump_hash(:options))
      end

      # Resets the criteria object after a Marshal.load
      #
      # @example Load the criteria.
      #   Marshal.load(criteria)
      #
      # @param [ Array ] data The raw data.
      #
      # @since 3.0.15
      def marshal_load(data)
        @scoping_options, raw_selector, raw_options = data.pop(3)
        @klass, @driver, @inclusions, @documents, @strategy, @negating = data
        @selector = load_hash(Origin::Selector, raw_selector)
        @options = load_hash(Origin::Options, raw_options)
      end

      private

      def dump_hash(name)
        send(name).inject({}) do |raw, (key, value)|
          raw[key] = value
          raw
        end
      end

      def load_hash(hash_class, raw)
        hash = hash_class.new(klass.aliased_fields, klass.fields)
        hash.merge!(raw)
        hash
      end
    end
  end
end

Version data entries

35 entries across 32 versions & 6 rubygems

Version Path
mongoid-5.4.1 lib/mongoid/criteria/marshalable.rb
mongoid-5.4.0 lib/mongoid/criteria/marshalable.rb
mongoid-5.2.1 lib/mongoid/criteria/marshalable.rb
mongoid-5.2.0 lib/mongoid/criteria/marshalable.rb
mongoid-5.2.0.rc0 lib/mongoid/criteria/marshalable.rb
mongoid-5.1.6 lib/mongoid/criteria/marshalable.rb
mongoid-5.1.5 lib/mongoid/criteria/marshalable.rb
mongoid-5.1.4 lib/mongoid/criteria/marshalable.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/criteria/marshalable.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-5.1.3/lib/mongoid/criteria/marshalable.rb
mongoid-5.1.3 lib/mongoid/criteria/marshalable.rb
mongoid-5.1.2 lib/mongoid/criteria/marshalable.rb
mongoid-5.1.1 lib/mongoid/criteria/marshalable.rb
mongoid-5.1.0 lib/mongoid/criteria/marshalable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mongoid-5.0.2/lib/mongoid/criteria/marshalable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mongoid-5.0.2/lib/mongoid/criteria/marshalable.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mongoid-5.0.1/lib/mongoid/criteria/marshalable.rb
mongoid-5.0.2 lib/mongoid/criteria/marshalable.rb
mongoid-5.0.1 lib/mongoid/criteria/marshalable.rb
mongoid-5.0.0 lib/mongoid/criteria/marshalable.rb