Module: ActiveSupport::Messages::Rotator

Included in:
ActiveSupport::MessageEncryptor, ActiveSupport::MessageVerifier
Defined in:
lib/active_support/messages/rotator.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#fall_back_to(fallback) ⇒ Object



18
19
20
21
# File 'lib/active_support/messages/rotator.rb', line 18

def fall_back_to(fallback)
  @rotations << fallback
  self
end

#initialize(*args, on_rotation: nil, **options) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/active_support/messages/rotator.rb', line 6

def initialize(*args, on_rotation: nil, **options)
  super(*args, **options)
  @args = args
  @options = options
  @rotations = []
  @on_rotation = on_rotation
end

#read_message(message, on_rotation: @on_rotation, **options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_support/messages/rotator.rb', line 23

def read_message(message, on_rotation: @on_rotation, **options)
  if @rotations.empty?
    super(message, **options)
  else
    thrown, error = catch_rotation_error do
      return super(message, **options)
    end

    @rotations.each do |rotation|
      catch_rotation_error do
        value = rotation.read_message(message, **options)
        on_rotation&.call
        return value
      end
    end

    throw thrown, error
  end
end

#rotate(*args, **options) ⇒ Object



14
15
16
# File 'lib/active_support/messages/rotator.rb', line 14

def rotate(*args, **options)
  fall_back_to build_rotation(*args, **options)
end