module Mongoid::Criteria::Marshalable

Public Instance Methods

marshal_dump() click to toggle source

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

# File lib/mongoid/criteria/marshalable.rb, line 16
def marshal_dump
  data = [ klass, driver, inclusions, documents, strategy, negating ]
  data.push(scoping_options).push(dump_hash(:selector)).push(dump_hash(:options))
end
marshal_load(data) click to toggle source

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

# File lib/mongoid/criteria/marshalable.rb, line 29
def marshal_load(data)
  @scoping_options, raw_selector, raw_options = data.pop(3)
  @klass, @driver, @inclusions, @documents, @strategy, @negating = data
  @selector = load_hash(Queryable::Selector, raw_selector)
  @options = load_hash(Queryable::Options, raw_options)
end

Private Instance Methods

dump_hash(name) click to toggle source
# File lib/mongoid/criteria/marshalable.rb, line 38
def dump_hash(name)
  send(name).inject({}) do |raw, (key, value)|
    raw[key] = value
    raw
  end
end
load_hash(hash_class, raw) click to toggle source
# File lib/mongoid/criteria/marshalable.rb, line 45
def load_hash(hash_class, raw)
  hash = hash_class.new(klass.aliased_fields, klass.fields)
  hash.merge!(raw)
  hash
end