Class: ActiveSupport::Messages::RotationCoordinator
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activesupport/lib/active_support/messages/rotation_coordinator.rb |
Class Method Summary
- .new(&secret_generator) ⇒ RotationCoordinator constructor
Instance Attribute Summary
Instance Method Summary
Constructor Details
.new(&secret_generator) ⇒ RotationCoordinator
# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 10
def initialize(&secret_generator) raise ArgumentError, "A secret generator block is required" unless secret_generator @secret_generator = secret_generator @rotate_options = [] @on_rotation = nil @codecs = {} end
Instance Attribute Details
#transitional (rw)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 8
attr_accessor :transitional
Instance Method Details
#[](salt)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 18
def [](salt) @codecs[salt] ||= build_with_rotations(salt) end
#[]=(salt, codec)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 22
def []=(salt, codec) @codecs[salt] = codec end
#build(salt, secret_generator:, secret_generator_options:, **options) (private)
# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 88
def build(salt, secret_generator:, secret_generator_options:, ** ) raise NotImplementedError end
#build_with_rotations(salt) (private)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 76
def build_with_rotations(salt) = @rotate_options.map { || .is_a?(Proc) ? .(salt) : } transitional = self.transitional && .first .compact! [0..1] = [0..1].reverse if transitional = .map { || ( ) }.uniq raise "No options have been configured for #{salt}" if .empty? .map { || build(salt.to_s, ** ) }.reduce(&:fall_back_to) end
#changing_configuration! (private)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 51
def changing_configuration! if @codecs.any? raise <<~MESSAGE Cannot change #{self.class} configuration after it has already been applied. The configuration has been applied with the following salts: #{@codecs.keys.map { |salt| "- #{salt.inspect}" }.join("\n")} MESSAGE end end
#clear_rotations
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 39
def clear_rotations changing_configuration! @rotate_options.clear self end
#normalize_options(options) (private)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 62
def ( ) = .dup [:secret_generator] ||= @secret_generator secret_generator_kwargs = [:secret_generator].parameters. filter_map { |type, name| name if type == :key || type == :keyreq } [: ] = .extract!(*secret_generator_kwargs) [:on_rotation] = @on_rotation end
#on_rotation(&callback)
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 45
def on_rotation(&callback) changing_configuration! @on_rotation = callback end
#rotate(**options, &block)
# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 26
def rotate(**, &block) raise ArgumentError, "Options cannot be specified when using a block" if block && ! .empty? changing_configuration! @rotate_options << (block || ) self end
#rotate_defaults
[ GitHub ]# File 'activesupport/lib/active_support/messages/rotation_coordinator.rb', line 35
def rotate_defaults rotate() end