mongo-db-utils 0.0.9.2 → 0.0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60f9d5dc43d84806e0284ab99d3018d0f7a6013f
4
- data.tar.gz: 41d85fc792b941ebe3ff901a2add2f09643bfbbc
3
+ metadata.gz: bc200a0f72f693a50a790204198e16914ddf20de
4
+ data.tar.gz: 31ff2d8deacdb9cf0030e6a7b585f161e122d7b1
5
5
  SHA512:
6
- metadata.gz: dac4c457c4f95c22b32f5122b91c4f920f11f72687bc41c8702f3e1a96e107a64e82cc6dca0ffaea88b4d7a3a3b6d7c133290c7484dacf86dfb0dcc55ec4dc78
7
- data.tar.gz: ebad5fca30541d643d4ddfcfc2311ddc300dcefe215cfc0e28ec7d77c50628b98fb79707aa54ecb18799e87af2b6f15044db04fe712a82271b725cb0cb5ecd99
6
+ metadata.gz: 6fd93c8cd9e389d2e7be88a2fb5af007f2560a8fa74b0f2007c02b1679961db1e2316af8cbf7094d03a6db7a2258e161a994c3b9f9f19455d138c5df28230bfd
7
+ data.tar.gz: f8a8de001e8969aa30ba61ed75463bcac5b1e533090519e73e0ea2976dfe0ec8ea57397ec1b362082e8ab4fafff144993041e911229f8b19de7400580605c958
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # MongoDbUtils
2
2
 
3
+ [![Build Status](https://travis-ci.org/edeustace/mongo-db-utils.png)](https://travis-ci.org/edeustace/mongo-db-utils)
4
+
5
+
3
6
  ### !Current version 0.0.9.2 is in Beta - for a safer version use 0.0.9
4
7
 
5
8
  A little gem that simplifies backing up and copying your mongo dbs.
@@ -27,7 +30,7 @@ And then execute:
27
30
 
28
31
  ## Limitatons
29
32
 
30
- Only works on ruby 1.9.3 (to_yaml is throwing an error in earlier versions)
33
+ ruby >= 1.9.3
31
34
 
32
35
  ## Usage
33
36
  Once you launch the console it'll provide you with a set of options - pretty self explanatory.
@@ -43,7 +46,7 @@ When it does backups it stores them in ````~/.mongo-db-utils/backups/````. The n
43
46
  ## Building source
44
47
 
45
48
  #run console
46
- bundle exec bin/mongo-db-utils console path_to/config.yml (optional)
49
+ bundle exec bin/mongo-db-utils console path_to/config.yml (optional - it defaults to ~/.mongo-db-utils/config.yml)
47
50
 
48
51
  #install the gem locally
49
52
  rake build
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -8,9 +8,7 @@ This is only really useful if you are working on the source code. If you're just
8
8
  ### Standalone DB
9
9
 
10
10
  * init the environment `create_two_standalone_dbs` - this creates 2 mongod instances on 27018/27019
11
- * To run the console go:
12
-
13
- bundle exec bin/mongo-db-utils console integration-test-env/standalone/config.yml
11
+ * To run the console go: `bundle exec bin/mongo-db-utils console integration-test-env/standalone/config.yml`
14
12
 
15
13
  * kill the environment `kill_processes standalone/.processes`
16
14
 
@@ -20,10 +18,8 @@ This is only really useful if you are working on the source code. If you're just
20
18
  * `create_two_replica_sets`
21
19
  * `replica_sets/rs_config` - you'll probably have to run this a few times
22
20
  * `seed_replica_sets`
23
- * run the console:
24
-
25
- bundle exec bin/mongo-db-utils console integration-test-env/replica_sets/config.yml
21
+ * run the console: `bundle exec bin/mongo-db-utils console integration-test-env/replica_sets/config.yml`
26
22
 
27
23
  * kill the environment `kill_processes replica_sets/.processes`
28
24
 
29
- ....
25
+
@@ -1,6 +1,6 @@
1
- project_root = File.dirname(File.absolute_path(__FILE__))
2
-
3
- Dir.glob(project_root + '/lib/mongo-db-utils/models/*', &method(:require))
1
+ require 'mongo-db-utils/models/bucket'
2
+ require 'mongo-db-utils/models/config'
3
+ require 'mongo-db-utils/models/db'
4
4
 
5
5
  require 'yaml'
6
6
 
@@ -174,7 +174,7 @@ eos
174
174
  def add_single_db
175
175
  mongo_uri = ask("Mongo uri (eg: 'mongodb://user:pass@locahost:27017/db')")
176
176
  new_uri = mongo_uri.to_s.strip
177
- successful = @config.add_db_from_uri(new_uri)
177
+ successful = @config.add_single_db(new_uri)
178
178
 
179
179
  say("bad uri!") unless successful
180
180
 
@@ -35,7 +35,7 @@ module MongoDbUtils
35
35
  end
36
36
 
37
37
 
38
- def add_db_from_uri(uri)
38
+ def add_single_db(uri)
39
39
  add_db Db.new(uri)
40
40
  end
41
41
 
@@ -57,23 +57,20 @@ module MongoDbUtils
57
57
  !@buckets.find{ |b| b.to_s == bucket.to_s}.nil?
58
58
  end
59
59
 
60
- def to_s
61
- "Config"
62
- end
63
-
64
60
  private
65
61
  def save
66
62
  @writer.save(self) unless @writer.nil?
67
63
  end
68
64
 
69
65
  def add_db(db)
66
+ raise "nil db" if db.nil?
70
67
  @dbs = [] if @dbs.nil?
71
- unless db.nil? || already_contains(db)
68
+ unless already_contains(db)
72
69
  @dbs << db
73
70
  @dbs.sort!
74
71
  save
75
72
  end
76
- @dbs.include?(db) && !db.nil?
73
+ @dbs.include?(db)
77
74
  end
78
75
 
79
76
  end
@@ -4,6 +4,14 @@ module MongoDbUtils
4
4
 
5
5
  module Tools
6
6
 
7
+ class ToolsException < RuntimeError
8
+ attr :cmd, :output
9
+ def initialize(cmd, output)
10
+ @cmd = cmd
11
+ @output =output
12
+ end
13
+ end
14
+
7
15
  class BaseCmd
8
16
  private
9
17
  def self.o(key,value)
@@ -31,7 +39,6 @@ module MongoDbUtils
31
39
  end
32
40
 
33
41
  class Dump < BaseCmd
34
-
35
42
  # create the cmd string that will be executed by the system
36
43
  def self.cmd(host_and_port,db,output,username = "", password = "")
37
44
  options = build_base_options(host_and_port,db,username,password)
@@ -43,9 +50,9 @@ module MongoDbUtils
43
50
  def self.run(host_and_port,db,output,username="", password ="")
44
51
  cmd_string = self.cmd(host_and_port,db,output,username,password)
45
52
  puts "[Dump] run: #{cmd_string}"
46
- `#{cmd_string}`
53
+ output = `#{cmd_string}`
54
+ raise ToolsException.new("#{cmd_string}", output) unless $?.to_i == 0
47
55
  end
48
-
49
56
  end
50
57
 
51
58
  class Restore < BaseCmd
@@ -58,7 +65,8 @@ module MongoDbUtils
58
65
  def self.run(host_and_port,db,source_folder,username="", password ="")
59
66
  cmd_string = self.cmd(host_and_port,db,source_folder,username,password)
60
67
  puts "[Restore] run: #{cmd_string}"
61
- `#{cmd_string}`
68
+ output = `#{cmd_string}`
69
+ raise ToolsException.new("#{cmd_string}", output) unless $?.to_i == 0
62
70
  end
63
71
  end
64
72
 
@@ -75,6 +83,5 @@ module MongoDbUtils
75
83
  @value.nil? || @value.empty?
76
84
  end
77
85
  end
78
-
79
86
  end
80
87
  end
@@ -1,4 +1,4 @@
1
1
  module MongoDbUtils
2
- VERSION = "0.0.9.2"
2
+ VERSION = "0.0.9.3"
3
3
  READY_FOR_USE = "(Beta version)"
4
4
  end
@@ -21,7 +21,7 @@ describe MongoDbUtils do
21
21
  it "should write a config correctly" do
22
22
  path = ".tmp_path/config2.yml"
23
23
  config = MongoDbUtils::ConfigLoader.new(path).config
24
- config.add_db_from_uri("mongodb://localhost:27017/db")
24
+ config.add_single_db("mongodb://localhost:27017/db")
25
25
  loaded_config = YAML.load(File.open(path))
26
26
  loaded_config.dbs[0].uri.should == config.dbs[0].uri
27
27
  end
@@ -23,7 +23,7 @@ describe MongoDbUtils::ConfigProxy do
23
23
 
24
24
  it "should add a single db" do
25
25
  db = HighLine::String.new("mongodb://localhost:27017/db ")
26
- @config.add_db_from_uri(db)
26
+ @config.add_single_db(db)
27
27
  @config.dbs.length.should == 1
28
28
  @config.dbs[0].uri.should == "mongodb://localhost:27017/db"
29
29
  @config.dbs[0].uri.class.to_s.should == "String"
@@ -22,20 +22,20 @@ describe MongoDbUtils::Model::Config do
22
22
  end
23
23
 
24
24
  it "should add a single db" do
25
- @config.add_db_from_uri( "mongodb://localhost:27017/db")
25
+ @config.add_single_db( "mongodb://localhost:27017/db")
26
26
  @config.dbs.length.should == 1
27
- @config.add_db_from_uri( "mongodb://localhost:27017/db2")
27
+ @config.add_single_db( "mongodb://localhost:27017/db2")
28
28
  @config.dbs.length.should == 2
29
29
  end
30
30
 
31
31
  it "should not add the db if its already there" do
32
- @config.add_db_from_uri( "mongodb://localhost:27017/db")
33
- @config.add_db_from_uri( "mongodb://localhost:27017/db")
32
+ @config.add_single_db( "mongodb://localhost:27017/db")
33
+ @config.add_single_db( "mongodb://localhost:27017/db")
34
34
  @config.dbs.length.should == 1
35
35
  end
36
36
 
37
37
  it "should remove a single db" do
38
- @config.add_db_from_uri( "mongodb://localhost:27017/db")
38
+ @config.add_single_db( "mongodb://localhost:27017/db")
39
39
  @config.dbs.length.should == 1
40
40
  @config.remove_db(@config.dbs[0])
41
41
  @config.dbs.length.should == 0
@@ -49,4 +49,8 @@ describe MongoDbUtils::Model::Config do
49
49
  @config.dbs.length.should == 0
50
50
  end
51
51
 
52
+ it "should throw an exception if add a nil db" do
53
+ expect { @config.add_single_db(nil)}.to raise_error
54
+ end
55
+
52
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo-db-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9.2
4
+ version: 0.0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - edeustace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -145,6 +145,7 @@ extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
147
  - .gitignore
148
+ - .travis.yml
148
149
  - Gemfile
149
150
  - LICENSE
150
151
  - README.md