cape 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +7 -0
  4. data/.yardopts +1 -0
  5. data/Gemfile +18 -0
  6. data/History.markdown +7 -0
  7. data/MIT-LICENSE.markdown +10 -0
  8. data/README.markdown +157 -0
  9. data/Rakefile +49 -0
  10. data/cape.gemspec +36 -0
  11. data/features/dsl/each_rake_task/with_defined_namespace_argument.feature +43 -0
  12. data/features/dsl/each_rake_task/with_defined_task_argument.feature +37 -0
  13. data/features/dsl/each_rake_task/with_undefined_argument.feature +31 -0
  14. data/features/dsl/each_rake_task/without_arguments.feature +81 -0
  15. data/features/dsl/mirror_rake_tasks/inside_capistrano_namespace/with_defined_namespace_argument.feature +93 -0
  16. data/features/dsl/mirror_rake_tasks/inside_capistrano_namespace/with_defined_task_argument.feature +66 -0
  17. data/features/dsl/mirror_rake_tasks/inside_capistrano_namespace/with_undefined_argument.feature +39 -0
  18. data/features/dsl/mirror_rake_tasks/inside_capistrano_namespace/without_arguments.feature +263 -0
  19. data/features/dsl/mirror_rake_tasks/with_defined_namespace_argument.feature +85 -0
  20. data/features/dsl/mirror_rake_tasks/with_defined_task_argument.feature +60 -0
  21. data/features/dsl/mirror_rake_tasks/with_undefined_argument.feature +35 -0
  22. data/features/dsl/mirror_rake_tasks/without_arguments.feature +243 -0
  23. data/features/step_definitions.rb +33 -0
  24. data/features/support/env.rb +1 -0
  25. data/features/task_invocation/nonparameterized.feature +69 -0
  26. data/features/task_invocation/parameterized.feature +70 -0
  27. data/lib/cape.rb +22 -0
  28. data/lib/cape/capistrano.rb +86 -0
  29. data/lib/cape/core_ext.rb +10 -0
  30. data/lib/cape/core_ext/hash.rb +24 -0
  31. data/lib/cape/core_ext/symbol.rb +25 -0
  32. data/lib/cape/dsl.rb +81 -0
  33. data/lib/cape/rake.rb +60 -0
  34. data/lib/cape/strings.rb +25 -0
  35. data/lib/cape/version.rb +6 -0
  36. data/spec/cape/capistrano_spec.rb +0 -0
  37. data/spec/cape/core_ext/hash_spec.rb +12 -0
  38. data/spec/cape/core_ext/symbol_spec.rb +7 -0
  39. data/spec/cape/dsl_spec.rb +128 -0
  40. data/spec/cape/rake_spec.rb +0 -0
  41. data/spec/cape/strings_spec.rb +44 -0
  42. data/spec/cape/task_spec.rb +0 -0
  43. data/spec/cape/version_spec.rb +6 -0
  44. data/spec/cape_spec.rb +5 -0
  45. metadata +192 -0
File without changes
@@ -0,0 +1,6 @@
1
+ .bundle
2
+ .rvmrc
3
+ .yardoc
4
+ Gemfile.lock
5
+ doc
6
+ pkg
@@ -0,0 +1,7 @@
1
+ bundler_args: --without development
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
7
+ script: "bundle exec rake test"
@@ -0,0 +1 @@
1
+ --file MIT-LICENSE.markdown --file History.markdown --no-private --protected --title "Cape"
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'jruby-openssl', :platforms => :jruby
6
+
7
+ group :development do
8
+ gem 'ruby-debug', :platforms => :mri_18
9
+
10
+ # This is a dependency of ruby-debug. We're specifying it here because its
11
+ # v0.45 is incompatible with Ruby v1.8.7.
12
+ gem 'linecache', '<= 0.43', :platforms => :mri_18
13
+
14
+ gem 'ruby-debug19', :platforms => :mri_19
15
+
16
+ gem 'yard', :platforms => [:ruby, :mswin, :mingw]
17
+ gem 'rdiscount', :platforms => [:ruby, :mswin, :mingw]
18
+ end
@@ -0,0 +1,7 @@
1
+ Version history for the _Cape_ project
2
+ ======================================
3
+
4
+ <a name="v1.0.0"></a>v1.0.0, Mon 11/28/2011
5
+ -------------------------------------------
6
+
7
+ (First release)
@@ -0,0 +1,10 @@
1
+ The MIT License
2
+ ===============
3
+
4
+ Source code for _Cape_ is Copyright © 2011 [Nils Jonsson](mailto:cape@nilsjonsson.com) and [contributors](http://github.com/njonsson/cape/contributors "Cape contributors at GitHub").
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,157 @@
1
+ _____ __
2
+ / ___/___ / /_ __ _____ __ ______
3
+ / (_ // -_) __/ / // / _ | // / __/
4
+ \___/ \__/\__/ \_, /\___|_,_/_/
5
+ '-(+++++... /___/ ............ s++++++++.
6
+ .(++++++++++++( -+++~~~~~ 'N++++++++++= B++++++++s
7
+ '+++++++++++++++( DN=++++++< -NB+++++++++s Bz++++++++
8
+ +++++++++++++++++. 'NNN=++++++(-BNB+++++++++'BN========-
9
+ =B=+++++++++sDBBBBs<. +NNNN=+++++(<NNNBDBDBNNNNDBNNBBBBBBBz
10
+ 'NN+s+++++=BBBh=+((+sB=DNNNNNBBBNNDhNNNN' .. -BNs (z
11
+ sN+N+z+++sBs- .hNNNNBNh(-' NNNN. .NB- <Ns +BBBz
12
+ D+N+N+z=Bs. .~. 'NNNNNB~ DNNN .NN+ (Ns =B+~
13
+ BN+N+NNB+ ~NBD BNNNBN h' hNNN .Bs< <Ns =Dz~
14
+ BNNNN+ND +BhB DNNNBz 'N~ sNNN 'ND' hNs -(z-
15
+ NNNNNNB( sDDN hNNNB( +N~ +NNN ..-<hBNs ~=h-
16
+ NNNNNNB- sDBN 'DNNNN. DN~ <BNN 'NNhs(NNs =NN-
17
+ NNNNNNB' zNNN(+sDNNBNNNz .NB( ~BNN 'D NNs =Bh~
18
+ NNNNNNN. zNNNBNBBNNNNNB( <NB~ 'BNB 'D <Bs =NNNN
19
+ NNNNNNN. zNNNNNNNNNNBNN. . .NDB -D hs N
20
+ NNNNNNN. zNNNNNhBNBN=+z +BN- NDB '(D <BhhhhhhhN
21
+ BNNNNNN. zNNNh=<~. h-s< D~D'.-~B<NBNBDs ''``
22
+ DNNNNNN. zNNN D-B-~(+B DNBDzs-`
23
+ sNNNNNN. zNNN B(NDhs=( ''`
24
+ (BNNNNN' zNDB ~D.
25
+ sNNNNB- +hsz h< O___
26
+ <NNNB( -=s' 'hz ___ ___ < s > \____
27
+ ~BNh .+B+ / _ \/ _ \ = \ /
28
+ ~Dz~. .~+zB=' \___/_//_/ / \ \__/
29
+ <hNNBNBh=(. / \ `
30
+ ..
31
+
32
+ Cape
33
+ ====
34
+
35
+ If
36
+
37
+ * **You use [Capistrano](http://capify.org)** to deploy your application, and
38
+ * **You have [Rake](http://rake.rubyforge.org) tasks you want to run remotely** — but you don’t want to hand-code Capistrano recipes for each Rake task —
39
+
40
+ Then
41
+
42
+ * **You can invoke [Cape](http://github.com/njonsson/cape)** to dynamically add Capistrano recipes for each of your application’s Rake tasks, and
43
+ * **You can run your Rake tasks on your deployed servers,** friction-free, and look like a superhero. _[cue fanfare]_
44
+
45
+ Features
46
+ --------
47
+
48
+ * **Mirror Rake tasks** as Capistrano recipes, optionally filtered by namespace or name
49
+ * **Embed Rake tasks** in a Capistrano namespace
50
+ * **Pass arguments** to Rake tasks by setting environment variables with the same names
51
+ * **Override the default executables** for local and remote Rake installations (`/usr/bin/env rake` is the default)
52
+ * **Enumerate Rake tasks** for your own purposes
53
+
54
+ Examples
55
+ --------
56
+
57
+ Assume we have the following _Rakefile_.
58
+
59
+ desc 'Rakes the leaves'
60
+ task :leaves do
61
+ # (Raking action goes here.)
62
+ end
63
+
64
+ desc 'Rakes and bags the leaves'
65
+ task :bag_leaves, [:paper_or_plastic] => :leaves do
66
+ # (Bagging action goes here.)
67
+ end
68
+
69
+ Rake lists these tasks in the expected fashion.
70
+
71
+ $ rake --tasks
72
+ rake bag_leaves[paper_or_plastic] # Rakes and bags the leaves
73
+ rake leaves # Rakes the leaves
74
+
75
+ Put the following in your _config/deploy.rb_. **Note that Cape statements must be executed within a `Cape` block.**
76
+
77
+ require 'cape'
78
+
79
+ Cape do
80
+ # Create Capistrano recipes for all Rake tasks.
81
+ mirror_rake_tasks
82
+ end
83
+
84
+ Now all your Rake tasks can be invoked as Capistrano recipes. Capistrano lists the recipes in the following fashion.
85
+
86
+ $ cap --tasks
87
+ cap deploy # Deploys your project.
88
+ ...
89
+ [other built-in Capistrano recipes]
90
+ ...
91
+ cap bag_leaves # Rakes and bags the leaves.
92
+ cap leaves # Rakes the leaves.
93
+ Some tasks were not listed, either because they have no description,
94
+ or because they are only used internally by other tasks. To see all
95
+ tasks, type `cap -vT'.
96
+
97
+ Extended help may be available for these tasks.
98
+ Type `cap -e taskname' to view it.
99
+
100
+ Let’s use Capistrano to view the unabbreviated description of a Rake task recipe, including instructions for how to pass arguments to it. Note that Rake task parameters are automatically converted to environment variables.
101
+
102
+ $ cap --explain bag_leaves
103
+ ------------------------------------------------------------
104
+ cap bag_leaves
105
+ ------------------------------------------------------------
106
+ Bags the leaves.
107
+
108
+ You must set environment variable PAPER_OR_PLASTIC.
109
+
110
+ Cape lets you filter the Rake tasks to be mirrored:
111
+
112
+ Cape do
113
+ # Create Capistrano recipes for the Rake task 'foo' or for the tasks in a
114
+ # 'foo' namespace.
115
+ mirror_rake_tasks :foo
116
+
117
+ # Create Capistrano recipes only for the Rake task 'bar:baz' or for the
118
+ # tasks in the 'bar:baz' namespace.
119
+ mirror_rake_tasks 'bar:baz'
120
+ end
121
+
122
+ Cape plays friendly with the Capistrano DSL for organizing Rake tasks in Capistrano namespaces.
123
+
124
+ # Use an argument with the Cape block, if you want to or need to.
125
+ namespace :rake_tasks do
126
+ Cape do |cape|
127
+ cape.mirror_rake_tasks
128
+ end
129
+ end
130
+
131
+ Cape lets you enumerate Rake tasks, optionally filtering them by task name or namespace.
132
+
133
+ Cape do
134
+ each_rake_task do |t|
135
+ # Do something interesting with this hash:
136
+ # * t[:name] -- the full name of the task
137
+ # * t[:parameters] -- the names of task arguments
138
+ # * t[:description] -- documentation on the task, including parameters
139
+ end
140
+ end
141
+
142
+ Limitations
143
+ -----------
144
+
145
+ For now, only Rake tasks that have descriptions can be mirrored or enumerated.
146
+
147
+ Contributing
148
+ ------------
149
+
150
+ Report defects and feature requests on [GitHub Issues](http://github.com/njonsson/cape/issues).
151
+
152
+ Your patches are welcome, and you will receive attribution here for good stuff.
153
+
154
+ License
155
+ -------
156
+
157
+ Released under the [MIT License](http://github.com/njonsson/cape/blob/master/MIT-LICENSE.markdown).
@@ -0,0 +1,49 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'cucumber'
3
+ require 'cucumber/rake/task'
4
+ require 'rspec/core/rake_task'
5
+
6
+ begin
7
+ require 'yard'
8
+ rescue LoadError
9
+ else
10
+ namespace :build do
11
+ YARD::Rake::YardocTask.new :doc
12
+ end
13
+ end
14
+
15
+ Cucumber::Rake::Task.new :features, 'Test features'
16
+
17
+ def define_spec_task(name, options={})
18
+ RSpec::Core::RakeTask.new name do |t|
19
+ t.rspec_opts = ['--color']
20
+ unless options[:debug] == false
21
+ begin
22
+ require 'ruby-debug'
23
+ rescue LoadError
24
+ else
25
+ t.rspec_opts << '--debug'
26
+ end
27
+ end
28
+ t.pattern = "spec/**/*_spec.rb"
29
+ end
30
+ end
31
+
32
+ desc 'Run all specs'
33
+ define_spec_task :spec
34
+
35
+ desc 'Run all specs and test features'
36
+ task '' => [:spec, :features]
37
+ task :default => [:spec, :features]
38
+
39
+ # Support the 'gem test' command.
40
+ namespace :test do
41
+ desc ''
42
+ define_spec_task :specs, :debug => false
43
+
44
+ Cucumber::Rake::Task.new :features, '' do |t|
45
+ t.bundler = false
46
+ t.cucumber_opts = '--backtrace'
47
+ end
48
+ end
49
+ task :test => %w(test:specs test:features)
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'cape/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'cape'
7
+ s.version = Cape::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Nils Jonsson']
10
+ s.email = %w(cape@nilsjonsson.com)
11
+ s.homepage = ''
12
+ s.summary = 'Dynamically generates Capistrano recipes for Rake tasks'
13
+ s.description = 'Cape provides a simple DSL for selecting Rake tasks to be ' +
14
+ 'made available as documented Capistrano recipes. You can ' +
15
+ 'pass required arguments to Rake tasks via environment ' +
16
+ 'variables.'
17
+ s.license = 'MIT'
18
+
19
+ # TODO: Apply for RubyForge project
20
+ # s.rubyforge_project = 'cape'
21
+
22
+ s.required_ruby_version = '>= 1.8.7'
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
27
+ File.basename f
28
+ end
29
+ s.require_paths = %w(lib)
30
+ s.has_rdoc = true
31
+
32
+ s.add_development_dependency 'aruba'
33
+ s.add_development_dependency 'capistrano'
34
+ s.add_development_dependency 'rake'
35
+ s.add_development_dependency 'rspec', '~> 2.7'
36
+ end
@@ -0,0 +1,43 @@
1
+ Feature: The #each_rake_task DSL method with an argument of a defined namespace
2
+
3
+ In order to use the metadata of Rake tasks in my Capistrano recipes,
4
+ As a developer using Cape,
5
+ I want to use the Cape DSL.
6
+
7
+ Scenario: enumerate only the Rake tasks in the matching namespace
8
+ Given a full-featured Rakefile
9
+ And a file named "Capfile" with:
10
+ """
11
+ require 'cape'
12
+
13
+ Cape do
14
+ each_rake_task :my_namespace do |t|
15
+ $stdout.puts '', "Name: #{t[:name].inspect}"
16
+ if t[:parameters]
17
+ $stdout.puts "Parameters: #{t[:parameters].inspect}"
18
+ end
19
+ if t[:description]
20
+ $stdout.puts "Description: #{t[:description].inspect}"
21
+ end
22
+ end
23
+ end
24
+ """
25
+ When I run `cap -T`
26
+ Then the output should not contain:
27
+ """
28
+
29
+ Name: "with_period"
30
+ Description: "Ends with period."
31
+ """
32
+ And the output should contain:
33
+ """
34
+
35
+ Name: "my_namespace:in_a_namespace"
36
+ Description: "My task in a namespace"
37
+ """
38
+ And the output should contain:
39
+ """
40
+
41
+ Name: "my_namespace:my_nested_namespace:in_a_nested_namespace"
42
+ Description: "My task in a nested namespace"
43
+ """
@@ -0,0 +1,37 @@
1
+ Feature: The #each_rake_task DSL method with an argument of a defined task
2
+
3
+ In order to use the metadata of Rake tasks in my Capistrano recipes,
4
+ As a developer using Cape,
5
+ I want to use the Cape DSL.
6
+
7
+ Scenario: enumerate only the matching Rake task
8
+ Given a full-featured Rakefile
9
+ And a file named "Capfile" with:
10
+ """
11
+ require 'cape'
12
+
13
+ Cape do
14
+ each_rake_task 'with_period' do |t|
15
+ $stdout.puts '', "Name: #{t[:name].inspect}"
16
+ if t[:parameters]
17
+ $stdout.puts "Parameters: #{t[:parameters].inspect}"
18
+ end
19
+ if t[:description]
20
+ $stdout.puts "Description: #{t[:description].inspect}"
21
+ end
22
+ end
23
+ end
24
+ """
25
+ When I run `cap -T`
26
+ Then the output should contain:
27
+ """
28
+
29
+ Name: "with_period"
30
+ Description: "Ends with period."
31
+ """
32
+ And the output should not contain:
33
+ """
34
+
35
+ Name: "without_period"
36
+ Description: "Ends without period"
37
+ """
@@ -0,0 +1,31 @@
1
+ Feature: The #each_rake_task DSL method with an undefined argument
2
+
3
+ In order to use the metadata of Rake tasks in my Capistrano recipes,
4
+ As a developer using Cape,
5
+ I want to use the Cape DSL.
6
+
7
+ Scenario: do not enumerate any Rake tasks
8
+ Given a full-featured Rakefile
9
+ And a file named "Capfile" with:
10
+ """
11
+ require 'cape'
12
+
13
+ Cape do
14
+ each_rake_task :this_does_not_exist do |t|
15
+ $stdout.puts '', "Name: #{t[:name].inspect}"
16
+ if t[:parameters]
17
+ $stdout.puts "Parameters: #{t[:parameters].inspect}"
18
+ end
19
+ if t[:description]
20
+ $stdout.puts "Description: #{t[:description].inspect}"
21
+ end
22
+ end
23
+ end
24
+ """
25
+ When I run `cap -T`
26
+ Then the output should not contain:
27
+ """
28
+
29
+ Name: "with_period"
30
+ Description: "Ends with period."
31
+ """
@@ -0,0 +1,81 @@
1
+ Feature: The #each_rake_task DSL method without arguments
2
+
3
+ In order to use the metadata of Rake tasks in my Capistrano recipes,
4
+ As a developer using Cape,
5
+ I want to use the Cape DSL.
6
+
7
+ Scenario: enumerate all non-hidden Rake tasks
8
+ Given a full-featured Rakefile
9
+ And a file named "Capfile" with:
10
+ """
11
+ require 'cape'
12
+
13
+ Cape do
14
+ each_rake_task do |t|
15
+ $stdout.puts '', "Name: #{t[:name].inspect}"
16
+ if t[:parameters]
17
+ $stdout.puts "Parameters: #{t[:parameters].inspect}"
18
+ end
19
+ if t[:description]
20
+ $stdout.puts "Description: #{t[:description].inspect}"
21
+ end
22
+ end
23
+ end
24
+ """
25
+ When I run `cap -T`
26
+ Then the output should contain:
27
+ """
28
+
29
+ Name: "with_period"
30
+ Description: "Ends with period."
31
+ """
32
+ And the output should contain:
33
+ """
34
+
35
+ Name: "without_period"
36
+ Description: "Ends without period"
37
+ """
38
+ And the output should contain:
39
+ """
40
+
41
+ Name: "long"
42
+ Description: "My long task -- it has a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long description"
43
+ """
44
+ And the output should contain:
45
+ """
46
+
47
+ Name: "with_one_arg"
48
+ Parameters: ["the_arg"]
49
+ Description: "My task with one argument"
50
+ """
51
+ And the output should contain:
52
+ """
53
+
54
+ Name: "my_namespace:in_a_namespace"
55
+ Description: "My task in a namespace"
56
+ """
57
+ And the output should contain:
58
+ """
59
+
60
+ Name: "my_namespace:my_nested_namespace:in_a_nested_namespace"
61
+ Description: "My task in a nested namespace"
62
+ """
63
+ And the output should contain:
64
+ """
65
+
66
+ Name: "with_two_args"
67
+ Parameters: ["my_arg1", "my_arg2"]
68
+ Description: "My task with two arguments"
69
+ """
70
+ And the output should contain:
71
+ """
72
+
73
+ Name: "with_three_args"
74
+ Parameters: ["an_arg1", "an_arg2", "an_arg3"]
75
+ Description: "My task with three arguments"
76
+ """
77
+ And the output should not contain:
78
+ """
79
+
80
+ Name: "hidden_task"
81
+ """