Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/standby/active_record/base.rb

Direct Known Subclasses

Standby::ConnectionHolder

Class Method Summary collapse

Class Method Details

.connectionObject



6
7
8
9
10
11
12
13
# File 'lib/standby/active_record/base.rb', line 6

def connection
  case Thread.current[:_standby]
  when :primary, NilClass
    connection_without_standby
  else
    Standby.connection_holder(Thread.current[:_standby]).connection_without_standby
  end
end

.connection_without_standbyObject



4
# File 'lib/standby/active_record/base.rb', line 4

alias_method :connection_without_standby, :connection

.on_standby(name = :null_state) ⇒ Object

Generate scope at top level e.g. User.on_standby



16
17
18
19
20
21
22
# File 'lib/standby/active_record/base.rb', line 16

def on_standby(name = :null_state)
  # Why where(nil)?
  # http://stackoverflow.com/questions/18198963/with-rails-4-model-scoped-is-deprecated-but-model-all-cant-replace-it
  context = where(nil)
  context.standby_target = name || :null_state
  context
end