class BaseBranch::Database::ActiveDatabase
Public Class Methods
branch_config()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/base_branch/database/active_database.rb, line 7 def database_name branch_specific_db || default_db_name end
default_db_name()
click to toggle source
# 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
Private Class Methods
adapter()
click to toggle source
# File lib/base_branch/database/active_database.rb, line 64 def adapter "BaseBranch::Database::Adapter::#{rails_db_config['development']['adapter'].classify}" .constantize end
branch_db_present?(db_name)
click to toggle source
# File lib/base_branch/database/active_database.rb, line 54 def branch_db_present?(db_name) return nil unless db_name branch_config['branches'].include?(db_name) end
current()
click to toggle source
# File lib/base_branch/database/active_database.rb, line 60 def current rails_db_config['development']['database'] end
db_user()
click to toggle source
# File lib/base_branch/database/active_database.rb, line 69 def db_user rails_db_config['development']['username'] end
rails_db_config()
click to toggle source
# File lib/base_branch/database/active_database.rb, line 73 def rails_db_config Rails.configuration.database_configuration end