File tree Expand file tree Collapse file tree 5 files changed +33
-28
lines changed
lib/active_support/core_ext/big_decimal Expand file tree Collapse file tree 5 files changed +33
-28
lines changed Original file line number Diff line number Diff line change
1
+ * Deprecate custom ` BigDecimal ` serialization
2
+
3
+ Deprecate the custom ` BigDecimal ` serialization that is included when requiring
4
+ ` active_support/all ` as a fix for #12467 . Let Ruby handle YAML serialization
5
+ for ` BigDecimal ` instead.
6
+
7
+ * David Celis*
8
+
1
9
* Fix parsing bugs in ` XmlMini `
2
10
3
- Symbols or boolean parsing would raise an error for non string values (e.g.
11
+ Symbols or boolean parsing would raise an error for non string values (e.g.
4
12
integers). Decimal parsing would fail due to a missing requirement.
5
13
6
14
* Birkir A. Barkarson*
Original file line number Diff line number Diff line change 1
1
require 'bigdecimal'
2
2
require 'bigdecimal/util'
3
- require 'yaml'
4
3
5
4
class BigDecimal
6
- YAML_MAPPING = { 'Infinity' => '.Inf' , '-Infinity' => '-.Inf' , 'NaN' => '.NaN' }
7
-
8
- def encode_with ( coder )
9
- string = to_s
10
- coder . represent_scalar ( nil , YAML_MAPPING [ string ] || string )
11
- end
12
-
13
- # Backport this method if it doesn't exist
14
- unless method_defined? ( :to_d )
15
- def to_d
16
- self
17
- end
18
- end
19
-
20
5
DEFAULT_STRING_FORMAT = 'F'
21
6
def to_formatted_s ( *args )
22
7
if args [ 0 ] . is_a? ( Symbol )
Original file line number Diff line number Diff line change
1
+ ActiveSupport ::Deprecation . warn 'core_ext/big_decimal/yaml_conversions is deprecated and will be removed in the future.'
2
+
3
+ require 'bigdecimal'
4
+ require 'yaml'
5
+
6
+ class BigDecimal
7
+ YAML_MAPPING = { 'Infinity' => '.Inf' , '-Infinity' => '-.Inf' , 'NaN' => '.NaN' }
8
+
9
+ def encode_with ( coder )
10
+ string = to_s
11
+ coder . represent_scalar ( nil , YAML_MAPPING [ string ] || string )
12
+ end
13
+ end
Original file line number Diff line number Diff line change
1
+ require 'abstract_unit'
2
+ require 'active_support/core_ext/big_decimal/yaml_conversions'
3
+
4
+ class BigDecimalYamlConversionsTest < ActiveSupport ::TestCase
5
+ def test_to_yaml
6
+ assert_match ( "--- 100000.30020320320000000000000000000000000000001\n " , BigDecimal . new ( '100000.30020320320000000000000000000000000000001' ) . to_yaml )
7
+ assert_match ( "--- .Inf\n " , BigDecimal . new ( 'Infinity' ) . to_yaml )
8
+ assert_match ( "--- .NaN\n " , BigDecimal . new ( 'NaN' ) . to_yaml )
9
+ assert_match ( "--- -.Inf\n " , BigDecimal . new ( '-Infinity' ) . to_yaml )
10
+ end
11
+ end
Original file line number Diff line number Diff line change 2
2
require 'active_support/core_ext/big_decimal'
3
3
4
4
class BigDecimalTest < ActiveSupport ::TestCase
5
- def test_to_yaml
6
- assert_match ( "--- 100000.30020320320000000000000000000000000000001\n " , BigDecimal . new ( '100000.30020320320000000000000000000000000000001' ) . to_yaml )
7
- assert_match ( "--- .Inf\n " , BigDecimal . new ( 'Infinity' ) . to_yaml )
8
- assert_match ( "--- .NaN\n " , BigDecimal . new ( 'NaN' ) . to_yaml )
9
- assert_match ( "--- -.Inf\n " , BigDecimal . new ( '-Infinity' ) . to_yaml )
10
- end
11
-
12
- def test_to_d
13
- bd = BigDecimal . new '10'
14
- assert_equal bd , bd . to_d
15
- end
16
-
17
5
def test_to_s
18
6
bd = BigDecimal . new '0.01'
19
7
assert_equal '0.01' , bd . to_s
You can’t perform that action at this time.
0 commit comments