Module: MysqlTruck::Helper
Instance Method Summary collapse
- #base_path ⇒ Object
- #benchmark ⇒ Object
- #bucket_dir ⇒ Object
- #config ⇒ Object
- #csv_options ⇒ Object
- #db_connection_options ⇒ Object
- #formatted_time(time) ⇒ Object
- #initialize_directories ⇒ Object
- #initialize_s3 ⇒ Object
- #local_host? ⇒ Boolean
- #remote_host? ⇒ Boolean
- #remove_directories ⇒ Object
- #s3_path ⇒ Object
- #tmp_path ⇒ Object
Instance Method Details
#base_path ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/mysql_truck/helper.rb', line 54 def base_path if config[:dump_dir] config[:dump_dir].is_a?(Pathname) ? config[:dump_dir].join("mysqltruck") : Pathname.new(config[:dump_dir]).join("mysqltruck") else Pathname.new("/tmp/mysqltruck") end end |
#benchmark ⇒ Object
66 67 68 69 70 71 |
# File 'lib/mysql_truck/helper.rb', line 66 def benchmark time = Benchmark.realtime do yield end puts "Ran in #{formatted_time(time)}." end |
#bucket_dir ⇒ Object
62 63 64 |
# File 'lib/mysql_truck/helper.rb', line 62 def bucket_dir "mysql/#{config[:bucket_dir] || config[:database]}/" end |
#config ⇒ Object
6 7 8 |
# File 'lib/mysql_truck/helper.rb', line 6 def config @config end |
#csv_options ⇒ Object
77 78 79 |
# File 'lib/mysql_truck/helper.rb', line 77 def " --fields-enclosed-by=\\\" --fields-terminated-by=, " end |
#db_connection_options ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/mysql_truck/helper.rb', line 17 def opts = %Q[ -u #{config[:username]} ] opts += %Q[ -p"#{config[:password]}" ] unless config[:password].nil? opts += %Q[ -h #{config[:host]} --default-character-set=utf8 ] opts += %Q[ -P #{config[:port]} ] if config[:port] opts += %Q[ #{config[:database]} ] opts end |
#formatted_time(time) ⇒ Object
73 74 75 |
# File 'lib/mysql_truck/helper.rb', line 73 def formatted_time(time) "#{"%0.5f" % time}s" end |
#initialize_directories ⇒ Object
34 35 36 37 38 |
# File 'lib/mysql_truck/helper.rb', line 34 def initialize_directories mkdir_p base_path mkdir_p tmp_path chmod 0777, tmp_path end |
#initialize_s3 ⇒ Object
10 11 12 13 14 15 |
# File 'lib/mysql_truck/helper.rb', line 10 def initialize_s3 @s3 = RightAws::S3.new( config[:s3_access_key], config[:s3_secret_access_key]) @bucket = @s3.bucket(config[:bucket]) end |
#local_host? ⇒ Boolean
26 27 28 |
# File 'lib/mysql_truck/helper.rb', line 26 def local_host? config[:host] == '127.0.0.1' || config[:host] == 'localhost' end |
#remote_host? ⇒ Boolean
30 31 32 |
# File 'lib/mysql_truck/helper.rb', line 30 def remote_host? !local_host? end |
#remove_directories ⇒ Object
40 41 42 |
# File 'lib/mysql_truck/helper.rb', line 40 def remove_directories rm_r tmp_path, :force => true end |
#s3_path ⇒ Object
49 50 51 52 |
# File 'lib/mysql_truck/helper.rb', line 49 def s3_path raise "@time not initialized" unless @time "#{bucket_dir}#{@time.strftime("%Y-%m-%d")}" end |
#tmp_path ⇒ Object
44 45 46 47 |
# File 'lib/mysql_truck/helper.rb', line 44 def tmp_path raise "@time not initialized" unless @time base_path.join(@time.strftime("%Y-%m-%d")) end |