Module: Switchman::StandardError

Defined in:
lib/switchman/standard_error.rb

Instance Method Summary collapse

Instance Method Details

#current_shard(klass = ::ActiveRecord::Base) ⇒ Object



22
23
24
# File 'lib/switchman/standard_error.rb', line 22

def current_shard(klass = ::ActiveRecord::Base)
  @active_shards&.[](klass) || Shard.default
end

#initialize(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/switchman/standard_error.rb', line 5

def initialize(*args)
  # Shard.current can throw this when switchman isn't working right; if we try to
  # do our stuff here, it'll cause a SystemStackError, which is a pain to deal with
  if is_a?(::ActiveRecord::ConnectionNotEstablished)
    super
    return
  end

  begin
    @active_shards = Shard.active_shards if defined?(Shard)
  rescue ::ActiveRecord::ConnectionNotEstablished
    # If we hit an error really early in boot, activerecord may not be initialized yet
  end

  super
end