gomon 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13c1f6fc23957b2744e0f9c44afa4ef1773bfe47
4
+ data.tar.gz: 4650d0201660a9486950dfc7bc9335f607209cd0
5
+ SHA512:
6
+ metadata.gz: e50aa4ed12ac8cf6e7c6047555071bb116e409a8fce93a063b8def90d7d90b73ac11594ed2e0985487bded3df4656f593563fc057f15d594781175928202ec7f
7
+ data.tar.gz: 77a7b11c9b6443cbbe77ee23cd619fb2762b31dec6fdd81ac814d4fae5fbba08d7e81c57d86877fced24fb3169cba4572868e3332970694087ba645893092506
@@ -1,9 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.0.0
3
4
  - 1.9.3
4
- - 1.9.2
5
5
  - 1.8.7
6
6
  - jruby-18mode
7
7
  - jruby-19mode
8
8
  - rbx-18mode
9
9
  - rbx-19mode
10
+ notifications:
11
+ email: false
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
@@ -1,18 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gomon (0.0.3)
4
+ gomon (1.0.0)
5
5
  activesupport
6
+ clue (~> 1.0.0)
6
7
 
7
8
  GEM
8
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
9
10
  specs:
10
- activesupport (3.2.11)
11
- i18n (~> 0.6)
11
+ activesupport (3.2.13)
12
+ i18n (= 0.6.1)
12
13
  multi_json (~> 1.0)
14
+ clue (1.0.0)
15
+ activesupport
13
16
  diff-lcs (1.1.3)
14
17
  i18n (0.6.1)
15
- multi_json (1.5.0)
18
+ multi_json (1.7.2)
16
19
  rake (10.0.3)
17
20
  rspec (2.12.0)
18
21
  rspec-core (~> 2.12.0)
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2012 Novelys
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom
8
+ the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -6,7 +6,7 @@ Ruby wrappers around mongodb cli tools.
6
6
 
7
7
  [![Build Status](https://travis-ci.org/novelys/gomon.png?branch=master)](https://travis-ci.org/novelys/gomon)
8
8
 
9
- This gem depends on no other gems. It is tested agains many rubies: 1.8.7, 1.9.2, 1.9.3, jruby-18, jruby-19, rubinius-18, rubinius-19.
9
+ This gem is built upon [novelys/clue](https://github.com/novelys/clue/). It is tested agains many rubies: 1.8.7, 1.9.3, 2.0.0, jruby-18, jruby-19, rubinius-18, rubinius-19.
10
10
 
11
11
  It assumes the presence of `mongorestore` and `mongodump` commands.
12
12
  It was built around the latest mongodb tools at the moment of this writing, meaning version 2.2.2.
@@ -23,35 +23,22 @@ Gemfile : `gem 'gomon'`
23
23
  The tools currently supported are `mongodump` and `mongorestore`.
24
24
  They are wrapped in `Gomon::Dump` and `Gomon::Restore` respectively.
25
25
 
26
- These two classes are used in the same way: first, instantiate the object, then, invoke `call` without arguments on it. In most cases, the only difference of usage will be the options passed to the constructor.
26
+ They are used in the same way as any instance of [clue](https://github.com/novelys/clue/) is used,
27
+ so you should refer to clue's documentation. What makes `gomon` different is its support fort parsing mongodb uris.
27
28
 
28
29
  ### Example
29
30
 
30
- > gd = Gomon::Dump.new uri: "mongodb://user:pass@host:12345/database", other: 'journal'
31
- > gd.cmd_string
32
- => "mongodump --host 'host' --port '12345' --username 'user' --password 'pass' --db 'database' --journal"
33
- > gd.call
34
- # Dumping `database` from host...
35
- # Executing: mongodump --host 'host' --port '12345' --username 'user' --password 'pass' --db 'database' --journal
36
- # ....
37
- # Done dumping.
38
- => nil
39
-
40
- ### Options
41
-
42
- The two classes accepts a hash of options when initializing, as in `gd = Gomon::Dumper.new(db: 'gem_test')`. You can also supply this hash later by calling `gd.handle_options(opts)`, both have the same effect. When you add options this way, some specific rules apply :
43
-
44
- * If the key `:uri` is present, its value will be parsed and split to retrieve the username, password, host, port, and database;
45
- * Specific to `Gomon::Restore`: the option value for the key `:path` will be used as its last argument, as is.
46
-
47
- Adding options using the following methods will **not** trigger the specific behaviours listed above.
48
-
49
- * `add_option(key, value)`: adds the option. It will override previous ones.
50
- * `add_options(hash)`: adds the options. It will override previous ones.
51
- * `add_singular_option(string): adds the singular option. Duplicates will be removed.
52
- * `add_singular_options(string_or_array): adds the singular options. Duplicates will be removed.
53
-
54
- Options keys will always be casted as symbols, while values will always be casted as string.
31
+ ```ruby
32
+ > gd = Gomon::Dump.new options: ['journal', uri: "mongodb://user:pass@host:12345/database"]
33
+ > gd.cli_command
34
+ => "mongodump --username 'user' --password 'pass' --host 'host' --port '12345' --db 'database' --journal"
35
+ > gd.call
36
+ # Dumping `database` from host...
37
+ # Executing: mongodump --host 'host' --port '12345' --username 'user' --password 'pass' --db 'database' --journal
38
+ # ....
39
+ # Done dumping.
40
+ => nil
41
+ ```
55
42
 
56
43
  No validation of options is done, so you should be careful about supplying only options accepted by `mongodump` or `mongorestore`. Refer to the [MongoDB Manual](http://docs.mongodb.org/manual/reference/mongorestore/) for more on the topic.
57
44
 
@@ -64,6 +51,7 @@ No validation of options is done, so you should be careful about supplying only
64
51
 
65
52
  ## Changelog
66
53
 
54
+ * `1.0.0`: Tagged '1.0.0'. Uses [novelys/clue](https://github.com/novelys/clue/) as foundation.
67
55
  * `0.4`: Better options handling. Many ruby versions are now supported.
68
56
  * `0.3`: Ruby 1.8 support
69
57
  * `0.2`: Test coverage.
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_path = 'lib'
17
17
 
18
18
  s.add_dependency('activesupport')
19
+ s.add_dependency('clue', '~> 1.0.0')
19
20
  s.add_development_dependency("rspec")
20
21
  s.add_development_dependency("rake")
21
22
  end
@@ -1,41 +1,12 @@
1
- require 'gomon/options'
1
+ require 'clue'
2
2
  require 'gomon/uri'
3
3
 
4
4
  module Gomon
5
- class Base
6
- include Options
5
+ class Base < Clue
7
6
  include Uri
8
7
 
9
- attr_reader :options, :singular_options
10
-
11
- def initialize(opts = {})
12
- init_options :host => 'localhost', :port => '27017'
13
-
14
- handle_options opts
15
- end
16
-
17
- # Handle options addition, with special cases
18
- def handle_options(opts = {})
19
- # Extract singular options
20
- add_singular_options opts.delete(:other)
21
-
22
- # Extract uri into options
23
- add_options parse_uri(opts.delete(:uri)) if opts[:uri]
24
-
25
- # Keep track of other options
26
- add_options opts
27
- end
28
-
29
- # String to execute
30
- def cmd_string
31
- "#{tool} #{cli_options}"
32
- end
33
-
34
- # Execute before/after hookes if any, execute command
35
- def call
36
- before_cmd
37
- system(cmd_string)
38
- after_cmd
8
+ def after_initialize(*args)
9
+ add_options parse_uri(options.delete(:uri)) if options[:uri]
39
10
  end
40
11
  end
41
12
  end
@@ -2,20 +2,18 @@ require 'gomon/base'
2
2
 
3
3
  module Gomon
4
4
  class Dump < Base
5
- attr_reader :tool
6
-
7
- def initialize(opts = {})
5
+ def initialize(*args)
8
6
  super
9
7
 
10
- @tool = 'mongodump'
8
+ @command = 'mongodump'
11
9
  end
12
10
 
13
- def before_cmd
11
+ def before_call
14
12
  puts "Dumping `#{options[:db]}` from #{options[:host]}..."
15
- puts "Executing: #{cmd_string}"
13
+ puts "Executing: #{cli_command}"
16
14
  end
17
15
 
18
- def after_cmd
16
+ def after_call
19
17
  puts "Done dumping."
20
18
  end
21
19
  end
@@ -2,27 +2,18 @@ require 'gomon/base'
2
2
 
3
3
  module Gomon
4
4
  class Restore < Base
5
- attr_reader :tool, :path
5
+ def initialize(*args)
6
+ super
6
7
 
7
- def initialize(opts = {})
8
- @path = opts.delete(:path) || 'dump/*'
9
- super(opts)
10
- @tool = 'mongorestore'
8
+ @command = 'mongorestore'
11
9
  end
12
10
 
13
- # String to execute
14
- def cmd_string
15
- "#{super} '#{path}'"
11
+ def before_call
12
+ puts "Restoring from dir `#{arguments.first}` into `#{options[:db]}` at #{options[:host]}..."
13
+ puts "Executing: #{cli_command}"
16
14
  end
17
15
 
18
- # Hook to execute before restoring
19
- def before_cmd
20
- puts "Restoring from dir `#{path}` into `#{options[:db]}` at #{options[:host]}..."
21
- puts "Executing: #{cmd_string}"
22
- end
23
-
24
- # Hook to execute after restoring
25
- def after_cmd
16
+ def after_call
26
17
  puts "Done restoring."
27
18
  end
28
19
  end
@@ -1,3 +1,3 @@
1
1
  module Gomon
2
- VERSION = '0.0.4'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,19 +1,9 @@
1
1
  require 'gomon/dump'
2
2
 
3
3
  describe "Dump" do
4
-
5
- subject { Gomon::Dump.new :username => 'john', :password => 'mcclane', :db => 'die_hard'}
6
- let(:tool) { subject.instance_variable_get :@tool }
7
- let(:options) { subject.instance_variable_get :@options }
8
- let(:singular) { subject.instance_variable_get :@singular_options }
4
+ subject { Gomon::Dump.new :options => {:username => 'john', :password => 'mcclane', :db => 'die_hard'} }
9
5
 
10
6
  it 'should have a toolname' do
11
- expect(tool).to eq 'mongodump'
12
- end
13
-
14
- it 'should have a command string' do
15
- cmd = "mongodump"
16
- options.each { |k, v| expect(subject.cmd_string).to include "--#{k} '#{v}'" }
17
- singular.each { |k| expect(subject.cmd_string).to include "--#{k}" }
7
+ expect(subject.command).to eq 'mongodump'
18
8
  end
19
9
  end
@@ -1,29 +1,9 @@
1
1
  require 'gomon/restore'
2
2
 
3
3
  describe "Restore" do
4
-
5
- subject { Gomon::Restore.new :path => 'dump/dir', :db => 'die_hard', :username => 'john' }
6
- let(:tool) { subject.instance_variable_get :@tool }
7
- let(:path) { subject.instance_variable_get :@path }
8
- let(:options) { subject.instance_variable_get :@options }
9
- let(:singular) { subject.instance_variable_get :@singular_options }
4
+ subject { Gomon::Restore.new :options => [:db => 'die_hard', :username => 'john'], :arguments => 'dump/dir' }
10
5
 
11
6
  it 'should have a toolname' do
12
- expect(tool).to eq 'mongorestore'
13
- end
14
-
15
- it 'should not have a path option' do
16
- expect(options.has_key?(:path)).to be false
17
- end
18
-
19
- it 'should have a path' do
20
- expect(path).to eq 'dump/dir'
21
- end
22
-
23
- it 'should have a command string' do
24
- cmd = "mongorestore"
25
- options.each { |k, v| expect(subject.cmd_string).to include "--#{k} '#{v}'" }
26
- singular.each { |k| expect(subject.cmd_string).to include "--#{k}" }
27
- expect(subject.cmd_string).to satisfy { |str| str.end_with? "'#{path}'" }
7
+ expect(subject.command).to eq 'mongorestore'
28
8
  end
29
9
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gomon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Novelys
@@ -10,54 +9,62 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: clue
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.0
31
42
  - !ruby/object:Gem::Dependency
32
43
  name: rspec
33
44
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
45
  requirements:
36
- - - ! '>='
46
+ - - '>='
37
47
  - !ruby/object:Gem::Version
38
48
  version: '0'
39
49
  type: :development
40
50
  prerelease: false
41
51
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
52
  requirements:
44
- - - ! '>='
53
+ - - '>='
45
54
  - !ruby/object:Gem::Version
46
55
  version: '0'
47
56
  - !ruby/object:Gem::Dependency
48
57
  name: rake
49
58
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
59
  requirements:
52
- - - ! '>='
60
+ - - '>='
53
61
  - !ruby/object:Gem::Version
54
62
  version: '0'
55
63
  type: :development
56
64
  prerelease: false
57
65
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
66
  requirements:
60
- - - ! '>='
67
+ - - '>='
61
68
  - !ruby/object:Gem::Version
62
69
  version: '0'
63
70
  description: A set of ruby classing wrapping mongodb cli tools, making them pleasant
@@ -72,44 +79,41 @@ files:
72
79
  - .travis.yml
73
80
  - Gemfile
74
81
  - Gemfile.lock
82
+ - LICENCE.md
75
83
  - README.md
76
84
  - Rakefile
77
85
  - gomon.gemspec
78
86
  - lib/gomon.rb
79
87
  - lib/gomon/base.rb
80
88
  - lib/gomon/dump.rb
81
- - lib/gomon/options.rb
82
89
  - lib/gomon/restore.rb
83
90
  - lib/gomon/uri.rb
84
91
  - lib/gomon/version.rb
85
- - spec/base_spec.rb
86
92
  - spec/dump_spec.rb
87
- - spec/options_spec.rb
88
93
  - spec/restore_spec.rb
89
94
  - spec/spec_helper.rb
90
95
  - spec/uri_spec.rb
91
96
  homepage: http://github.com/novelys/gomon
92
97
  licenses: []
98
+ metadata: {}
93
99
  post_install_message:
94
100
  rdoc_options: []
95
101
  require_paths:
96
102
  - lib
97
103
  required_ruby_version: !ruby/object:Gem::Requirement
98
- none: false
99
104
  requirements:
100
- - - ! '>='
105
+ - - '>='
101
106
  - !ruby/object:Gem::Version
102
107
  version: '0'
103
108
  required_rubygems_version: !ruby/object:Gem::Requirement
104
- none: false
105
109
  requirements:
106
- - - ! '>='
110
+ - - '>='
107
111
  - !ruby/object:Gem::Version
108
112
  version: 1.3.6
109
113
  requirements: []
110
114
  rubyforge_project: gomon
111
- rubygems_version: 1.8.23
115
+ rubygems_version: 2.0.3
112
116
  signing_key:
113
- specification_version: 3
117
+ specification_version: 4
114
118
  summary: Ruby wrappers around mongo utilities.
115
119
  test_files: []
@@ -1,58 +0,0 @@
1
- require 'active_support/core_ext/enumerable'
2
-
3
- module Gomon
4
- module Options
5
- # Initialize options ivars
6
- def init_options(defaults = {})
7
- @options = {}
8
- @singular_options = []
9
-
10
- add_options defaults
11
- end
12
-
13
- # Add a singular option
14
- def add_singular_option(option)
15
- @singular_options << option.to_s
16
- @singular_options.uniq!
17
- end
18
-
19
- # Add many singular options
20
- def add_singular_options(options)
21
- return unless options
22
- options = options.split(' ') if options.is_a?(String)
23
-
24
- @singular_options += options.map(&:to_s)
25
- @singular_options.uniq!
26
- end
27
-
28
- # Add a single options
29
- def add_option(key, value)
30
- @options[key.to_sym] = value.to_s
31
- end
32
-
33
- # Add many options
34
- def add_options(opts = {})
35
- opts.each { |key, value| add_option key, value }
36
- end
37
-
38
- # Returns the options string
39
- def cli_options
40
- options_as_array.join(' ')
41
- end
42
-
43
- # Returns options as an array
44
- def options_as_array
45
- # Valued options
46
- ary = @options.each_with_object([]) do |(key, value), memo|
47
- memo << "--#{key.to_s} '#{value.to_s}'"
48
- end
49
-
50
- # Singular options
51
- ary = @singular_options.each_with_object(ary) do |opt, memo|
52
- memo << "--#{opt.to_s}"
53
- end
54
-
55
- ary
56
- end
57
- end
58
- end
@@ -1,66 +0,0 @@
1
- require 'gomon/base'
2
-
3
- describe "Base" do
4
- context 'default options' do
5
- subject { Gomon::Base.new }
6
- let(:options) { subject.instance_variable_get :@options }
7
-
8
- it 'host should be localhost' do
9
- expect(options[:host]).to eq 'localhost'
10
- end
11
-
12
- it 'port should be 27017' do
13
- expect(options[:port]).to eq '27017'
14
- end
15
- end
16
-
17
- context 'initialized with uri' do
18
- subject { Gomon::Base.new :uri => "mongodb://john:wayne@marlon.bran.do:23042/dark_side_of_the_moon" }
19
- let(:options) { subject.instance_variable_get :@options }
20
-
21
- it 'should not have uri' do
22
- expect(options.has_key?(:uri)).not_to be_true
23
- end
24
-
25
- it 'should have username' do
26
- expect(options[:username]).to be
27
- end
28
-
29
- it 'should have password' do
30
- expect(options[:password]).to be
31
- end
32
-
33
- it 'should have host' do
34
- expect(options[:host]).to be
35
- end
36
-
37
- it 'should have port' do
38
- expect(options[:port]).to be
39
- end
40
-
41
- it 'should have database' do
42
- expect(options[:db]).to be
43
- end
44
- end
45
-
46
- context 'initialized with other' do
47
- subject { Gomon::Base.new :other => "first third" }
48
- let(:options) { subject.instance_variable_get :@singular_options }
49
-
50
- it 'should have singular options' do
51
- expect(options).to include 'first'
52
- expect(options).to include 'third'
53
- end
54
- end
55
-
56
- context 'initialized with options' do
57
- subject { Gomon::Base.new :host => 'john', :username => 'wayne', :out => 'side' }
58
- let(:options) { subject.instance_variable_get :@options }
59
-
60
- it 'should have options set' do
61
- expect(options[:host]).to eq 'john'
62
- expect(options[:username]).to eq 'wayne'
63
- expect(options[:out]).to eq 'side'
64
- end
65
- end
66
- end
@@ -1,70 +0,0 @@
1
- require 'gomon/options'
2
-
3
- describe "Options" do
4
- before :all do
5
- class TestObject
6
- include Gomon::Options
7
-
8
- def initialize; init_options; end
9
- end
10
- end
11
-
12
- subject { TestObject.new }
13
- let(:options) { subject.instance_variable_get :@options }
14
- let(:singular) { subject.instance_variable_get :@singular_options }
15
-
16
- it 'should add one option' do
17
- subject.add_option :key, 'value'
18
- expect(options[:key]).to eq 'value'
19
- end
20
-
21
- it 'should add several options' do
22
- subject.add_options :key1 => 'value1', :key2 => 'value2'
23
- expect(options[:key1]).to eq 'value1'
24
- expect(options[:key2]).to eq 'value2'
25
- end
26
-
27
- it 'should add options with symbols as keys' do
28
- subject.add_options 'key' => 'value'
29
- expect(options[:key]).to eq 'value'
30
- end
31
-
32
- it 'should add one singular option' do
33
- subject.add_singular_option 'hank'
34
- expect(singular).to include 'hank'
35
- end
36
-
37
- it 'should add several singular options given as string' do
38
- subject.add_singular_options 'rocky balboa'
39
- expect(singular).to include 'rocky', 'balboa'
40
- end
41
-
42
- it 'should add several singular options given as array' do
43
- subject.add_singular_options ['rocky', 'balboa']
44
- expect(singular).to include 'rocky', 'balboa'
45
- end
46
-
47
- it 'can override previous keys' do
48
- subject.add_option :key, 'value'
49
- expect(options[:key]).to eq 'value'
50
- subject.add_option :key, 'new_value'
51
- expect(options[:key]).to eq 'new_value'
52
- end
53
-
54
- it 'should not add many times the same singular option' do
55
- subject.add_singular_options ['rocky', 'rocky']
56
- expect(singular).to include 'rocky'
57
- expect(singular.size).to eq 1
58
- end
59
-
60
- it 'can merge options into a string' do
61
- subject.add_options :key1 => 'value1', :key2 => 'value2'
62
- subject.add_singular_options %w(john jim jones)
63
-
64
- expect(subject.cli_options).to include "--key1 'value1'"
65
- expect(subject.cli_options).to include "--key2 'value2'"
66
- expect(subject.cli_options).to include "--john"
67
- expect(subject.cli_options).to include "--jim"
68
- expect(subject.cli_options).to include "--jones"
69
- end
70
- end