class Mysqlknife::Configs
Attributes
color[R]
commands[R]
connection[W]
connections[R]
host[R]
mysql[R]
name[R]
ssh[R]
Public Class Methods
new()
click to toggle source
# File lib/mysqlknife/configs.rb, line 16 def initialize # Define path for config file: if ENV['ENV'] == 'test' path = File.expand_path(File.join(Dir.pwd, '.db.yml')) else path = File.expand_path("#{Dir.home}/.db.yml") end # Load config file: @configs = YAML.load_file(path) if File.exist?(path) if @configs.nil? puts "Not exist config file in #{path}" exit 1 end # Define generic variables: @ssh = {} @mysql = {} @ssh[:host] = @configs['ssh']['host'] @ssh[:port] = @configs['ssh']['port'] @ssh[:user] = @configs['ssh']['user'] @ssh[:password] = @configs['ssh']['password'] @ssh[:key] = @configs['ssh']['keys'] @connections = @configs['connections'].keys.sort @commands = @configs['commands'].keys.sort end
Public Instance Methods
command(name)
click to toggle source
# File lib/mysqlknife/configs.rb, line 84 def command(name) if @configs['commands'].key?(name) @configs['commands'][name] end end
connection(name)
click to toggle source
# File lib/mysqlknife/configs.rb, line 57 def connection(name) @name = name @color = db_color(@name) @ssh[:use] = db_ssh(@name) @mysql[:host] = db_host(@name) @mysql[:port] = db_port(@name) @mysql[:username] = db_username(@name) @mysql[:password] = db_password(@name) @mysql[:slaves] = db_slaves(@name) end
hosts()
click to toggle source
# File lib/mysqlknife/configs.rb, line 68 def hosts (@mysql[:slaves] = []) if @mysql[:slaves].nil? (@mysql[:host] = '') if @mysql[:host].nil? (@mysql[:host] + ',' + @mysql[:slaves].join(',')).split(',') end
method_missing(name, *args)
click to toggle source
# File lib/mysqlknife/configs.rb, line 45 def method_missing(name, *args) method = name.to_s.split(/_/) if method.first == 'db' param = method[1] conn = args[0] if @configs['connections'].include?(conn) @configs['connections'][conn][param] end end end
select(name)
click to toggle source
# File lib/mysqlknife/configs.rb, line 75 def select(name) if hosts.is_a?(Array) hosts.each do |host| return @host = host if host.include?(name) end end nil end