Class: ActiveSupport::Messages::Metadata
- Defined in:
- lib/active_support/messages/metadata.rb
Overview
:nodoc:
Class Method Summary collapse
- .verify(message, purpose) ⇒ Object
- .wrap(message, expires_at: nil, expires_in: nil, purpose: nil) ⇒ Object
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(message, expires_at = nil, purpose = nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #verify(purpose) ⇒ Object
Constructor Details
#initialize(message, expires_at = nil, purpose = nil) ⇒ Metadata
Returns a new instance of Metadata.
8 9 10 11 |
# File 'lib/active_support/messages/metadata.rb', line 8 def initialize(, expires_at = nil, purpose = nil) @message, @purpose = , purpose @expires_at = expires_at.is_a?(String) ? Time.iso8601(expires_at) : expires_at end |
Class Method Details
.verify(message, purpose) ⇒ Object
26 27 28 |
# File 'lib/active_support/messages/metadata.rb', line 26 def verify(, purpose) ().verify(purpose) end |
.wrap(message, expires_at: nil, expires_in: nil, purpose: nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/active_support/messages/metadata.rb', line 18 def wrap(, expires_at: nil, expires_in: nil, purpose: nil) if expires_at || expires_in || purpose JSON.encode new(encode(), pick_expiry(expires_at, expires_in), purpose) else end end |
Instance Method Details
#as_json(options = {}) ⇒ Object
13 14 15 |
# File 'lib/active_support/messages/metadata.rb', line 13 def as_json( = {}) { _rails: { message: @message, exp: @expires_at, pur: @purpose } } end |
#verify(purpose) ⇒ Object
58 59 60 |
# File 'lib/active_support/messages/metadata.rb', line 58 def verify(purpose) @message if match?(purpose) && fresh? end |