Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
show all
- Defined in:
- lib/slavery/active_record/base.rb
Class Method Summary
collapse
Class Method Details
.connection ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/slavery/active_record/base.rb', line 6
def connection
case Thread.current[:slavery]
when :master, NilClass
connection_without_slavery
else
Slavery.connection_holder(Thread.current[:slavery]).connection_without_slavery
end
end
|
.connection_without_slavery ⇒ Object
4
|
# File 'lib/slavery/active_record/base.rb', line 4
alias_method :connection_without_slavery, :connection
|
.on_slave(name = :null_state) ⇒ Object
Generate scope at top level e.g. User.on_slave
16
17
18
19
20
21
22
|
# File 'lib/slavery/active_record/base.rb', line 16
def on_slave(name = :null_state)
context = where(nil)
context.slavery_target = name || :null_state
context
end
|