123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Messages::Codec

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Metadata
Inherits: Object
Defined in: activesupport/lib/active_support/messages/codec.rb

Constant Summary

Metadata - Included

ENVELOPE_SERIALIZERS, TIMESTAMP_SERIALIZERS

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(**options) ⇒ Codec

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 15

def initialize(**options)
  @serializer = options[:serializer] || self.class.default_serializer
  @serializer = SerializerWithFallback[@serializer] if @serializer.is_a?(Symbol)
  @url_safe = options[:url_safe]
  @force_legacy_metadata_serializer = options[:]
end

Class Attribute Details

.default_serializer (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 12

class_attribute :default_serializer, default: :marshal,
  instance_accessor: false, instance_predicate: false

Instance Attribute Details

#serializer (readonly, private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 23

attr_reader :serializer

#use_message_serializer_for_metadata?Boolean (readonly, private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 60

def use_message_serializer_for_metadata?
  !@force_legacy_metadata_serializer && super
end

Instance Method Details

#catch_and_ignore(throwable, &block) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 45

def catch_and_ignore(throwable, &block)
  catch throwable do
    return block.call
  end
  nil
end

#catch_and_raise(throwable, as: nil, &block) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 52

def catch_and_raise(throwable, as: nil, &block)
  error = catch throwable do
    return block.call
  end
  error = as.new(error.to_s) if as
  raise error
end

#decode(encoded, url_safe: @url_safe) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 29

def decode(encoded, url_safe: @url_safe)
  url_safe ? ::Base64.urlsafe_decode64(encoded) : ::Base64.strict_decode64(encoded)
rescue ArgumentError => error
  throw :invalid_message_format, error
end

#deserialize(serialized) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 39

def deserialize(serialized)
  serializer.load(serialized)
rescue StandardError => error
  throw :invalid_message_serialization, error
end

#encode(data, url_safe: @url_safe) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 25

def encode(data, url_safe: @url_safe)
  url_safe ? ::Base64.urlsafe_encode64(data, padding: false) : ::Base64.strict_encode64(data)
end

#serialize(data) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/messages/codec.rb', line 35

def serialize(data)
  serializer.dump(data)
end