dumper 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/dumper.gemspec +6 -0
- data/lib/dumper/database/mongodb.rb +7 -5
- data/lib/dumper/stack.rb +11 -12
- data/lib/dumper/version.rb +1 -1
- data/spec/dumper_spec.rb +52 -1
- metadata +82 -2
data/dumper.gemspec
CHANGED
@@ -18,6 +18,12 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_runtime_dependency 'multi_json', '~> 1.0'
|
19
19
|
gem.add_runtime_dependency 'multipart-post', '~> 1.1.5'
|
20
20
|
gem.add_runtime_dependency 'posix-spawn', '~> 0.3.6'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'bson_ext'
|
23
|
+
gem.add_development_dependency 'mongo_mapper'
|
24
|
+
gem.add_development_dependency 'mongoid', '~> 3.0'
|
25
|
+
gem.add_development_dependency 'rails', '~> 3.2.6'
|
26
|
+
gem.add_development_dependency 'redis'
|
21
27
|
gem.add_development_dependency 'rspec'
|
22
28
|
|
23
29
|
# For Travis
|
@@ -21,15 +21,17 @@ module Dumper
|
|
21
21
|
|
22
22
|
def set_config_for(rails_env=nil)
|
23
23
|
return unless defined?(Mongo::DB) &&
|
24
|
-
(mongo = find_instance_in_object_space(Mongo::DB))
|
24
|
+
(mongo = find_instance_in_object_space(Mongo::DB)) ||
|
25
|
+
defined?(Mongoid) && Mongoid::Config.respond_to?(:sessions) &&
|
26
|
+
(mongoid = Mongoid::Config.sessions[:default])
|
25
27
|
|
26
28
|
@config = {
|
27
|
-
:host => mongo.connection.host,
|
28
|
-
:port => mongo.connection.port,
|
29
|
-
:database => mongo.name,
|
29
|
+
:host => mongo ? mongo.connection.host : mongoid[:hosts].first.split(/:/).first,
|
30
|
+
:port => mongo ? mongo.connection.port : mongoid[:hosts].first.split(/:/).last,
|
31
|
+
:database => mongo ? mongo.name : mongoid[:database],
|
30
32
|
:dump_tool => dump_tool_path
|
31
33
|
}.tap do |h|
|
32
|
-
if auth = mongo.connection.auths.first
|
34
|
+
if auth = mongo ? mongo.connection.auths.first : mongoid
|
33
35
|
h.update(:username => auth['username'], :password => auth['password'])
|
34
36
|
end
|
35
37
|
end
|
data/lib/dumper/stack.rb
CHANGED
@@ -15,7 +15,7 @@ module Dumper
|
|
15
15
|
@databases = {}
|
16
16
|
|
17
17
|
# Rackup?
|
18
|
-
@rackup = find_instance_in_object_space(Rack::Server)
|
18
|
+
@rackup = defined?(Rack::Server) && find_instance_in_object_space(Rack::Server)
|
19
19
|
|
20
20
|
# Rails?
|
21
21
|
if defined?(::Rails)
|
@@ -23,21 +23,20 @@ module Dumper
|
|
23
23
|
@rails_env = Rails.env.to_s
|
24
24
|
@rails_version = Rails::VERSION::STRING
|
25
25
|
@is_supported_rails_version = (::Rails::VERSION::MAJOR >= 3)
|
26
|
-
|
27
|
-
if defined?(MongoMapper)
|
28
|
-
MongoMapper.database # Creates the Mongo::DB instance
|
29
|
-
end
|
30
|
-
|
31
|
-
DATABASES.each do |key, klass|
|
32
|
-
database = klass.new
|
33
|
-
next unless database.set_config_for(@rails_env) || database.set_config_for(options[:additional_env])
|
34
|
-
@databases[key] = database
|
35
|
-
end
|
36
|
-
|
37
26
|
else
|
38
27
|
@framework = :ruby
|
39
28
|
end
|
40
29
|
|
30
|
+
if defined?(MongoMapper)
|
31
|
+
MongoMapper.database # Trigger to create a Mongo::DB instance
|
32
|
+
end
|
33
|
+
|
34
|
+
DATABASES.each do |key, klass|
|
35
|
+
database = klass.new
|
36
|
+
next unless database.set_config_for(@rails_env) || database.set_config_for(options[:additional_env])
|
37
|
+
@databases[key] = database
|
38
|
+
end
|
39
|
+
|
41
40
|
# Which dispatcher?
|
42
41
|
[ :unicorn, :passenger, :thin, :mongrel, :webrick, :resque ].find do |name|
|
43
42
|
@dispatcher = send("#{name}?") ? name : nil
|
data/lib/dumper/version.rb
CHANGED
data/spec/dumper_spec.rb
CHANGED
@@ -1,7 +1,58 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'rails'
|
4
|
+
|
3
5
|
describe Dumper do
|
4
|
-
it '
|
6
|
+
it 'conforms to public API' do
|
5
7
|
Dumper::Agent.respond_to?(:start).should be_true
|
6
8
|
end
|
9
|
+
|
10
|
+
describe :Stack do
|
11
|
+
it 'initializes stack' do
|
12
|
+
stack = Dumper::Stack.new
|
13
|
+
stack.framework.should == :rails
|
14
|
+
stack.rails_env.should == 'development'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'detects mongoid 3' do
|
18
|
+
require 'mongoid'
|
19
|
+
Mongoid::Config.send :load_configuration, { sessions: { default: { hosts: ['localhost:27017'], database: 'test' } } }
|
20
|
+
|
21
|
+
stack = Dumper::Stack.new
|
22
|
+
stack.databases[:mongodb].should_not == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'detects mongo_mapper' do
|
26
|
+
require 'mongo_mapper'
|
27
|
+
MongoMapper.setup({ development: { database: 'test' } }, :development)
|
28
|
+
MongoMapper.database
|
29
|
+
|
30
|
+
stack = Dumper::Stack.new
|
31
|
+
stack.databases[:mongodb].should_not == nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'detects mysql' do
|
35
|
+
require 'active_record'
|
36
|
+
ActiveRecord::Base.configurations['development'] = { 'adapter' => 'mysql2' }
|
37
|
+
|
38
|
+
stack = Dumper::Stack.new
|
39
|
+
stack.databases[:mysql].should_not == nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'detects postgresql' do
|
43
|
+
require 'active_record'
|
44
|
+
ActiveRecord::Base.configurations['development'] = { 'adapter' => 'postgresql' }
|
45
|
+
|
46
|
+
stack = Dumper::Stack.new
|
47
|
+
stack.databases[:postgresql].should_not == nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'detects redis' do
|
51
|
+
require 'redis'
|
52
|
+
redis = Redis.new
|
53
|
+
|
54
|
+
stack = Dumper::Stack.new
|
55
|
+
stack.databases[:redis].should_not == nil
|
56
|
+
end
|
57
|
+
end
|
7
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -59,6 +59,86 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.3.6
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bson_ext
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mongo_mapper
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: mongoid
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '3.0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rails
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.2.6
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 3.2.6
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: redis
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
62
142
|
- !ruby/object:Gem::Dependency
|
63
143
|
name: rspec
|
64
144
|
requirement: !ruby/object:Gem::Requirement
|