database_exporter 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require 'bundler'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "database_exporter"
8
- s.version = '0.0.5'
8
+ s.version = '0.0.6'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Mike Pack"]
11
11
  s.email = ["mikepackdev@gmail.com"]
@@ -5,21 +5,21 @@ class MysqlAdapter
5
5
 
6
6
  def export
7
7
  ensure_db_exists
8
- Kernel.` "mysqldump -h #{@config['host']} -u #{@config['username']} #{'-p' + @config['password'] if @config['password']} #{@config['database']}"
8
+ Kernel.` "mysqldump -h #{@config[:host]} -u #{@config[:username]} #{'-p' + @config[:password] if @config[:password]} #{@config[:database]}"
9
9
  end
10
10
 
11
11
  def import(sql)
12
12
  ensure_db_exists
13
- Kernel.` "echo \"#{sql}\" | mysql -h #{@config['host']} -u #{@config['username']} #{'-p' + @config['password'] if @config['password']} #{@config['database']}"
13
+ Kernel.` "echo \"#{sql}\" | mysql -h #{@config[:host]} -u #{@config[:username]} #{'-p' + @config[:password] if @config[:password]} #{@config[:database]}"
14
14
  end
15
15
 
16
16
  def copy(new_db_config)
17
17
  ensure_db_exists
18
- ensure_db_exists(new_db_config['database'])
19
- Kernel.` "mysqldump -h #{@config['host']} -u #{@config['username']} #{'-p' + @config['password'] if @config['password']} #{@config['database']} | mysql -h #{new_db_config['host']} -u #{new_db_config['username']} #{'-p' + new_db_config['password'] if new_db_config['password']} #{new_db_config['database']}"
18
+ ensure_db_exists(new_db_config[:database])
19
+ Kernel.` "mysqldump -h #{@config[:host]} -u #{@config[:username]} #{'-p' + @config[:password] if @config[:password]} #{@config[:database]} | mysql -h #{new_db_config[:host]} -u #{new_db_config[:username]} #{'-p' + new_db_config[:password] if new_db_config[:password]} #{new_db_config[:database]}"
20
20
  end
21
21
 
22
- def ensure_db_exists(name = @config['database'])
23
- `echo "CREATE DATABASE IF NOT EXISTS #{name}" | mysql -h #{@config['host']} -u #{@config['username']} #{'-p' + @config['password'] if @config['password']}`
22
+ def ensure_db_exists(name = @config[:database])
23
+ `echo "CREATE DATABASE IF NOT EXISTS #{name}" | mysql -h #{@config[:host]} -u #{@config[:username]} #{'-p' + @config[:password] if @config[:password]}`
24
24
  end
25
25
  end
@@ -5,7 +5,7 @@ class DatabaseExporter
5
5
  extend Forwardable
6
6
 
7
7
  def initialize(config)
8
- @adapter = case config['adapter']
8
+ @adapter = case config[:adapter]
9
9
  when /mysql/
10
10
  MysqlAdapter.new(config)
11
11
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe MysqlAdapter do
4
4
  context 'with a MySQL database' do
5
- let(:adapter) { MysqlAdapter.new({"database"=>"some_mysql_db", "host"=>"localhost", "username"=>"root", "password"=>nil}) }
5
+ let(:adapter) { MysqlAdapter.new({:database => "some_mysql_db", :host => "localhost", :username => "root", :password => nil}) }
6
6
 
7
7
  describe '#export' do
8
8
  it 'ensures the database exists' do
@@ -52,16 +52,16 @@ describe MysqlAdapter do
52
52
  describe '#copy' do
53
53
  it 'executes the mysqldump and pipes to the mysql command' do
54
54
  Kernel.should_receive(:`).with(/mysqldump.*\|\s+mysql/)
55
- adapter.copy({"database"=>"new_mysql_db", "host"=>"localhost", "username"=>"root", "password"=>nil})
55
+ adapter.copy({:database=>"new_mysql_db", :host=>"localhost", :username=>"root", :password=>nil})
56
56
  end
57
57
 
58
58
  it 'copies one database to another' do
59
59
  # Create a new table to check that it was duplicated to the new database
60
60
  adapter.import('CREATE TABLE some_new_database_table ( id INT );')
61
- adapter.copy({"database"=>"new_mysql_db", "host"=>"localhost", "username"=>"root", "password"=>nil})
61
+ adapter.copy({:database=>"new_mysql_db", :host=>"localhost", :username=>"root", :password=>nil})
62
62
 
63
63
  # Load the new database and check that the table exists
64
- new_adapter = MysqlAdapter.new({"database"=>"new_mysql_db", "host"=>"localhost", "username"=>"root", "password"=>nil})
64
+ new_adapter = MysqlAdapter.new({:database=>"new_mysql_db", :host=>"localhost", :username=>"root", :password=>nil})
65
65
  new_adapter.export.should =~ /some_new_database_table/
66
66
 
67
67
  `echo "DROP DATABASE some_mysql_db" | mysql -u root`
@@ -3,14 +3,14 @@ require 'spec_helper'
3
3
  describe DatabaseExporter do
4
4
  describe '#initialize' do
5
5
  it 'initializes the MysqlAdapter when passed a MySQL config' do
6
- MysqlAdapter.should_receive(:new).with({'adapter' => 'mysql2'})
7
- DatabaseExporter.new({'adapter' => 'mysql2'})
6
+ MysqlAdapter.should_receive(:new).with({:adapter => 'mysql2'})
7
+ DatabaseExporter.new({:adapter => 'mysql2'})
8
8
  end
9
9
  end
10
10
 
11
11
  describe '#export, #import, #copy' do
12
12
  it 'all exist (and are delegated to the adapter)' do
13
- exporter = DatabaseExporter.new({'adapter' => 'mysql2'})
13
+ exporter = DatabaseExporter.new({:adapter => 'mysql2'})
14
14
  [:export, :import, :copy, :ensure_db_exists].each do |method|
15
15
  exporter.respond_to?(method).should be_true
16
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: