aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
diff options
context:
space:
mode:
authorDavid Celis <me@davidcel.is>2014-01-31 17:42:21 -0800
committerDavid Celis <me@davidcel.is>2014-02-01 10:45:51 -0800
commit85d820b1693a52faddf1f838512e132906272e41 (patch)
tree451e75dd1fe30610566906d8e94f64d3e5c6782c /activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
parent9b2a017aa82f95911280ed597e4bf3193c9399e9 (diff)
downloadrails-85d820b1693a52faddf1f838512e132906272e41.tar.gz
rails-85d820b1693a52faddf1f838512e132906272e41.tar.bz2
rails-85d820b1693a52faddf1f838512e132906272e41.zip
Don't require BigDecimal serialization extension
Rails currently provides an extension to BigDecimal that redefines how it is serialized to YAML. However, as noted in #12467, this does not work as expected. When ActiveSupport is required, BigDecimal YAML serialization does not maintain the object type. It instead ends up serializing the number represented by the BigDecimal itself which, when loaded by YAML later, becomes a Float: ```ruby require 'yaml' require 'bigdecimal' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class require 'active_support/all' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class ``` @tenderlove posits that we should deprecate the custom BigDecimal serialization and let Ruby handle it. For the time being, users who require this serialization for backwards compatibility can manually `require 'active_support/core_ext/big_decimal/yaml_conversions'`. This will close #12467 and deprecate the custom BigDecimal#to_yaml. Signed-off-by: David Celis <me@davidcel.is>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/big_decimal/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/big_decimal/conversions.rb8
1 files changed, 0 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
index 39b8cea807..54b49e6d04 100644
--- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
@@ -1,15 +1,7 @@
require 'bigdecimal'
require 'bigdecimal/util'
-require 'yaml'
class BigDecimal
- YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }
-
- def encode_with(coder)
- string = to_s
- coder.represent_scalar(nil, YAML_MAPPING[string] || string)
- end
-
# Backport this method if it doesn't exist
unless method_defined?(:to_d)
def to_d