Module: Stagehand::Database
- Extended by:
- Database
- Included in:
- Database
- Defined in:
- lib/stagehand/database.rb
Defined Under Namespace
Classes: ProductionProbe, StagingProbe
Constant Summary
collapse
- @@connection_name_stack =
[Rails.env.to_sym]
Instance Method Summary
collapse
Instance Method Details
#connected_to_production? ⇒ Boolean
7
8
9
|
# File 'lib/stagehand/database.rb', line 7
def connected_to_production?
current_connection_name == Configuration.production_connection_name
end
|
#connected_to_staging? ⇒ Boolean
11
12
13
|
# File 'lib/stagehand/database.rb', line 11
def connected_to_staging?
current_connection_name == Configuration.staging_connection_name
end
|
#production_connection ⇒ Object
19
20
21
|
# File 'lib/stagehand/database.rb', line 19
def production_connection
ProductionProbe.connection
end
|
#set_connection_for_model(model, connection_name) ⇒ Object
37
38
39
|
# File 'lib/stagehand/database.rb', line 37
def set_connection_for_model(model, connection_name)
connect_to(connection_name, model) unless Configuration.ghost_mode?
end
|
#staging_connection ⇒ Object
15
16
17
|
# File 'lib/stagehand/database.rb', line 15
def staging_connection
StagingProbe.connection
end
|
#with_connection(connection_name) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/stagehand/database.rb', line 23
def with_connection(connection_name)
different = !Configuration.ghost_mode? && current_connection_name != connection_name.to_sym
@@connection_name_stack.push(connection_name.to_sym)
Rails.logger.debug "Connecting to #{current_connection_name}"
connect_to(current_connection_name) if different
yield
ensure
@@connection_name_stack.pop
Rails.logger.debug "Restoring connection to #{current_connection_name}"
connect_to(current_connection_name) if different
end
|