dbmanager 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## v0.1.3
2
+
3
+ * environments are now listed sorted
4
+ * raise meaningful error when database.yml contains invalid data
5
+
6
+ ## v0.1.2
7
+
8
+ * move checks for protected environment from adapters to dumpable and importable modules
9
+
1
10
  ## v0.1.0
2
11
 
3
12
  * major code refactoring
@@ -13,7 +13,7 @@ module Dbmanager
13
13
  end
14
14
 
15
15
  def run
16
- output.puts "\nPlease choose target file (defaults to #{default_filename}):\n\n"
16
+ output.print "\nPlease choose target file (defaults to #{default_filename}): "
17
17
  @filename = get_filename
18
18
  dumper.run
19
19
  output.puts "Database successfully dumped in #{filename} file."
@@ -1,3 +1,3 @@
1
1
  module Dbmanager
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -5,7 +5,8 @@ require 'active_support/core_ext/hash'
5
5
  module Dbmanager
6
6
  module YmlParser
7
7
  extend self
8
- attr_writer :config
8
+
9
+ class YmlInvalidError < StandardError; end
9
10
 
10
11
  def config
11
12
  @config ||= yml_load(db_config_file).deep_merge(override_config)
@@ -22,16 +23,25 @@ module Dbmanager
22
23
 
23
24
  def environments
24
25
  @environments ||= begin
25
- config.select do |key, value|
26
- value.has_key?('adapter')
27
- end.each_with_object(ActiveSupport::OrderedHash.new) do |arr, hash|
28
- hash[arr[0]] = Environment.new arr[1].merge(:name => arr[0])
26
+ yml_sorted_envs.each_with_object(ActiveSupport::OrderedHash.new) do |arr, hash|
27
+ env_name, env_config = arr[0], arr[1]
28
+ begin
29
+ hash[env_name] = Environment.new env_config.merge(:name => env_name)
30
+ rescue NoMethodError
31
+ raise YmlInvalidError, invalid_message(env_name, env_config)
32
+ end
29
33
  end
30
34
  end
31
35
  end
32
36
 
33
37
  private
34
38
 
39
+ def yml_sorted_envs
40
+ config.select do |key, value|
41
+ value.has_key?('adapter')
42
+ end.sort
43
+ end
44
+
35
45
  def yml_load(path)
36
46
  YAML.load(ERB.new(File.read(path)).result) || {}
37
47
  end
@@ -43,5 +53,10 @@ module Dbmanager
43
53
  def db_override_file
44
54
  File.join Dbmanager.rails_root, 'config', 'dbmanager_override.yml'
45
55
  end
56
+
57
+ def invalid_message(env_name, config)
58
+ message = "\"#{env_name}\" config seems to be corrupted:\n#{config.inspect}"
59
+ message << "\nPlease verify database.yml file (original error: #{$!.message})"
60
+ end
46
61
  end
47
62
  end
@@ -4,7 +4,7 @@ module Dbmanager
4
4
  describe YmlParser do
5
5
  before do
6
6
  stub_rails_root
7
- YmlParser.config = nil
7
+ YmlParser.instance_eval { @config = nil }
8
8
  end
9
9
 
10
10
  describe '#config' do
metadata CHANGED
@@ -1,74 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dbmanager
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - andrea longhi
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-07-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
39
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :development
61
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
62
  description: helps manage db dumps and imports via rake tasks
63
- email:
63
+ email:
64
64
  - andrea.longhi@mikamai.com
65
65
  executables: []
66
-
67
66
  extensions: []
68
-
69
67
  extra_rdoc_files: []
70
-
71
- files:
68
+ files:
72
69
  - .gitignore
73
70
  - CHANGELOG.md
74
71
  - Gemfile
@@ -100,40 +97,31 @@ files:
100
97
  - spec/lib/yml_parser_spec.rb
101
98
  - spec/spec_helper.rb
102
99
  - spec/support/std_stub.rb
103
- homepage: ""
100
+ homepage: ''
104
101
  licenses: []
105
-
106
102
  post_install_message:
107
103
  rdoc_options: []
108
-
109
- require_paths:
104
+ require_paths:
110
105
  - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
112
107
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
120
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
113
  none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 0
128
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
129
118
  requirements: []
130
-
131
119
  rubyforge_project: dbmanager
132
120
  rubygems_version: 1.8.24
133
121
  signing_key:
134
122
  specification_version: 3
135
123
  summary: database manager
136
- test_files:
124
+ test_files:
137
125
  - spec/fixtures/adapter_sample.rb
138
126
  - spec/fixtures/config/database.yml
139
127
  - spec/fixtures/config/dbmanager_override.yml