kete-capistrano-configuration 0.1.2 → 0.2.0

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.
@@ -1,3 +1,10 @@
1
+ == 0.2.0 (March 9, 2009)
2
+
3
+ * Multi level configuration is now possible (when previously only one level was working)
4
+ * A to_file option can be passed to configure method to specify the location of the yml file (defaults to config directory)
5
+ * Raises to ensure methods are called in the right order
6
+ * Testing - Covers all the main parts of Capistrano Configuration so hopefully this release is pretty bug free
7
+
1
8
  == 0.1.2 (January 12, 2009)
2
9
 
3
10
  * Fixing configuration writing issue
data/Manifest CHANGED
@@ -6,3 +6,4 @@ Manifest
6
6
  MIT-LICENSE
7
7
  Rakefile
8
8
  README.rdoc
9
+ test/capistrano_configuration_test.rb
@@ -42,22 +42,6 @@ that method has an alias called 'context' which you can use to do the
42
42
  same thing.
43
43
 
44
44
 
45
- == Issues
46
-
47
- The gem currently only supports one environment level, that is, code
48
- like this won't work:
49
-
50
- configure :database do
51
- environment :test do
52
- environment :remote do
53
- config 'username', 'app'
54
- end
55
- end
56
- end
57
-
58
- This feature (nested environments) is planned for a future version.
59
-
60
-
61
45
  == Bug and Feature Requests
62
46
 
63
47
  You can report bugs and request features / submit patches at our Lighthouse account
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
1
5
  namespace :gem do
2
6
 
3
- task :default => :build
7
+ task :default => ['gem:build', 'gem:install']
4
8
 
5
9
  desc 'Build the Capistrano Configuration Gem'
6
10
  task :build do
@@ -13,9 +17,25 @@ namespace :gem do
13
17
  desc 'Install the Capistrano Configuration Gem'
14
18
  task :install do
15
19
  gem_filename = Dir['*.gem'].first
16
- sh "sudo gem install --local #{gem_filename}"
20
+ sh "sudo gem install #{gem_filename}"
17
21
  end
18
22
 
19
23
  end
20
24
 
21
- task :default => ['gem:build', 'gem:install']
25
+ task :gem => ['gem:build', 'gem:install']
26
+
27
+ desc 'Test Capistrano Configuration Gem'
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = true
31
+ end
32
+
33
+ task :default do
34
+ puts "----"
35
+ puts " rake - This menu"
36
+ puts " rake test - Test the gem"
37
+ puts " rake gem - Build and install gem"
38
+ puts " rake gem:build - Build gem"
39
+ puts " rake gem:install - Install gem"
40
+ puts "----"
41
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "capistrano-configuration"
5
- s.version = "0.1.2"
6
- s.date = "2009-01-12"
5
+ s.version = "0.2.0"
6
+ s.date = "2009-03-09"
7
7
  s.author = "Kieran Pilkington"
8
8
  s.email = "kieran@katipo.co.nz"
9
9
  s.homepage = "http://github.com/kete/capistrano-configuration"
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
17
17
  Manifest
18
18
  MIT-LICENSE
19
19
  Rakefile
20
- README.rdoc }
20
+ README.rdoc
21
+ test/capistrano_configuration_test.rb }
21
22
  s.has_rdoc = true
22
23
  s.extra_rdoc_files = %w{ CHANGELOG.rdoc
23
24
  MIT-LICENSE
24
25
  README.rdoc }
25
26
  s.rdoc_options = ["--line-numbers",
26
- "--inline-source",
27
27
  "--title",
28
28
  "capistrano-configuration",
29
29
  "--main",
@@ -5,29 +5,45 @@ end
5
5
  module CapistranoConfiguration
6
6
  unless included_modules.include? CapistranoConfiguration
7
7
 
8
+ class CapistranoConfigurationError < Exception; end
9
+
10
+ @@current_config = nil
8
11
  @@configurations = Hash.new
9
- @@current_config = String.new
10
- @@current_env = String.new
12
+ @@locations = Hash.new
13
+ @@current_envs = Array.new
14
+ @@original_envs = Array.new
11
15
 
12
- def configure(config)
13
- @@current_config = config
16
+ def configure(config, options={})
17
+ raise CapistranoConfigurationError.new("You cannot call configure without first closing an already existing configure.") unless @@current_config.nil?
18
+ raise CapistranoConfigurationError.new("Configure is designed to work with a block. Please pass it one.") unless block_given?
19
+ @@current_config = config.to_sym
14
20
  @@configurations[@@current_config] ||= Hash.new
21
+ @@locations[@@current_config] = options[:to_file] if options[:to_file]
15
22
  yield
23
+ @@current_config = nil
16
24
  end
17
25
 
18
26
  def environment(env)
19
- @@current_env = env
20
- @@configurations[@@current_config][@@current_env] ||= Hash.new
27
+ raise CapistranoConfigurationError.new("You cannot call environment without wrapping it inside a configure call.") if @@current_config.nil?
28
+ raise CapistranoConfigurationError.new("Environment is designed to work with a block. Please pass it one.") unless block_given?
29
+ current_level[env] ||= Hash.new
30
+ @@original_envs << @@current_envs.dup
31
+ @@current_envs << env
21
32
  yield
22
- @@current_env = nil
33
+ @@current_envs = @@original_envs.pop
23
34
  end
24
35
  alias :context :environment
25
36
 
26
37
  def config(setting, value)
27
- if @@current_env.nil?
28
- @@configurations[@@current_config][setting] = value
38
+ raise CapistranoConfigurationError.new("You cannot call config without wrapping it inside a configure or environment call.") if @@current_config.nil?
39
+ current_level[setting] = value
40
+ end
41
+
42
+ def file_path_for(configuration, default='.')
43
+ if @@locations[configuration.to_sym]
44
+ @@locations[configuration.to_sym]
29
45
  else
30
- @@configurations[@@current_config][@@current_env][setting] = value
46
+ "#{default}/#{configuration}.yml"
31
47
  end
32
48
  end
33
49
 
@@ -40,20 +56,28 @@ module CapistranoConfiguration
40
56
  desc 'Write the configuration files based on whats in @@configurations'
41
57
  task :write, :role => :app do
42
58
  abort "@@configurations is empty. Did you forget to define some configurations?" if @@configurations.empty?
43
- @@configurations.each do |file, value|
44
- run "cd #{current_path} && rm -rf config/#{file}.yml"
45
- put value.to_yaml, "#{current_path}/config/#{file}.yml"
59
+ @@configurations.each do |configuration, value|
60
+ file_path = file_path_for(configuration, "#{current_path}/config")
61
+ run "cd #{current_path} && rm -rf #{file_path}"
62
+ put value.to_yaml, file_path
46
63
  end
47
64
  end
48
65
 
49
66
  end
50
67
 
51
68
  end
52
-
69
+
53
70
  after "deploy:symlink", "deploy:configuration:write"
54
71
 
55
72
  end
56
73
 
74
+ private
75
+
76
+ def current_level
77
+ env_string = @@current_envs.collect { |env| env.is_a?(String) ? "['#{env}']" : "[:#{env}]" }.join('')
78
+ eval("@@configurations[@@current_config]#{env_string}")
79
+ end
80
+
57
81
  end
58
82
  end
59
83
 
@@ -0,0 +1,279 @@
1
+ require 'test/unit'
2
+
3
+ # Mock Capistrano modules/methods.
4
+ # We don't need to test them (capistrano does that)
5
+ module Capistrano
6
+ class Configuration
7
+ def self.instance; self; end
8
+ def self.load(&block); end
9
+ end
10
+ end
11
+
12
+ require File.dirname(__FILE__) + "/../lib/capistrano-configuration"
13
+
14
+ class CapistranoConfigurationTest < Test::Unit::TestCase
15
+
16
+ include CapistranoConfiguration
17
+
18
+ def setup
19
+ @@current_config = nil
20
+ @@configurations = Hash.new
21
+ @@locations = Hash.new
22
+ @@current_envs = Array.new
23
+ @@original_envs = Array.new
24
+ end
25
+
26
+ def test_configure_cannot_be_used_within_itself
27
+ assert_raise CapistranoConfigurationError do
28
+ configure :test do
29
+ configure :this
30
+ end
31
+ end
32
+ end
33
+
34
+ def test_environment_cannot_be_used_on_its_own
35
+ assert_raise CapistranoConfigurationError do
36
+ environment :test
37
+ end
38
+ end
39
+
40
+ def test_config_cannot_be_used_on_its_own
41
+ assert_raise CapistranoConfigurationError do
42
+ config :key, :value
43
+ end
44
+ end
45
+
46
+ def test_configure_requires_a_block
47
+ assert_raise CapistranoConfigurationError do
48
+ configure :test
49
+ end
50
+ end
51
+
52
+ def test_environment_requires_a_block
53
+ assert_raise CapistranoConfigurationError do
54
+ configure :test do
55
+ environment :test
56
+ end
57
+ end
58
+ end
59
+
60
+ def test_configure_stores_correct_settings
61
+ configure :test do
62
+ assert_equal :test, @@current_config
63
+ end
64
+ assert_equal({ :test => {} }, @@configurations)
65
+ assert_equal nil, @@current_config
66
+ end
67
+
68
+ def test_configure_stores_symbols
69
+ configure 'test' do
70
+ assert_equal :test, @@current_config
71
+ end
72
+ end
73
+
74
+ def test_config_within_an_configure
75
+ configure :test do
76
+ config 'key', 'value'
77
+ end
78
+ assert_equal({ :test => { 'key' => 'value' } }, @@configurations)
79
+ end
80
+
81
+ def test_config_within_an_environment_within_an_configure
82
+ configure :test do
83
+ environment :test do
84
+ config 'key', 'value'
85
+ end
86
+ end
87
+ assert_equal({ :test => { :test => { 'key' => 'value' } } }, @@configurations)
88
+ end
89
+
90
+ def test_config_within_two_environments_within_an_configure
91
+ configure :test do
92
+ environment :test do
93
+ environment :test do
94
+ config 'key', 'value'
95
+ end
96
+ end
97
+ end
98
+ assert_equal({ :test => { :test => { :test => { 'key' => 'value' } } } }, @@configurations)
99
+ end
100
+
101
+ def test_config_within_different_environments_within_a_configure
102
+ configure :test do
103
+ environment :test1 do
104
+ config 'key', 'value'
105
+ end
106
+ environment :test2 do
107
+ config 'key', 'value'
108
+ end
109
+ end
110
+ assert_equal({ :test => { :test1 => { 'key' => 'value' },
111
+ :test2 => { 'key' => 'value' } } }, @@configurations)
112
+ end
113
+
114
+ def test_config_within_different_environments_within_an_environment_within_an_configure
115
+ configure :test do
116
+ environment :test1 do
117
+ environment :test2 do
118
+ config 'key', 'value'
119
+ end
120
+ environment :test3 do
121
+ config 'key', 'value'
122
+ end
123
+ end
124
+ end
125
+ assert_equal({ :test => { :test1 => { :test2 => { 'key' => 'value' },
126
+ :test3 => { 'key' => 'value' } } } }, @@configurations)
127
+ end
128
+
129
+ def test_complex_nesting_with_multiple_environments_and_configurations
130
+ configure :test do
131
+ environment :test1 do
132
+ environment :test2 do
133
+ config 'key', 'value'
134
+ environment :test3 do
135
+ config 'key', 'value'
136
+ environment :test4 do
137
+ config 'key', 'value'
138
+ end
139
+ environment :test5 do
140
+ config 'key', 'value'
141
+ environment :test6 do
142
+ config 'key', 'value'
143
+ end
144
+ end
145
+ end
146
+ end
147
+ environment :test7 do
148
+ config 'key', 'value'
149
+ end
150
+ end
151
+ end
152
+ assert_equal({
153
+ :test => {
154
+ :test1 => {
155
+ :test2 => {
156
+ "key"=>"value",
157
+ :test3 => {
158
+ "key"=>"value",
159
+ :test4 => { "key"=>"value" },
160
+ :test5 => {
161
+ "key"=>"value",
162
+ :test6 => { "key"=>"value" }
163
+ }
164
+ }
165
+ },
166
+ :test7 => { "key"=>"value" }
167
+ }
168
+ }
169
+ }, @@configurations)
170
+ end
171
+
172
+ def test_normal_usage_of_capistrano_configuration
173
+ configure :database do
174
+ environment 'development' do
175
+ config 'adapter', 'mysql'
176
+ config 'database', 'test'
177
+ config 'username', 'test'
178
+ config 'password', 'test'
179
+ config 'host', 'localhost'
180
+ end
181
+ environment 'production' do
182
+ config 'adapter', 'mysql'
183
+ config 'database', 'test'
184
+ config 'username', 'test'
185
+ config 'password', 'test'
186
+ config 'host', 'localhost'
187
+ end
188
+ environment 'test' do
189
+ config 'adapter', 'mysql'
190
+ config 'database', 'test'
191
+ config 'username', 'test'
192
+ config 'password', 'test'
193
+ config 'host', 'localhost'
194
+ end
195
+ end
196
+ configure :backgroundrb do
197
+ context :backgroundrb do
198
+ config :port, 5000
199
+ config :ip, '127.0.0.1'
200
+ config :environment, 'production'
201
+ config :result_storage, 'memcache'
202
+ config :persistent_disabled, true
203
+ end
204
+ config :memcache, "127.0.0.1:11211"
205
+ end
206
+ configure :google_map_api do
207
+ context :google_map_api do
208
+ config :api_key, 'google-key'
209
+ config :default_latitude, 1.2345
210
+ config :default_longitude, 1.2345
211
+ config :default_zoom_lvl, 2
212
+ end
213
+ end
214
+ configure :site_lockdown_auth_credentials do
215
+ config 'username', 'username'
216
+ config 'password', 'password'
217
+ end
218
+
219
+ assert_equal({
220
+ :database => {
221
+ "development" => {
222
+ "username"=>"test",
223
+ "adapter"=>"mysql",
224
+ "host"=>"localhost",
225
+ "password"=>"test",
226
+ "database"=>"test"
227
+ },
228
+ "test" => {
229
+ "username"=>"test",
230
+ "adapter"=>"mysql",
231
+ "host"=>"localhost",
232
+ "password"=>"test",
233
+ "database"=>"test"
234
+ },
235
+ "production" => {
236
+ "username"=>"test",
237
+ "adapter"=>"mysql",
238
+ "host"=>"localhost",
239
+ "password"=>"test",
240
+ "database"=>"test"
241
+ }
242
+ },
243
+ :backgroundrb => {
244
+ :backgroundrb => {
245
+ :port=>5000,
246
+ :ip=>"127.0.0.1",
247
+ :result_storage=>"memcache",
248
+ :persistent_disabled=>true,
249
+ :environment=>"production"
250
+ },
251
+ :memcache=>"127.0.0.1:11211"
252
+ },
253
+ :google_map_api => {
254
+ :google_map_api => {
255
+ :api_key=>"google-key",
256
+ :default_latitude=>1.2345,
257
+ :default_longitude=>1.2345,
258
+ :default_zoom_lvl=>2
259
+ }
260
+ },
261
+ :site_lockdown_auth_credentials => {
262
+ "username" => "username",
263
+ "password" => "password"
264
+ }
265
+ }, @@configurations)
266
+ end
267
+
268
+ def test_file_path_for
269
+ configure :test1 do; end
270
+ configure :test2, :to_file => '/etc/configs/test2.yml' do; end
271
+ configure :test3, :to_file => '/etc/configs/test3.yml' do; end
272
+
273
+ assert_equal "./test1.yml", file_path_for(:test1)
274
+ assert_equal "/etc/configs/test1.yml", file_path_for(:test1, '/etc/configs')
275
+ assert_equal "/etc/configs/test2.yml", file_path_for(:test2)
276
+ assert_equal "/etc/configs/test3.yml", file_path_for(:test3)
277
+ end
278
+
279
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kete-capistrano-configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Pilkington
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-12 00:00:00 -08:00
12
+ date: 2009-03-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capistrano
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -40,12 +41,12 @@ files:
40
41
  - MIT-LICENSE
41
42
  - Rakefile
42
43
  - README.rdoc
44
+ - test/capistrano_configuration_test.rb
43
45
  has_rdoc: true
44
46
  homepage: http://github.com/kete/capistrano-configuration
45
47
  post_install_message:
46
48
  rdoc_options:
47
49
  - --line-numbers
48
- - --inline-source
49
50
  - --title
50
51
  - capistrano-configuration
51
52
  - --main