模块:Mongoid::Extensions::String
- 定义于:
- lib/mongoid/extensions/string.rb
Overview
为string类添加类型转换行为。
在命名空间下定义
模块: 类方法
实例属性摘要折叠
实例方法摘要折叠
-
# __evolve_object_id__ ⇒ string | BSON::ObjectId
如果可能,将string转换为对象ID 。
-
# __mongoize_object_id__ ⇒ string | BSON::ObjectId | nil
如果可能,将string Mongoize 为对象ID 。
-
# __mongoize_time__ ⇒ 时间 | ActiveSupport::TimeWithZone
将string Mongoize 进行存储。
-
# before_type_cast? ⇒ true | false
string是否以 _before_type_cast 结尾?
-
# collectionize ⇒ string
将该string转换为集合友好名称。
- # mongoid_id? ⇒ true | false 已弃用 已弃用。
-
# numeric? ⇒ true | false
Is the string a number?字面量“NaN”、“Infinity”和“-Infinity”都计为数字。
-
# Reader ⇒ string
将string作为 getter string获取。
- # unconvertable_to_bson? ⇒ true | false 已弃用 已弃用。
-
# valid_method_name? ⇒ true | false
此string是 valid_method_name 吗?
-
# writer? ⇒ true | false
此string是作者吗?
实例属性详细信息
# unconvertable_to_bson ⇒对象
已弃用。
9 10 11 |
# File 'lib/mongoid/extensions/string.rb', line 9 def unconvertable_to_bson @unconvertable_to_bson end |
# unconvertable_to_bson 如果文档不可转换。 (如果文档不可转换。) ⇒对象
已弃用。
9 |
# File 'lib/mongoid/extensions/string.rb', line 9 attr_accessor :unconvertable_to_bson |
实例方法详细信息
# __evolve_object_id__ ⇒ string | BSON::ObjectId
如果可能,将string转换为对象ID 。
19 20 21 |
# File 'lib/mongoid/extensions/string.rb', line 19 def __evolve_object_id__ convert_to_object_id end |
# __mongoize_object_id__ ⇒ string | BSON::ObjectId | nil
如果可能,将string Mongoize 为对象ID 。
29 30 31 |
# File 'lib/mongoid/extensions/string.rb', line 29 def __mongoize_object_id__ convert_to_object_id 除非 空白? end |
# __mongoize_time__ ⇒时间| ActiveSupport::TimeWithZone
注意:
返回默认时区的本地时间。
将string Mongoize 进行存储。
45 46 47 48 49 50 51 52 |
# File 'lib/mongoid/extensions/string.rb', line 45 def __mongoize_time__ # 需要这个额外的Time.parse 来引发错误,如果string # 不是有效的时间string 。 ActiveSupport::TimeZone 不 # 执行此检查。 ::时间.parse(self) ::时间.区域.parse(self) end |
# before_type_cast? ⇒ true | false
string是否以 _before_type_cast 结尾?
125 126 127 |
# File 'lib/mongoid/extensions/string.rb', line 125 def before_type_cast? Ends_with?(' _before_type_cast ') end |
# collectionize ⇒ string
将该string转换为集合友好名称。
60 61 62 |
# File 'lib/mongoid/extensions/string.rb', line 60 def 集合化 tableize.tr(' / ', ' _ ') end |
# mongoid_id? ⇒ true | false
已弃用。
该string是 Mongoid ID的有效值吗?
71 72 73 |
# File 'lib/mongoid/extensions/string.rb', line 71 def mongoid_id? self =~ /\A(|_)id\z/ end |
# numeric? ⇒ true | false
Is the string a number?字面量“NaN”、“Infinity”和“-Infinity”都计为数字。
83 84 85 86 87 |
# File 'lib/mongoid/extensions/string.rb', line 83 def numeric? !!Float(self) 救援 ArgumentError (self =~ / \A(?:NaN|-?Infinity)\z /) == 0 end |
# Reader ⇒ string
将string作为 getter string获取。
95 96 97 |
# File 'lib/mongoid/extensions/string.rb', line 95 def Reader 删除(' = ').子(/_before_type_cast\z/, ' ') end |
# unconvertable_to_bson? ⇒ true | false
已弃用。
在创建条件时,对象是否不会转换为BSON ?
136 137 138 |
# File 'lib/mongoid/extensions/string.rb', line 136 def unconvertable_to_bson? @unconvertable_to_bson ||= false end |
# valid_method_name? ⇒ true | false
此string是 valid_method_name 吗?
115 116 117 |
# File 'lib/mongoid/extensions/string.rb', line 115 def valid_method_name? / [@$"-] / !~ self end |
# writer? ⇒ true | false
此string是作者吗?
105 106 107 |
# File 'lib/mongoid/extensions/string.rb', line 105 def writer? 包括?(' = ') end |