mongodb_clone 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d94a9f5b128193dcc417dc3ee167d9221fa8ddd1
4
- data.tar.gz: c7ece0b3dea24494786aea4d640298d961728258
3
+ metadata.gz: 51ae29dd49d07ae0d1205b4950bca9555bd7f875
4
+ data.tar.gz: 9aa9407029c673763bea5729a067f24c27b3516e
5
5
  SHA512:
6
- metadata.gz: 4ccbd7dd149e66ee306422a1258c3451d34b99e21177bdb9db1eafc1e1057641536377735efb1e27dae23e7edeea807c3dbfeb0e35fd8a8de620e62c4a4a6793
7
- data.tar.gz: 07f6bc13c4db366267871db140a8c161dad018bd123abef2fd476da94823412f1cf68d5107f00cc3ab77bcbc6dda9a447eb9bd2c2e003b51785df4d93774b874
6
+ metadata.gz: 77a1faab44783fcb5b67be51c6d0d03f20953b914555532b8ecc74968d6792616275370b04f98cc04db2cfc5ffe390e9c8f1653c33e49ee964ef58ae707dec7d
7
+ data.tar.gz: 092e76b892e28000175a01aa96dc9cc0b77feccd7a3219c8c86250291f6ed2994ab777deef79d0999ad672f2f4d8ac5d237c7612f48462706e538dd4901ba0cb
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+
7
+ gemfile:
8
+ - Gemfile
9
+ - gemfiles/rails-3.2.gemfile
10
+ - gemfiles/rails-master.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.2.0 - December 25, 2013
2
+
3
+ ### Improvements
4
+
5
+ * Add support to Rails 4
6
+ * Use the gem `railties` instead of `rails`
7
+
1
8
  ## 0.1.1 - July 26, 2013
2
9
 
3
10
  ### Bug fixes
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # MongodbClone
1
+ # MongodbClone [![Build Status](https://travis-ci.org/tiagogodinho/mongodb_clone.png?branch=master)](https://travis-ci.org/tiagogodinho/mongodb_clone) [![Dependency Status](https://gemnasium.com/tiagogodinho/mongodb_clone.png)](https://gemnasium.com/tiagogodinho/mongodb_clone) [![Gem Version](https://badge.fury.io/rb/mongodb_clone.png)](http://badge.fury.io/rb/mongodb_clone)
2
+
3
+ [![Code Climate](https://codeclimate.com/github/tiagogodinho/mongodb_clone.png)](https://codeclimate.com/github/tiagogodinho/mongodb_clone) [![Coverage Status](https://coveralls.io/repos/tiagogodinho/mongodb_clone/badge.png)](https://coveralls.io/r/tiagogodinho/mongodb_clone)
2
4
 
3
5
  Dump and restore databases easily.
4
6
 
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '~> 3.2.0'
4
+
5
+ gemspec path: '../'
6
+
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', github: 'rails/rails'
4
+
5
+ gemspec path: '../'
data/lib/mongodb_clone.rb CHANGED
@@ -1,63 +1,7 @@
1
1
  require 'rails'
2
+ require 'mongodb_clone/mongodb_replication'
2
3
  require 'mongodb_clone/engine'
3
4
  require 'mongodb_clone/version'
4
5
 
5
6
  module MongodbClone
6
- class MongodbReplication
7
- attr_accessor :id, :path
8
-
9
- def initialize
10
- @id = Time.now.utc.strftime('%Y%m%d%H%M%S')
11
- end
12
-
13
- def dump(environment = 'production', session = 'default')
14
- config = base_config[environment.to_s]['sessions'][session.to_s]
15
-
16
- params = {
17
- h: config['hosts'][0],
18
- d: config['database'],
19
- u: config['username'],
20
- p: config['password'],
21
- o: "/tmp/#{ config['database'] }/#{ @id }"
22
- }
23
-
24
- a = params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ')
25
-
26
- command = "mongodump #{ a }"
27
-
28
- execute(command)
29
-
30
- @path = "#{ params[:o] }/#{ params[:d] }"
31
-
32
- self
33
- end
34
-
35
- def restore(environment = 'development', session = 'default')
36
- config = base_config[environment.to_s]['sessions'][session.to_s]
37
-
38
- params = {
39
- h: config['hosts'][0],
40
- d: config['database'],
41
- u: config['username'],
42
- p: config['password']
43
- }
44
-
45
- a = params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ')
46
-
47
- command = "mongorestore --drop #{ a } #{ @path }"
48
-
49
- execute(command)
50
- end
51
-
52
- private
53
-
54
- def base_config
55
- YAML.load_file(Rails.root.join('config/mongoid.yml'))
56
- end
57
-
58
- def execute(command)
59
- puts command
60
- `#{ command }`
61
- end
62
- end
63
7
  end
@@ -0,0 +1,65 @@
1
+ require 'yaml'
2
+
3
+ module MongodbClone
4
+ class MongodbReplication
5
+ attr_accessor :id, :path
6
+
7
+ def initialize
8
+ @id = Time.now.utc.strftime('%Y%m%d%H%M%S')
9
+ end
10
+
11
+ def dump(environment = 'production', session = 'default')
12
+ config = get_config(environment, session)
13
+
14
+ params = default_params(config).merge({ o: "/tmp/#{ config['database'] }/#{ @id }" })
15
+
16
+ a = hash_to_inline_params(params)
17
+
18
+ command = "mongodump #{ a }"
19
+
20
+ execute(command)
21
+
22
+ @path = "#{ params[:o] }/#{ params[:d] }"
23
+
24
+ self
25
+ end
26
+
27
+ def restore(environment = 'development', session = 'default')
28
+ config = get_config(environment, session)
29
+
30
+ a = hash_to_inline_params(default_params(config))
31
+
32
+ command = "mongorestore --drop #{ a } #{ @path }"
33
+
34
+ execute(command)
35
+ end
36
+
37
+ private
38
+
39
+ def default_params(config)
40
+ {
41
+ h: config['hosts'][0],
42
+ d: config['database'],
43
+ u: config['username'],
44
+ p: config['password']
45
+ }
46
+ end
47
+
48
+ def get_config(environment, session)
49
+ base_config[environment.to_s]['sessions'][session.to_s]
50
+ end
51
+
52
+ def hash_to_inline_params(params)
53
+ params.collect { |key, value| "-#{ key } \"#{ value.to_s.gsub("\"", "\\\"") }\"" if value }.compact.join(' ')
54
+ end
55
+
56
+ def base_config
57
+ YAML.load_file(Rails.root.join('config/mongoid.yml'))
58
+ end
59
+
60
+ def execute(command)
61
+ puts command
62
+ `#{ command }`
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module MongodbClone
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -12,9 +12,10 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = %q{Write a gem summary}
13
13
  gem.homepage = ''
14
14
 
15
- gem.add_dependency 'rails', '~> 3.2.0'
15
+ gem.add_dependency 'railties', '>= 3.2.0'
16
16
 
17
- gem.add_development_dependency 'rspec', '~> 2.11.0'
17
+ gem.add_development_dependency 'coveralls', '~> 0.7'
18
+ gem.add_development_dependency 'rspec', '~> 2.14.0'
18
19
 
19
20
  gem.files = `git ls-files`.split($/)
20
21
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -2,10 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe MongodbClone::MongodbReplication do
4
4
  before do
5
- Rails.stub_chain(:root, :join).and_return(File.join(File.dirname(__FILE__), 'support', 'mongoid.yml'))
5
+ file = File.join(File.dirname(__FILE__), '../', 'support', 'mongoid.yml')
6
+ Rails.stub_chain(:root, :join).and_return(file)
6
7
  end
7
8
 
9
+ subject { MongodbClone::MongodbReplication.new.as_null_object }
10
+
8
11
  describe '#dump' do
12
+ it 'returns the object to create a chain of methods' do
13
+ subject.stub(:execute)
14
+ expect(subject.dump).to be_an_instance_of(described_class)
15
+ end
16
+
9
17
  it 'should dump database' do
10
18
  subject.id = '201210231843100200'
11
19
  subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')
@@ -27,10 +35,9 @@ describe MongodbClone::MongodbReplication do
27
35
  it 'should restore database' do
28
36
  subject.id = '201210231843100200'
29
37
  subject.path = '/tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production'
30
- subject.should_receive(:execute).with('mongodump -h "mongodb_clone.example.com:27017" -d "mongodb_clone_production" -u "mongodb_clone" -p "12345678" -o "/tmp/mongodb_clone_production/201210231843100200"')
31
38
  subject.should_receive(:execute).with('mongorestore --drop -h "localhost:27017" -d "mongodb_clone_development" /tmp/mongodb_clone_production/201210231843100200/mongodb_clone_production')
32
39
 
33
- subject.dump.restore
40
+ subject.restore
34
41
  end
35
42
  end
36
43
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'mongodb_clone'
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb_clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Rafael Godinho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2013-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: 2.11.0
47
+ version: 2.14.0
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: 2.11.0
54
+ version: 2.14.0
41
55
  description: Write a gem description
42
56
  email:
43
57
  - tiagogodinho3@gmail.com
@@ -47,17 +61,21 @@ extra_rdoc_files: []
47
61
  files:
48
62
  - .gitignore
49
63
  - .rspec
64
+ - .travis.yml
50
65
  - CHANGELOG.md
51
66
  - Gemfile
52
67
  - LICENSE.txt
53
68
  - README.md
54
69
  - Rakefile
70
+ - gemfiles/rails-3.2.gemfile
71
+ - gemfiles/rails-master.gemfile
55
72
  - lib/mongodb_clone.rb
56
73
  - lib/mongodb_clone/engine.rb
74
+ - lib/mongodb_clone/mongodb_replication.rb
57
75
  - lib/mongodb_clone/version.rb
58
76
  - lib/tasks/mongodb_clone.rake
59
77
  - mongodb_clone.gemspec
60
- - spec/mongodb_clone_spec.rb
78
+ - spec/mongodb_clone/mongodb_replication_spec.rb
61
79
  - spec/spec_helper.rb
62
80
  - spec/support/mongoid.yml
63
81
  homepage: ''
@@ -79,11 +97,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
97
  version: '0'
80
98
  requirements: []
81
99
  rubyforge_project:
82
- rubygems_version: 2.0.3
100
+ rubygems_version: 2.1.10
83
101
  signing_key:
84
102
  specification_version: 4
85
103
  summary: Write a gem summary
86
104
  test_files:
87
- - spec/mongodb_clone_spec.rb
105
+ - spec/mongodb_clone/mongodb_replication_spec.rb
88
106
  - spec/spec_helper.rb
89
107
  - spec/support/mongoid.yml