Class: ActiveSupport::MessagesMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/active_storage/messages_metadata.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MessagesMetadata.



2
3
4
# File 'lib/active_storage/messages_metadata.rb', line 2

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

Class Method Details

.verify(message, purpose) ⇒ Object



19
20
21
# File 'lib/active_storage/messages_metadata.rb', line 19

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

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



11
12
13
14
15
16
17
# File 'lib/active_storage/messages_metadata.rb', line 11

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

Instance Method Details

#as_json(options = {}) ⇒ Object



6
7
8
# File 'lib/active_storage/messages_metadata.rb', line 6

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

#verify(purpose) ⇒ Object



51
52
53
# File 'lib/active_storage/messages_metadata.rb', line 51

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