capistrano-configuration 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.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,21 @@
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
+
8
+ == 0.1.2 (January 12, 2009)
9
+
10
+ * Fixing configuration writing issue
11
+ - Replacing 'echo >>' syntax with Capistrano's much less buggy 'put' command
12
+
13
+ == 0.1.1 (January 7, 2009)
14
+
15
+ * Fixing deployment issues
16
+ - Configuration write now happens after symlink, not code update (so current directory is present)
17
+ - YAML files were parsing incorrectly (would leave backslashes at the end of lines breaking format)
18
+
19
+ == 0.1.0 (January 6, 2009)
20
+
21
+ * Initial Release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kieran Pilkington
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,9 @@
1
+ capistrano-configuration.gemspec
2
+ CHANGELOG.rdoc
3
+ install.rb
4
+ lib/capistrano-configuration.rb
5
+ Manifest
6
+ MIT-LICENSE
7
+ Rakefile
8
+ README.rdoc
9
+ test/capistrano_configuration_test.rb
data/README.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = Capistrano Configuration
2
+
3
+ Capistrano Configuration allows you to create configurations on deployment,
4
+ so you don't have to worry about copy different yml files to the right place
5
+ (especially when you have multiple deploy stages in one repository)
6
+
7
+
8
+ == Installation
9
+
10
+ sudo gem install kete-capistrano-configuration --source=http://gems.github.com
11
+
12
+
13
+ == Usage
14
+
15
+ Simply add the following to your deploy.rb file:
16
+
17
+ require 'capistrano-configuration'
18
+
19
+ and then write your configurations in ruby like so:
20
+
21
+ configure :database do
22
+ environment 'development' do
23
+ config 'username', 'app'
24
+ config 'password', 'secret'
25
+ end
26
+ environment 'production' do
27
+ config 'username', 'app_production'
28
+ config 'password', 'secret_production'
29
+ end
30
+ end
31
+
32
+ configure :google_map_key do
33
+ config 'map_key', 'u232398b208x9830x30xb383'
34
+ end
35
+
36
+ The gem will take care of the rest. It stores your configurations,
37
+ and after the code is updated, it'll write the configurations needed
38
+ for things like migrations.
39
+
40
+ Note: The method name environment doesn't suit all configurations, so
41
+ that method has an alias called 'context' which you can use to do the
42
+ same thing.
43
+
44
+
45
+ == Bug and Feature Requests
46
+
47
+ You can report bugs and request features / submit patches at our Lighthouse account
48
+
49
+ http://kete.lighthouseapp.com/projects/23036-capistrano-configuration
50
+
51
+
52
+ == Credits
53
+
54
+ Gem created and maintained by Kieran Pilkington <kieran@katipo.co.nz>
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ namespace :gem do
6
+
7
+ task :default => ['gem:build', 'gem:install']
8
+
9
+ desc 'Build the Capistrano Configuration Gem'
10
+ task :build do
11
+ Dir['*.gem'].each do |gem_filename|
12
+ sh "rm -rf #{gem_filename}"
13
+ end
14
+ sh "gem build capistrano-configuration.gemspec"
15
+ end
16
+
17
+ desc 'Install the Capistrano Configuration Gem'
18
+ task :install do
19
+ gem_filename = Dir['*.gem'].first
20
+ sh "sudo gem install #{gem_filename}"
21
+ end
22
+
23
+ end
24
+
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
@@ -0,0 +1,34 @@
1
+ # Gem::Specification for capistrano-configuration
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "capistrano-configuration"
5
+ s.version = "0.2.0"
6
+ s.date = "2009-03-09"
7
+ s.author = "Kieran Pilkington"
8
+ s.email = "kieran@katipo.co.nz"
9
+ s.homepage = "http://github.com/kete/capistrano-configuration"
10
+ s.summary = "Configure your application on deployment"
11
+ s.description = "Write application configuration files on deployment with Ruby"
12
+ s.require_path = "lib"
13
+ s.files = %w{ capistrano-configuration.gemspec
14
+ CHANGELOG.rdoc
15
+ install.rb
16
+ lib/capistrano-configuration.rb
17
+ Manifest
18
+ MIT-LICENSE
19
+ Rakefile
20
+ README.rdoc
21
+ test/capistrano_configuration_test.rb }
22
+ s.has_rdoc = true
23
+ s.extra_rdoc_files = %w{ CHANGELOG.rdoc
24
+ MIT-LICENSE
25
+ README.rdoc }
26
+ s.rdoc_options = ["--line-numbers",
27
+ "--title",
28
+ "capistrano-configuration",
29
+ "--main",
30
+ "README.rdoc"]
31
+ s.rubygems_version = "1.1.1"
32
+ s.add_dependency "capistrano", ">= 1.1.0"
33
+ s.rubyforge_project = "capistrano-conf"
34
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
@@ -0,0 +1,84 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "capistrano-configuration requires Capistrano 2"
3
+ end
4
+
5
+ module CapistranoConfiguration
6
+ unless included_modules.include? CapistranoConfiguration
7
+
8
+ class CapistranoConfigurationError < Exception; end
9
+
10
+ @@current_config = nil
11
+ @@configurations = Hash.new
12
+ @@locations = Hash.new
13
+ @@current_envs = Array.new
14
+ @@original_envs = Array.new
15
+
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
20
+ @@configurations[@@current_config] ||= Hash.new
21
+ @@locations[@@current_config] = options[:to_file] if options[:to_file]
22
+ yield
23
+ @@current_config = nil
24
+ end
25
+
26
+ def environment(env)
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
32
+ yield
33
+ @@current_envs = @@original_envs.pop
34
+ end
35
+ alias :context :environment
36
+
37
+ def 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]
45
+ else
46
+ "#{default}/#{configuration}.yml"
47
+ end
48
+ end
49
+
50
+ Capistrano::Configuration.instance.load do
51
+
52
+ namespace :deploy do
53
+
54
+ namespace :configuration do
55
+
56
+ desc 'Write the configuration files based on whats in @@configurations'
57
+ task :write, :role => :app do
58
+ abort "@@configurations is empty. Did you forget to define some configurations?" if @@configurations.empty?
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
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ after "deploy:symlink", "deploy:configuration:write"
71
+
72
+ end
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
+
81
+ end
82
+ end
83
+
84
+ Capistrano::Configuration.send(:include, CapistranoConfiguration)
@@ -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 ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-configuration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Kieran Pilkington
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-09 00:00:00 +13:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: capistrano
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.0
24
+ version:
25
+ description: Write application configuration files on deployment with Ruby
26
+ email: kieran@katipo.co.nz
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - CHANGELOG.rdoc
33
+ - MIT-LICENSE
34
+ - README.rdoc
35
+ files:
36
+ - capistrano-configuration.gemspec
37
+ - CHANGELOG.rdoc
38
+ - install.rb
39
+ - lib/capistrano-configuration.rb
40
+ - Manifest
41
+ - MIT-LICENSE
42
+ - Rakefile
43
+ - README.rdoc
44
+ - test/capistrano_configuration_test.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/kete/capistrano-configuration
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --line-numbers
52
+ - --title
53
+ - capistrano-configuration
54
+ - --main
55
+ - README.rdoc
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: capistrano-conf
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Configure your application on deployment
77
+ test_files: []
78
+