模块:Mongoid::Extensions::Array

定义于:
lib/mongoid/extensions/ 大量.rb

Overview

为 Array 类添加类型转换行为。

在命名空间下定义

模块: 类方法

实例方法摘要折叠

实例方法详细信息

# __evolve_object_id__ "> Array <BSON::ObjectId>

将数组演进为对象 ID 数组。

例子:

将数组演进为对象 ID。

[ id ].__evolve_object_id__

返回:

  • ( Array <BSON::ObjectId> )

    转换后的数组。



15
16
17
18
# File 'lib/mongoid/extensions/ 大量.rb', line 15

def __evolve_object_id__
  地图!(:__evolve_object_id__)
  self
end

# __find_args__数组

已弃用。

获取 args 数组作为查找查询的参数。

例子:

获取数组作为查找参数。

[ 1, 2, 3 ].__find_args__

返回:

  • ( Array )

    args 数组。



27
28
29
# File 'lib/mongoid/extensions/ 大量.rb', line 27

def __find_args__
  flat_map{ |a| a.__find_args__ }.uniq{ |a| a.to_s }
end

# __mongoize_object_id__ "> Array <BSON::ObjectId>

将数组 Mongoize 为对象 ID 数组。

例子:

将数组演进为对象 ID。

[ id ].__mongoize_object_id__

返回:

  • ( Array <BSON::ObjectId> )

    转换后的数组。



38
39
40
41
# File 'lib/mongoid/extensions/ 大量.rb', line 38

def __mongoize_object_id__
  地图!(:__mongoize_object_id__).紧凑!
  self
end

# __mongoize_time__时间| ActiveSupport::TimeWithZone

注意:

返回默认时区的本地时间。

将数组转换为时间进行存储。

例子:

将数组转换为时间。

[ 2010, 1, 1 ].__mongoize_time__
# => 2010-01-01 00:00:00 -0500

返回:

  • ( Time | ActiveSupport::TimeWithZone )

    与此数组中的日期/时间组件相对应的已配置默认时区中的本地时间。



54
55
56
# File 'lib/mongoid/extensions/ 大量.rb', line 54

def __mongoize_time__
  ::时间.区域.local(*self)
end

# delete_one (object) ⇒对象

删除数组中与所提供对象相等的第一个对象并将其返回。 这比对大型数组执行标准删除要快得多,因为它不执行多次删除。

例子:

删除第一个对象。

[ "1", "2", "1" ].delete_one("1")

参数:

  • 对象 ( Object )

    要删除的对象。

返回:

  • ( Object )

    已删除的对象。



91
92
93
94
# File 'lib/mongoid/extensions/ 大量.rb', line 91

def delete_one(对象)
  Position = 索引(index)(对象)
  Position ? delete_at(Position) : nil
end

# mongoize数组| nil

将对象从我们处理的Ruby类型转换为mongo友好类型。

例子:

将对象 Mongoize。

object.mongoize

返回:

  • ( Array | nil )

    对象或 nil。



77
78
79
# File 'lib/mongoid/extensions/ 大量.rb', line 77

def mongoize
  ::阵列.mongoize(self)
end

# multi_arged?true | false

已弃用。

数组是方法中包含多个参数的集合吗?

例子:

这是 multi args 吗?

[ 1, 2, 3 ].multi_arged?

返回:

  • ( true | false )

    如果数组为多参数。



65
66
67
# File 'lib/mongoid/extensions/ 大量.rb', line 65

def multi_arged?
  !first.is_a?(哈希) && first.可调整大小? || size > 1
end

#可调整大小?true

返回对象大小是否可以更改的信息。

例子:

对象的大小是否可调整?

object.resizable?

返回:

  • ( true )

    true。



102
103
104
# File 'lib/mongoid/extensions/ 大量.rb', line 102

def 可调整大小?
  true
end