类:Mongoid::Criteria::Queryable::Selector
- 定义于:
- lib/mongoid/criteria/queryable/selector.rb
Overview
选择器是一种特殊的哈希,它知道如何序列化进入其中的值,并了解键名称的别名和区域设置。
实例属性摘要
从Smash继承的属性
#aliased_associations 、 #aliased_associations aliased_associations。 、 #aliases 、 #aliases 别名。 、 #associations 、 #associations 关联。 、 #serializers 、 #serializers 序列化器。
实例方法摘要折叠
-
# merge! (其他)→ 选择器
将另一个选择器合并到此选择器中。
-
# 存储 (key, value) ⇒ 对象(也:#[]=)
将该值存储在所提供键的选择器中。
-
#to_pipeline ⇒ Array<Hash>
将选择器转换为聚合管道条目。
从Smash继承的方法
#[] 、 #__deep_copy__ 、 #initialize
构造函数详情
该类从Mongoid::Criteria::Queryable::Smash继承构造函数
实例方法详细信息
# merge! (其他)→选择器
将另一个选择器合并到此选择器中。
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongoid/criteria/queryable/selector.rb', line 20 def 合并!(其他) 其他.each_pair do |key, 值| if 值.is_a?(哈希) && self[key.to_s].is_a?(哈希) 值 = self[key.to_s].合并(merge)(值) do |_key, old_val, new_val| 案例 _key.to_s when ' $in ' new_val 和 old_val when '$nin' (old_val + new_val).uniq else new_val end end end if multi_selection?(key) 值 = (self[key.to_s] || []).concat(值) end 存储(key, 值) end end |
# 存储 (key, value) ⇒ Object也称为: []=
将该值存储在所提供键的选择器中。 选择器将在此步骤中处理所有必要的序列化和本地化。
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mongoid/criteria/queryable/selector.rb', line 51 def 存储(key, 值) 名称, 序列化器 = storage_pair(key) if multi_selection?(名称) store_name = 名称 store_value = evolve_multi(值) else store_name, store_value = store_creds(名称, 序列化器, 值) end 超(store_name, store_value) end |
# to_pipeline ⇒ Array<Hash>
将选择器转换为聚合管道条目。
69 70 71 72 73 |
# File 'lib/mongoid/criteria/queryable/selector.rb', line 69 def to_pipeline 管道 = [] 管道.推动({ " $match " => self }) 除非 空? 管道 end |