mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/psych/lib/psych/visitors/to_ruby.rb: BigDecimals can be restored
from YAML. * ext/psych/lib/psych/visitors/yaml_tree.rb: BigDecimals can be dumped to YAML. * test/psych/test_numeric.rb: tests for BigDecimal serialization git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7cabeff61a
commit
cf2bbc89d2
4 changed files with 26 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Sun Dec 18 12:42:48 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* ext/psych/lib/psych/visitors/to_ruby.rb: BigDecimals can be restored
|
||||||
|
from YAML.
|
||||||
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: BigDecimals can be dumped
|
||||||
|
to YAML.
|
||||||
|
* test/psych/test_numeric.rb: tests for BigDecimal serialization
|
||||||
|
|
||||||
Sun Dec 18 12:03:13 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
Sun Dec 18 12:03:13 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates
|
* ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates
|
||||||
|
|
|
@ -52,6 +52,9 @@ module Psych
|
||||||
o.value.unpack('m').first
|
o.value.unpack('m').first
|
||||||
when '!str', 'tag:yaml.org,2002:str'
|
when '!str', 'tag:yaml.org,2002:str'
|
||||||
o.value
|
o.value
|
||||||
|
when '!ruby/object:BigDecimal'
|
||||||
|
require 'bigdecimal'
|
||||||
|
BigDecimal._load o.value
|
||||||
when "!ruby/object:DateTime"
|
when "!ruby/object:DateTime"
|
||||||
require 'date'
|
require 'date'
|
||||||
@ss.parse_time(o.value).to_datetime
|
@ss.parse_time(o.value).to_datetime
|
||||||
|
|
|
@ -214,6 +214,10 @@ module Psych
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def visit_BigDecimal o
|
||||||
|
@emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY
|
||||||
|
end
|
||||||
|
|
||||||
def binary? string
|
def binary? string
|
||||||
string.encoding == Encoding::ASCII_8BIT ||
|
string.encoding == Encoding::ASCII_8BIT ||
|
||||||
string.index("\x00") ||
|
string.index("\x00") ||
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require 'psych/helper'
|
require 'psych/helper'
|
||||||
|
require 'bigdecimal'
|
||||||
|
|
||||||
module Psych
|
module Psych
|
||||||
###
|
###
|
||||||
|
@ -10,5 +11,15 @@ module Psych
|
||||||
str = Psych.load('--- 090')
|
str = Psych.load('--- 090')
|
||||||
assert_equal '090', str
|
assert_equal '090', str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_big_decimal_tag
|
||||||
|
decimal = BigDecimal("12.34")
|
||||||
|
assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_big_decimal_round_trip
|
||||||
|
decimal = BigDecimal("12.34")
|
||||||
|
assert_cycle decimal
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue