hummingbird 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,9 +15,25 @@ common denominator amongst those databases.
15
15
 
16
16
  Hummingbird will look for a `hummingbird.yml` in the directory passed
17
17
  to `Hummingbird::Configuration.new`. Hummingbird will also look for a
18
- user-specific `.hummingbird.yml` in the current working directory.
19
- The user-specific configuration file will take precidence over the
20
- configuration in the `hummingbird.yml`.
18
+ user-specific `.hummingbird.yml` in that directory. The user-specific
19
+ configuration file will take precidence over the configuration in the
20
+ `hummingbird.yml`. Both the configuration file name and path, and the
21
+ user-specific configuration name and path can be overridden by passing
22
+ `:config_file => config_name` or `:user_config_file => user_config_name`
23
+ to `Hummingbird::Configuration.new`.
24
+
25
+ For example:
26
+
27
+ ```Ruby
28
+ config = Hummingbird::Configuration.new(
29
+ Dir.getwd,
30
+ config_file: 'path/to/config.yml',
31
+ user_config_file: '/absolute/path/to/user_config.yml'
32
+ )
33
+ ```
34
+ The above example will cause Hummingbird to look for the configuration
35
+ file in `File.join(Dir.getwd, 'path/to/config.yml')`, and to look for
36
+ the user's configuration file in `/absolute/path/to/user_config.yml`.
21
37
 
22
38
  Both of these configuration files are YAML files with the following
23
39
  format:
@@ -59,7 +75,7 @@ handle the maximum file path relative to `migrations_dir`), and a
59
75
  `run_on` column of type `INTEGER`.
60
76
 
61
77
  The following is an example for defining the `migrations_table` for
62
- SQLite3:
78
+ SQLite3, and PostgreSQL:
63
79
 
64
80
  ```sql
65
81
  CREATE TABLE hummingbird_migrations (
@@ -5,23 +5,28 @@ class Hummingbird
5
5
  CONFIG_FILE = 'hummingbird.yml'
6
6
  USER_CONFIG_FILE = '.hummingbird.yml'
7
7
 
8
- def initialize(config_dir)
9
- @config = Optimism.require(
10
- File.expand_path(File.join(config_dir, CONFIG_FILE)),
11
- File.expand_path(File.join(FileUtils.pwd, USER_CONFIG_FILE))
12
- )
8
+ def initialize(config_dir,opts={})
9
+ opts[:config_file] ||= CONFIG_FILE
10
+ opts[:user_config_file] ||= USER_CONFIG_FILE
11
+
12
+ config_file_names = [opts[:config_file],opts[:user_config_file]].map do |f|
13
+ File.expand_path(f,config_dir)
14
+ end
15
+
16
+ @config_dir = config_dir
17
+ @config = Optimism.require(*config_file_names)
13
18
  end
14
19
 
15
20
  def basedir
16
- @basedir ||= @config[:basedir] || '.'
21
+ @basedir ||= File.expand_path(@config[:basedir] || '.', @config_dir)
17
22
  end
18
23
 
19
24
  def planfile
20
- @planfile ||= File.expand_path(File.join(basedir, @config[:planfile] || 'hummingbird.plan'))
25
+ @planfile ||= File.expand_path(@config[:planfile] || 'hummingbird.plan', basedir)
21
26
  end
22
27
 
23
28
  def migrations_dir
24
- @migrations_dir ||= File.expand_path(File.join(basedir, @config[:migrations_dir] || 'migrations'))
29
+ @migrations_dir ||= File.expand_path(@config[:migrations_dir] || 'migrations', basedir)
25
30
  end
26
31
 
27
32
  def migrations_table
@@ -54,7 +54,7 @@ class Hummingbird
54
54
  end
55
55
 
56
56
  def get_migration_contents(migration_file)
57
- File.read(File.absolute_path(migration_file, @migration_dir))
57
+ File.read(File.expand_path(migration_file, @migration_dir))
58
58
  end
59
59
 
60
60
  private
@@ -1,3 +1,3 @@
1
1
  class Hummingbird
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,6 @@
1
+ ---
2
+ basedir: 'overridden-sql'
3
+ planfile: 'overridden-application.plan'
4
+ migrations_dir: 'overridden-migrations-dir'
5
+ migrations_table: 'overridden_application_migrations'
6
+ connection_string: 'overridden sequel connection string'
@@ -15,33 +15,33 @@ describe Hummingbird::Configuration do
15
15
 
16
16
  it 'loads the hummingbird.yml file from the specified config_dir' do
17
17
  copy_fixture_to(
18
- 'basic_config.yml',
18
+ ['config','basic_config.yml'],
19
19
  File.join(@tempdir, Hummingbird::Configuration::CONFIG_FILE)
20
20
  )
21
21
 
22
22
  config = Hummingbird::Configuration.new(@tempdir)
23
23
 
24
- assert_equal 'sql', config.basedir
24
+ assert_equal File.expand_path('sql',@tempdir), config.basedir
25
25
  assert_equal _with_basedir(config, 'application.plan'), config.planfile
26
26
  assert_equal _with_basedir(config, 'migrations-dir'), config.migrations_dir
27
27
  assert_equal :application_migrations, config.migrations_table
28
28
  assert_equal 'sequel connection string', config.connection_string
29
29
  end
30
30
 
31
- it "defaults #basedir to be '.'" do
31
+ it "defaults #basedir to be the configuration directory" do
32
32
  copy_fixture_to(
33
- 'no_basedir_config.yml',
33
+ ['config','no_basedir_config.yml'],
34
34
  File.join(@tempdir, Hummingbird::Configuration::CONFIG_FILE)
35
35
  )
36
36
 
37
37
  config = Hummingbird::Configuration.new(@tempdir)
38
38
 
39
- assert_equal '.', config.basedir
39
+ assert_equal @tempdir, config.basedir
40
40
  end
41
41
 
42
42
  it "defaults #planfile to be basedir + 'hummingbird.plan'" do
43
43
  copy_fixture_to(
44
- 'no_planfile_config.yml',
44
+ ['config','no_planfile_config.yml'],
45
45
  File.join(@tempdir, Hummingbird::Configuration::CONFIG_FILE)
46
46
  )
47
47
 
@@ -52,7 +52,7 @@ describe Hummingbird::Configuration do
52
52
 
53
53
  it "defaults #migrations_dir to be basedir + 'migrations'" do
54
54
  copy_fixture_to(
55
- 'no_migrations_dir_config.yml',
55
+ ['config','no_migrations_dir_config.yml'],
56
56
  File.join(@tempdir, Hummingbird::Configuration::CONFIG_FILE)
57
57
  )
58
58
 
@@ -63,7 +63,7 @@ describe Hummingbird::Configuration do
63
63
 
64
64
  it 'defaults #migrations_table to be :hummingbird_migrations' do
65
65
  copy_fixture_to(
66
- 'no_migrations_table_config.yml',
66
+ ['config','no_migrations_table_config.yml'],
67
67
  File.join(@tempdir, Hummingbird::Configuration::CONFIG_FILE)
68
68
  )
69
69
 
@@ -74,7 +74,7 @@ describe Hummingbird::Configuration do
74
74
 
75
75
  it "does not have a default #connection_string" do
76
76
  copy_fixture_to(
77
- 'no_connection_string_config.yml',
77
+ ['config','no_connection_string_config.yml'],
78
78
  File.join(@tempdir, Hummingbird::Configuration::CONFIG_FILE)
79
79
  )
80
80
 
@@ -83,71 +83,121 @@ describe Hummingbird::Configuration do
83
83
  assert_equal nil, config.connection_string
84
84
  end
85
85
 
86
- it "prefers the user's configuration file if one is present" do
87
- [['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
88
- ['user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE]].each do |s,d|
89
- copy_fixture_to(s, File.join(@tempdir, d))
86
+ it "prefers the user's configuration file if one is present in the config dir" do
87
+ [ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
88
+ ['user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE]].each do |s,d|
89
+ copy_fixture_to(['config',s], File.join(@tempdir, d))
90
90
  end
91
91
 
92
- config = nil
93
- FileUtils.stub :pwd, @tempdir do
94
- config = Hummingbird::Configuration.new(@tempdir)
95
- end
92
+ config = Hummingbird::Configuration.new(@tempdir)
96
93
 
97
- assert_equal 'user-sql', config.basedir
94
+ assert_equal File.expand_path('user-sql', @tempdir), config.basedir
98
95
  assert_equal _with_basedir(config,'user-application.plan'), config.planfile
99
96
  assert_equal _with_basedir(config,'user-migrations-dir'), config.migrations_dir
100
97
  end
101
98
 
102
99
  it "uses non-user basedir if not present for user" do
103
- [['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
100
+ [ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
104
101
  ['no_basedir_user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE]].each do |s,d|
105
- copy_fixture_to(s, File.join(@tempdir, d))
102
+ copy_fixture_to(['config',s], File.join(@tempdir, d))
106
103
  end
107
104
 
108
- config = nil
109
- FileUtils.stub :pwd, @tempdir do
110
- config = Hummingbird::Configuration.new(@tempdir)
111
- end
105
+ config = Hummingbird::Configuration.new(@tempdir)
112
106
 
113
- assert_equal 'sql', config.basedir
107
+ assert_equal File.expand_path('sql', @tempdir), config.basedir
114
108
  assert_equal _with_basedir(config, 'user-application.plan'), config.planfile
115
109
  assert_equal _with_basedir(config, 'user-migrations-dir'), config.migrations_dir
116
110
  end
117
111
 
118
112
  it "uses non-user planfile if not present for user" do
119
- [['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
113
+ [ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
120
114
  ['no_planfile_user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE]].each do |s,d|
121
- copy_fixture_to(s, File.join(@tempdir, d))
115
+ copy_fixture_to(['config',s], File.join(@tempdir, d))
122
116
  end
123
117
 
124
- config = nil
125
- FileUtils.stub :pwd, @tempdir do
126
- config = Hummingbird::Configuration.new(@tempdir)
127
- end
118
+ config = Hummingbird::Configuration.new(@tempdir)
128
119
 
129
- assert_equal 'user-sql', config.basedir
120
+ assert_equal File.expand_path('user-sql', @tempdir), config.basedir
130
121
  assert_equal _with_basedir(config, 'application.plan'), config.planfile
131
122
  assert_equal _with_basedir(config, 'user-migrations-dir'), config.migrations_dir
132
123
  end
133
124
 
134
125
  it "uses non-user migrations_dir if not present for user" do
135
- [['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
126
+ [ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
136
127
  ['no_migrations_dir_user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE]].each do |s,d|
137
- copy_fixture_to(s, File.join(@tempdir, d))
128
+ copy_fixture_to(['config',s], File.join(@tempdir, d))
138
129
  end
139
130
 
140
- config = nil
141
- FileUtils.stub :pwd, @tempdir do
142
- config = Hummingbird::Configuration.new(@tempdir)
143
- end
131
+ config = Hummingbird::Configuration.new(@tempdir)
144
132
 
145
- assert_equal 'user-sql', config.basedir
133
+ assert_equal File.expand_path('user-sql', @tempdir), config.basedir
146
134
  assert_equal _with_basedir(config, 'user-application.plan'), config.planfile
147
135
  assert_equal _with_basedir(config, 'migrations-dir'), config.migrations_dir
148
136
  end
149
137
 
138
+ it "overrides the base config file name when given a relative :config_file option" do
139
+ [ ['overridden_config.yml', 'overridden_name.yml'],
140
+ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE]].each do |s,d|
141
+ copy_fixture_to(['config',s],File.join(@tempdir,d))
142
+ end
143
+
144
+ config = Hummingbird::Configuration.new(@tempdir, config_file: 'overridden_name.yml')
145
+
146
+ assert_equal File.expand_path('overridden-sql', @tempdir), config.basedir
147
+ assert_equal File.expand_path('overridden-application.plan', config.basedir), config.planfile
148
+ assert_equal File.expand_path('overridden-migrations-dir', config.basedir), config.migrations_dir
149
+ assert_equal :overridden_application_migrations, config.migrations_table
150
+ assert_equal 'overridden sequel connection string', config.connection_string
151
+ end
152
+
153
+ it "overrides the base config file name when given an absolute :config_file option" do
154
+ copy_fixture_to(['config','basic_config.yml'], File.join(@tempdir,Hummingbird::Configuration::CONFIG_FILE))
155
+ overridden_config_path = File.join(tempdir,'config.yml')
156
+ copy_fixture_to(['config','overridden_config.yml'], overridden_config_path)
157
+
158
+ config = Hummingbird::Configuration.new(@tempdir, config_file: overridden_config_path)
159
+
160
+ assert_equal File.expand_path('overridden-sql', @tempdir), config.basedir
161
+ assert_equal File.expand_path('overridden-application.plan', config.basedir), config.planfile
162
+ assert_equal File.expand_path('overridden-migrations-dir', config.basedir), config.migrations_dir
163
+ assert_equal :overridden_application_migrations, config.migrations_table
164
+ assert_equal 'overridden sequel connection string', config.connection_string
165
+ end
166
+
167
+ it "overrides the base user config file name when given a relative :user_config_file option" do
168
+ [ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
169
+ ['user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE],
170
+ ['overridden_config.yml', 'overridden_name.yml']].each do |s,d|
171
+ copy_fixture_to(['config',s],File.join(@tempdir,d))
172
+ end
173
+
174
+ config = Hummingbird::Configuration.new(@tempdir, user_config_file: 'overridden_name.yml')
175
+
176
+ assert_equal File.expand_path('overridden-sql', @tempdir), config.basedir
177
+ assert_equal File.expand_path('overridden-application.plan', config.basedir), config.planfile
178
+ assert_equal File.expand_path('overridden-migrations-dir', config.basedir), config.migrations_dir
179
+ assert_equal :overridden_application_migrations, config.migrations_table
180
+ assert_equal 'overridden sequel connection string', config.connection_string
181
+ end
182
+
183
+ it "overrides the base user config file name when given an absolute :user_config_file option" do
184
+ overridden_config_path = File.join(tempdir,'overridden_name.yml')
185
+ [ ['basic_config.yml', Hummingbird::Configuration::CONFIG_FILE],
186
+ ['user_config.yml', Hummingbird::Configuration::USER_CONFIG_FILE],
187
+ ['overridden_config.yml', overridden_config_path]].each do |s,d|
188
+ copy_fixture_to(['config',s],File.expand_path(d,@tempdir))
189
+ end
190
+
191
+ config = Hummingbird::Configuration.new(@tempdir, user_config_file: overridden_config_path)
192
+
193
+ assert_equal File.expand_path('overridden-sql', @tempdir), config.basedir
194
+ assert_equal File.expand_path('overridden-application.plan', config.basedir), config.planfile
195
+ assert_equal File.expand_path('overridden-migrations-dir', config.basedir), config.migrations_dir
196
+ assert_equal :overridden_application_migrations, config.migrations_table
197
+ assert_equal 'overridden sequel connection string', config.connection_string
198
+ end
199
+
150
200
  def _with_basedir(config,path)
151
- File.expand_path(File.join(config.basedir,path))
201
+ File.expand_path(path,config.basedir)
152
202
  end
153
203
  end
data/test/test_helper.rb CHANGED
@@ -45,7 +45,7 @@ class MiniTest::Unit::TestCase
45
45
  end
46
46
 
47
47
  def copy_fixture_to(fixture, dest)
48
- FileUtils.cp(path_to_fixture(fixture), dest)
48
+ FileUtils.cp(path_to_fixture(*fixture), dest)
49
49
  end
50
50
 
51
51
  def assert_set_equal(exp, act, msg = nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hummingbird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.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-10-17 00:00:00.000000000 Z
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -161,22 +161,23 @@ files:
161
161
  - lib/hummingbird/plan.rb
162
162
  - lib/hummingbird/plan_error.rb
163
163
  - lib/hummingbird/version.rb
164
- - test/fixtures/basic_config.yml
165
- - test/fixtures/no_basedir_config.yml
166
- - test/fixtures/no_basedir_user_config.yml
167
- - test/fixtures/no_connection_string_config.yml
168
- - test/fixtures/no_migrations_dir_config.yml
169
- - test/fixtures/no_migrations_dir_user_config.yml
170
- - test/fixtures/no_migrations_table_config.yml
171
- - test/fixtures/no_planfile_config.yml
172
- - test/fixtures/no_planfile_user_config.yml
164
+ - test/fixtures/config/basic_config.yml
165
+ - test/fixtures/config/no_basedir_config.yml
166
+ - test/fixtures/config/no_basedir_user_config.yml
167
+ - test/fixtures/config/no_connection_string_config.yml
168
+ - test/fixtures/config/no_migrations_dir_config.yml
169
+ - test/fixtures/config/no_migrations_dir_user_config.yml
170
+ - test/fixtures/config/no_migrations_table_config.yml
171
+ - test/fixtures/config/no_planfile_config.yml
172
+ - test/fixtures/config/no_planfile_user_config.yml
173
+ - test/fixtures/config/overridden_config.yml
174
+ - test/fixtures/config/user_config.yml
173
175
  - test/fixtures/plan/basic.plan
174
176
  - test/fixtures/sql/migrations/basic/file1.sql
175
177
  - test/fixtures/sql/migrations/basic/file2.sql
176
178
  - test/fixtures/sql/migrations/basic/file3.sql
177
179
  - test/fixtures/sql/migrations/basic/file4.sql
178
180
  - test/fixtures/sql/migrations_table.sql
179
- - test/fixtures/user_config.yml
180
181
  - test/lib/hummingbird/configuration_test.rb
181
182
  - test/lib/hummingbird/database_test.rb
182
183
  - test/lib/hummingbird/plan_test.rb
@@ -204,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  version: '0'
205
206
  segments:
206
207
  - 0
207
- hash: -1062239906783200272
208
+ hash: -2384325587943083337
208
209
  requirements: []
209
210
  rubyforge_project:
210
211
  rubygems_version: 1.8.24
@@ -213,22 +214,23 @@ specification_version: 3
213
214
  summary: No DSL, as little magic as possible. Write your DB migrations in SQL, and
214
215
  run them in the order specified by a plan file.
215
216
  test_files:
216
- - test/fixtures/basic_config.yml
217
- - test/fixtures/no_basedir_config.yml
218
- - test/fixtures/no_basedir_user_config.yml
219
- - test/fixtures/no_connection_string_config.yml
220
- - test/fixtures/no_migrations_dir_config.yml
221
- - test/fixtures/no_migrations_dir_user_config.yml
222
- - test/fixtures/no_migrations_table_config.yml
223
- - test/fixtures/no_planfile_config.yml
224
- - test/fixtures/no_planfile_user_config.yml
217
+ - test/fixtures/config/basic_config.yml
218
+ - test/fixtures/config/no_basedir_config.yml
219
+ - test/fixtures/config/no_basedir_user_config.yml
220
+ - test/fixtures/config/no_connection_string_config.yml
221
+ - test/fixtures/config/no_migrations_dir_config.yml
222
+ - test/fixtures/config/no_migrations_dir_user_config.yml
223
+ - test/fixtures/config/no_migrations_table_config.yml
224
+ - test/fixtures/config/no_planfile_config.yml
225
+ - test/fixtures/config/no_planfile_user_config.yml
226
+ - test/fixtures/config/overridden_config.yml
227
+ - test/fixtures/config/user_config.yml
225
228
  - test/fixtures/plan/basic.plan
226
229
  - test/fixtures/sql/migrations/basic/file1.sql
227
230
  - test/fixtures/sql/migrations/basic/file2.sql
228
231
  - test/fixtures/sql/migrations/basic/file3.sql
229
232
  - test/fixtures/sql/migrations/basic/file4.sql
230
233
  - test/fixtures/sql/migrations_table.sql
231
- - test/fixtures/user_config.yml
232
234
  - test/lib/hummingbird/configuration_test.rb
233
235
  - test/lib/hummingbird/database_test.rb
234
236
  - test/lib/hummingbird/plan_test.rb