aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorJonathan del Strother <jdelStrother@gmail.com>2018-02-07 13:06:11 +0000
committerJonathan del Strother <jdelStrother@gmail.com>2018-02-07 13:19:08 +0000
commita467c6bdd5722c09f5a15c0a7c5c40cc99c8be25 (patch)
tree6898ee3324b1ed2cd658c44d14649abc237de952 /activesupport/lib/active_support
parent2c0300389c3f6be00bf6c6b806332808a9400429 (diff)
downloadrails-a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25.tar.gz
rails-a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25.tar.bz2
rails-a467c6bdd5722c09f5a15c0a7c5c40cc99c8be25.zip
Fix yaml deserialization of ActiveSupport::Duration
This ensures the duration's @parts hash has a default value, to avoid this regression introduced in 5.1: YAML.load(YAML.dump(10.minutes)) + 1 # => NoMethodError: undefined method `+' for nil:NilClass
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/duration.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index 39deb2313f..19b2d84fc8 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -334,6 +334,14 @@ module ActiveSupport
to_i
end
+ def init_with(coder) #:nodoc:
+ initialize(coder["value"], coder["parts"])
+ end
+
+ def encode_with(coder) #:nodoc:
+ coder.map = { "value" => @value, "parts" => @parts }
+ end
+
# Build ISO 8601 Duration string for this duration.
# The +precision+ parameter can be used to limit seconds' precision of duration.
def iso8601(precision: nil)