From 8ee9ace27b79a1e8d82e9e9482966781686d4851 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 23 Jul 2017 12:31:41 +0200 Subject: Let Metadata instance handle purpose coercion. [ Assain Jaleel & Kasper Timm Hansen ] --- activesupport/lib/active_support/messages/metadata.rb | 8 ++++---- 1 file 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? -- cgit v1.2.3