模块:Mongoid::Extensions::BigDecimal::ClassMethods
- 定义于:
- lib/mongoid/extensions/big_decimal.rb
实例方法摘要折叠
-
# demogoize (object) ⇒ BigDecimal | nil
将对象从其 mongo 友好的 Ruby 类型转换为此类型。
-
# mongoize (object) ⇒ string | BSON::Decimal128 | BSON::Decimal nil
根据其在数据库中的存储方式,对任意类型的对象进行 Mongoize 操作。
实例方法详细信息
# demogoize (object) ⇒ BigDecimal | nil
将对象从其 mongo 友好的 Ruby 类型转换为此类型。
56 57 58 59 60 61 62 63 |
# File 'lib/mongoid/extensions/big_decimal.rb', line 56 def demogoize(对象) return if 对象.空白? if 对象.is_a?(BSON::Decimal128) 对象.to_big_decimal elsif 对象.numeric? 对象.to_d end end |
# mongoize (object) ⇒ string | BSON::Decimal128 | BSON::Decimal nil
根据其在数据库中的存储方式,对任意类型的对象进行 Mongoize 操作。
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mongoid/extensions/big_decimal.rb', line 75 def mongoize(对象) return if 对象.空白? if Mongoid.map_big_decimal_to_decimal 128 if 对象.is_a?(BSON::Decimal128) 对象 elsif 对象.is_a?(BigDecimal) BSON::Decimal128.new(对象) elsif 对象.numeric? BSON::Decimal128.new(对象.to_s) elsif !对象.is_a?(字符串) 对象.try(:to_d) end else if 对象.is_a?(BSON::Decimal128) || 对象.numeric? 对象.to_s elsif !对象.is_a?(字符串) 对象.try(:to_d)&。to_s end end end |