Class: BaseBranch::Database::ActiveDatabase
- Inherits:
-
Object
- Object
- BaseBranch::Database::ActiveDatabase
- Defined in:
- lib/base_branch/database/active_database.rb
Class Method Summary collapse
- .branch_config ⇒ Object
- .branch_specific_db ⇒ Object
- .branch_specific_db_name ⇒ Object
- .create_branch_db ⇒ Object
- .database_name ⇒ Object
- .default_db_name ⇒ Object
Class Method Details
.branch_config ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/base_branch/database/active_database.rb', line 42 def branch_config @_branch_config ||= begin if File.exists?(File.join(Rails.root, '.base_branch.yml')) YAML::load_file(File.join(Rails.root, '.base_branch.yml')) else { 'branches' => [] } end end end |
.branch_specific_db ⇒ Object
20 21 22 23 |
# File 'lib/base_branch/database/active_database.rb', line 20 def branch_specific_db db_name = branch_specific_db_name branch_db_present?(db_name) ? db_name : nil end |
.branch_specific_db_name ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/base_branch/database/active_database.rb', line 25 def branch_specific_db_name current_branch = BaseBranch::GitBranch.current_branch unless current_branch == 'master' "#{default_db_name}-#{current_branch.gsub('/', '_')}" end end |
.create_branch_db ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/base_branch/database/active_database.rb', line 33 def create_branch_db unless branch_specific_db new_db_name = branch_specific_db_name adapter.clone_db new_db_name, default_db_name, db_user end new_db_name end |
.database_name ⇒ Object
7 8 9 |
# File 'lib/base_branch/database/active_database.rb', line 7 def database_name branch_specific_db || default_db_name end |
.default_db_name ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/base_branch/database/active_database.rb', line 11 def default_db_name @_default_db_name ||= begin YAML::load_file(File.join(Rails.root, 'config', 'base_branch.yml'))['default_db'] rescue Errno::ENOENT => e warn 'Please run `rails g base_branch:install`' nil end end |