mongo-util 0.0.2 → 0.0.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: 7ce946a3aab8df1e1933ffd88e4991c992e129a9
4
- data.tar.gz: a3dfad61ebc465b5f3dad97fbe5b08586e6eba12
3
+ metadata.gz: f94f3651f20125bfe48640a9a4f98574701ebac4
4
+ data.tar.gz: 154ffce121464f14a5d58bae6fb392eb1dacb9ce
5
5
  SHA512:
6
- metadata.gz: 6df06ef07f8ac9ddfb902c09321013bdb314adf2e6ec4739b911a585626be8f244ca185aac6608ac6da2b963f1706300a362f6f8774cc1fb25997df04a683689
7
- data.tar.gz: 31a9e1d4d32af7fa52be465b1f07825523513bd110771c4a47a77e74d2a8d33a69d9237ce2ab015d4f6b6700b412e5936e8b0d331d5a4c64916a9823df3538db
6
+ metadata.gz: 887e1f5f18150197502810755e8c36bacad29234a174270b3c614e04f9b9318a838a512338492d78c8af19badf0fbbe132afae969f12f328e3d8201a7bc149cb
7
+ data.tar.gz: bc973d8b57bb5b5e6e08b168ec1f7ff7979a18c63b3ded1715cae2fa2ac64b18b0b0c07793eb30e081bc847bea28c8034edc5f94d903f9944bafdb09216e98d4
data/lib/mongo/util.rb CHANGED
@@ -37,7 +37,7 @@ module Mongo
37
37
  # Append auth, if neccessary
38
38
  cmd += Mongo::Util.authentication(@from)
39
39
 
40
- system(cmd)
40
+ self.exec(cmd)
41
41
  end
42
42
 
43
43
  # Restore contents of @dump_dr to @to{database}
@@ -50,7 +50,7 @@ module Mongo
50
50
  # Append auth, if neccessary
51
51
  cmd += Mongo::Util.authentication(@to)
52
52
 
53
- system(cmd)
53
+ self.exec(cmd)
54
54
  end
55
55
 
56
56
  # Removes all items / items which match options[:query]
@@ -65,7 +65,7 @@ module Mongo
65
65
  cmd += Mongo::Util.authentication(@to)
66
66
  cmd += " --eval 'db.#{collection}.remove(#{options[:query] ? options[:query].to_json : ""});'"
67
67
 
68
- system(cmd)
68
+ self.exec(cmd)
69
69
  end
70
70
 
71
71
  # Returns Array of all collection-names of @to{database}
@@ -78,12 +78,20 @@ module Mongo
78
78
  # Append auth, if neccessary
79
79
  cmd += Mongo::Util.authentication(@to)
80
80
 
81
- `#{cmd}`.rstrip.split(',')
81
+ collections = self.exec(cmd, return_output: true).rstrip.split(',')
82
+ # If we have a '{' in the output, Mongo has thrown an error
83
+ collections.each {|col| raise "Error while fetching collections: '#{collections.join()}'" if col.include?('{')}
82
84
  end
83
85
 
84
86
  # Deletes @dump_dir
85
87
  def clean
86
- system("rm -rf #{@dump_dir}")
88
+ self.exec("rm -rf #{@dump_dir}")
89
+ end
90
+
91
+ def exec(cmd, options={})
92
+ # Print commands for debugging
93
+ print "Executing: '#{cmd}'\n"
94
+ options[:return_output] ? `#{cmd}` : system(cmd)
87
95
  end
88
96
 
89
97
  # Enable auth if we set db_config contains user & password
@@ -1,5 +1,5 @@
1
1
  module Mongo
2
2
  module Util
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn-Lenanrt Heemeyer