diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-23 12:31:41 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-23 12:31:41 +0200 |
commit | 8ee9ace27b79a1e8d82e9e9482966781686d4851 (patch) | |
tree | f007c1f4ab5be0aa91e71e8563550efe2cd9fe48 | |
parent | 9fbfb4bffe72320cc895e2f4eb4e30e108d58bb2 (diff) | |
download | rails-8ee9ace27b79a1e8d82e9e9482966781686d4851.tar.gz rails-8ee9ace27b79a1e8d82e9e9482966781686d4851.tar.bz2 rails-8ee9ace27b79a1e8d82e9e9482966781686d4851.zip |
Let Metadata instance handle purpose coercion.
[ Assain Jaleel & Kasper Timm Hansen ]
-rw-r--r-- | activesupport/lib/active_support/messages/metadata.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/messages/metadata.rb b/activesupport/lib/active_support/messages/metadata.rb index 54678b9552..db14ac0b1c 100644 --- a/activesupport/lib/active_support/messages/metadata.rb +++ b/activesupport/lib/active_support/messages/metadata.rb @@ -5,13 +5,13 @@ module ActiveSupport module Messages #:nodoc: class Metadata #:nodoc: def initialize(expires_at, purpose) - @expires_at, @purpose = expires_at, purpose + @expires_at, @purpose = expires_at, purpose.to_s end class << self def wrap(message, expires_at: nil, expires_in: nil, purpose: nil) if expires_at || expires_in || purpose - { "value" => message, "_rails" => { "exp" => pick_expiry(expires_at, expires_in), "pur" => purpose.to_s } } + { "value" => message, "_rails" => { "exp" => pick_expiry(expires_at, expires_in), "pur" => purpose } } else message end @@ -22,7 +22,7 @@ module ActiveSupport if metadata.nil? message if purpose.nil? - elsif metadata.match?(purpose.to_s) && metadata.fresh? + elsif metadata.match?(purpose) && metadata.fresh? message["value"] end end @@ -44,7 +44,7 @@ module ActiveSupport end def match?(purpose) - @purpose == purpose + @purpose == purpose.to_s end def fresh? |