模块:Mongoid::Criteria::Marshalable

包含在:
Mongoid::Criteria
定义于:
lib/mongoid/criteria/marshalable.rb

Overview

Mongoid::Criteria 的 Mixin 模块,其中添加了自定义 Marshal.dump 功能。

实例方法摘要折叠

实例方法详细信息

# marshal_dumpArray<Object>

提供 Marshal.dump 条件所需的数据。

注意:此处编写Mongo是为了向后兼容 Mongoid 7及更早版本。

例子:

转储条件。

Marshal.dump(criteria)

返回:

  • ( Array<Object> )

    已转储的数据。



20
21
22
23
# File 'lib/mongoid/criteria/marshalable.rb', line 20

def marshal_dump
  数据 = [ klass, :mongo, 包含, 文档, 策略, 否定 ]
  数据.推动(scoped_options).推动(dump_hash(:selector)).推动(dump_hash(:options))
end

# marshal_load (data) ⇒对象

在执行完 Marshal.load 之后重置条件对象

例子:

加载条件。

Marshal.load(criteria)

参数:

  • 数据 ( Array )

    原始数据。



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mongoid/criteria/marshalable.rb', line 31

def marshal_load(数据)
  @scoping_options, raw_selector, raw_options = 数据.Pop(3)
  @klass, 驱动, @inclusions, @documents, @strategy, @negating = 数据

  if 驱动 == : Mongo1 x
    提高 NotImplementedError, " Mongoid 不再支持使用驾驶员版本1 .x 进行编组。 "
  end

  @selector = load_hash(可查询::选择器, raw_selector)
  @options = load_hash(可查询::选项, raw_options)
end