class ActiveSupport::Messages::Metadata
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/active_support/messages/metadata.rbs class ActiveSupport::Messages::Metadata def verify: (String message, String purpose) -> untyped def verify: (String message, String purpose) -> untyped end
:nodoc:
:nodoc:
def as_json(options = {})
def as_json(options = {}) { _rails: { message: @message, exp: @expires_at, pur: @purpose } } end
def decode(message)
def decode(message) ::Base64.strict_decode64(message) end
def encode(message)
def encode(message) ::Base64.strict_encode64(message) end
def extract_metadata(message)
def extract_metadata(message) data = JSON.decode(message) rescue nil if data.is_a?(Hash) && data.key?("_rails") new(decode(data["_rails"]["message"]), data["_rails"]["exp"], data["_rails"]["pur"]) else new(message) end end
def fresh?
def fresh? @expires_at.nil? || Time.now.utc < @expires_at end
def initialize(message, expires_at = nil, purpose = nil)
:nodoc:
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
def match?(purpose)
def match?(purpose) @purpose.to_s == purpose.to_s end
def parse_expires_at(expires_at)
def parse_expires_at(expires_at) if ActiveSupport.use_standard_json_time_format Time.iso8601(expires_at) else Time.parse(expires_at) end end
def pick_expiry(expires_at, expires_in)
def pick_expiry(expires_at, expires_in) if expires_at expires_at.utc.iso8601(3) elsif expires_in Time.now.utc.advance(seconds: expires_in).iso8601(3) end end
def verify(message, purpose)
Experimental RBS support (using type sampling data from the type_fusion
project).
def verify: (String message, String purpose) -> untyped
This signature was generated using 1 sample from 1 application.
def verify(message, purpose) extract_metadata(message).verify(purpose) end
def verify(purpose)
Experimental RBS support (using type sampling data from the type_fusion
project).
def verify: (String message, String purpose) -> untyped
This signature was generated using 1 sample from 1 application.
def verify(purpose) @message if match?(purpose) && fresh? end
def wrap(message, expires_at: nil, expires_in: nil, purpose: nil)
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