Class: ActiveSupport::Messages::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/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
11
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/messages/metadata.rb', line 8

def initialize(message, expires_at = nil, purpose = nil)
  @message, @purpose = message, purpose
  @expires_at = expires_at.is_a?(String) ? parse_expires_at(expires_at) : expires_at
end

Class Method Details

.verify(message, purpose) ⇒ Object



26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/messages/metadata.rb', line 26

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

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



18
19
20
21
22
23
24
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/messages/metadata.rb', line 18

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



13
14
15
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/messages/metadata.rb', line 13

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

#verify(purpose) ⇒ Object



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/messages/metadata.rb', line 58

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