模块:Mongoid::Criteria::Translator Private

扩展方式:
转换器
包含在:
转换器
定义于:
lib/mongoid/criteria/translator.rb

Overview

该模块是私有 API 的一部分。 您应尽可能避免使用此模块,因为它将来可能会被删除或更改。

这是一个辅助模块,用于将原子和复合Ruby值转换为相应的查询和选项组件。 这种方法最初是作为核心类的补丁实现的,但现在普遍不受欢迎,因为它过多地占用了公共命名空间。

实例方法摘要折叠

实例方法详细信息

# to_direction (value) ⇒哈希 |数值

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

将给定值转换为用于排序的方向规范。

例子:

将值转换为方向。

Translator.to_direction(:desc)
Translator.to_direction("1")
Translator.to_direction(-1)
Translator.to_direction(score: { "$meta": "textScore" })

参数:

  • (哈希 | 数字 | string | 符号)

    要转换的值。

返回:

  • (哈希 | 数值)

    方向。



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

def to_direction()
  案例 
  when 哈希 then
    
  when 数值 then
    
  when 字符串 then
     =~ /desc/i ? -1 : 1
  when 符号 then
    to_direction(.to_s)
  else
    提高 ArgumentError, “ 无法将 #{ value .inspect } ( #{ value . class } } ) 转换为方向规范
  end
end