lib/fulmar/infrastructure/service/database/database_service.rb in fulmar-0.6.4 vs lib/fulmar/infrastructure/service/database/database_service.rb in fulmar-0.6.5

- old
+ new

@@ -22,20 +22,20 @@ } def initialize(config) @config = config @config.merge DEFAULT_CONFIG - @shell = Fulmar::Infrastructure::Service::ShellService.new(config[:local_path], config[:hostname]) @tunnel = nil @client = nil + initialize_shell config_test end def connect options = compile_options - if @config[:maria][:hostname] != 'localhost' && @config[:maria][:hostname] != '127.0.0.1' + unless local? tunnel.open options[:port] = tunnel.local_port end # Wait max 3 seconds for the tunnel to establish @@ -60,10 +60,14 @@ def connected? @connected end + def local? + @config[:maria][:hostname] == 'localhost' || @config[:maria][:hostname] == '127.0.0.1' + end + def tunnel @tunnel ||= Fulmar::Infrastructure::Service::TunnelService.new(@config[:maria][:hostname], @config[:maria][:port]) end # shortcut for DatabaseService.client.query @@ -124,9 +128,15 @@ # NOTE: The file might already exist, for example if this is run at the same # time from to different clients. I won't handle this as it is unlikely and # would result in more I/O def backup_filename "#{@config[:maria][:database]}_#{Time.now.strftime('%Y-%m-%dT%H%M%S')}.sql" + end + + def initialize_shell + path = local? ? @config[:local_path] : @config[:remote_path] + @shell = Fulmar::Infrastructure::Service::ShellService.new(path, @config[:hostname]) + @shell.debug = true if @config[:debug] end # Compiles a mysql config hash from valid options of the fulmar config def compile_options possible_options = [:host, :username, :password, :port, :encoding, :socket, :read_timeout, :write_timeout,