Class: DatabaseSwitcher
- Inherits:
-
Object
- Object
- DatabaseSwitcher
- Defined in:
- lib/database-switcher.rb
Instance Attribute Summary collapse
-
#config_file_path ⇒ Object
readonly
Returns the value of attribute config_file_path.
-
#database_name ⇒ Object
readonly
Returns the value of attribute database_name.
Instance Method Summary collapse
-
#initialize(database_name, config_file_path: 'config/database-switcher.yml') ⇒ DatabaseSwitcher
constructor
A new instance of DatabaseSwitcher.
- #perform(&block) ⇒ Object
Constructor Details
#initialize(database_name, config_file_path: 'config/database-switcher.yml') ⇒ DatabaseSwitcher
Returns a new instance of DatabaseSwitcher.
4 5 6 7 8 |
# File 'lib/database-switcher.rb', line 4 def initialize(database_name, config_file_path: 'config/database-switcher.yml') @database_name = database_name @config_file_path = config_file_path @main_db_params = ActiveRecord::Base.configurations[Rails.env] end |
Instance Attribute Details
#config_file_path ⇒ Object (readonly)
Returns the value of attribute config_file_path.
2 3 4 |
# File 'lib/database-switcher.rb', line 2 def config_file_path @config_file_path end |
#database_name ⇒ Object (readonly)
Returns the value of attribute database_name.
2 3 4 |
# File 'lib/database-switcher.rb', line 2 def database_name @database_name end |
Instance Method Details
#perform(&block) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/database-switcher.rb', line 10 def perform(&block) switch_db_connection return_value = block.call restore_main_db_connection return_value end |