Class: SandboxManager
- Inherits:
-
Object
- Object
- SandboxManager
- Defined in:
- lib/db_helper/sandbox_manager.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configurations ⇒ Object
-
#initialize(dir) ⇒ SandboxManager
constructor
A new instance of SandboxManager.
- #ports ⇒ Object
Constructor Details
#initialize(dir) ⇒ SandboxManager
Returns a new instance of SandboxManager.
7 8 9 |
# File 'lib/db_helper/sandbox_manager.rb', line 7 def initialize(dir) @dir = dir end |
Class Method Details
.default_sandboxes_base_dir ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/db_helper/sandbox_manager.rb', line 12 def self.default_sandboxes_base_dir configuration = Rails.configuration.database_configuration[Rails.env] suffixes = Rails.configuration.database_configuration.keys current_db = configuration['database'] while suffix = suffixes.pop current_db = current_db.gsub("_#{suffix}",'') end sandbox_proc = Sys::ProcTable.ps.find { |p| p.comm == 'mysqld' && p.cwd.to_s.include?(current_db) } if sandbox_proc sandbox_proc.cwd.gsub(File.join('', current_db, 'data'), '') else File.join('', 'db') end end |
Instance Method Details
#configurations ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/db_helper/sandbox_manager.rb', line 31 def configurations Dir[File.join(@dir,'**','my.sandbox.cnf')].map.with_object({}) do |config_file, hash| config = ParseConfig.new(config_file) sandbox_name = Pathname.new(config_file).split.first.split.last.to_s hash[sandbox_name] = config end end |
#ports ⇒ Object
40 41 42 |
# File 'lib/db_helper/sandbox_manager.rb', line 40 def ports configurations.map.with_object({}) { |(sandbox, conf), hash| hash[sandbox] = conf['client']['port']} end |