Class: ActiveSupport::Messages::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/messages/metadata.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, expires_at = nil, purpose = nil) ⇒ Metadata

Returns a new instance of Metadata.



8
9
10
# File 'lib/active_support/messages/metadata.rb', line 8

def initialize(message, expires_at = nil, purpose = nil)
  @message, @expires_at, @purpose = message, expires_at, purpose
end

Class Method Details

.verify(message, purpose) ⇒ Object



25
26
27
# File 'lib/active_support/messages/metadata.rb', line 25

def verify(message, purpose)
  (message).verify(purpose)
end

.wrap(message, expires_at: nil, expires_in: nil, purpose: nil) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/active_support/messages/metadata.rb', line 17

def wrap(message, expires_at: nil, expires_in: nil, purpose: nil)
  if expires_at || expires_in || purpose
    JSON.encode new(encode(message), pick_expiry(expires_at, expires_in), purpose)
  else
    message
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object



12
13
14
# File 'lib/active_support/messages/metadata.rb', line 12

def as_json(options = {})
  { _rails: { message: @message, exp: @expires_at, pur: @purpose } }
end

#verify(purpose) ⇒ Object



57
58
59
# File 'lib/active_support/messages/metadata.rb', line 57

def verify(purpose)
  @message if match?(purpose) && fresh?
end