cape 1.6.2 → 1.7.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/Gemfile +7 -6
- data/Guardfile +29 -10
- data/History.markdown +4 -0
- data/README.markdown +38 -9
- data/Rakefile +35 -8
- data/features/dsl/each_rake_task/{without_arguments.feature → unqualified.feature} +16 -37
- data/features/dsl/each_rake_task/{with_defined_namespace_argument.feature → with_defined_namespace.feature} +2 -13
- data/features/dsl/each_rake_task/{with_defined_task_argument.feature → with_defined_task.feature} +2 -6
- data/features/dsl/each_rake_task/with_undefined_task_or_namespace.feature +24 -0
- data/features/dsl/mirror_rake_tasks/inside_capistrano_namespace.feature +2 -2
- data/features/dsl/mirror_rake_tasks/{without_arguments.feature → unqualified.feature} +15 -11
- data/features/dsl/mirror_rake_tasks/with_cd.feature +63 -0
- data/features/dsl/mirror_rake_tasks/with_cd_and_environment_variables.feature +27 -0
- data/features/dsl/mirror_rake_tasks/{with_defined_namespace_argument.feature → with_defined_namespace.feature} +6 -8
- data/features/dsl/mirror_rake_tasks/{with_defined_task_argument.feature → with_defined_task.feature} +4 -4
- data/features/dsl/mirror_rake_tasks/{with_defined_task_argument_and_environment_variables.feature → with_defined_task_and_cd.feature} +8 -8
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_cd_and_environment_variables.feature +46 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_environment_variables.feature +92 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename.feature +47 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_cd.feature +49 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_cd_and_environment_variables.feature +52 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_environment_variables.feature +50 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options.feature +49 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_cd.feature +51 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_cd_and_environment_variables.feature +54 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_environment_variables.feature +52 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options.feature +53 -6
- data/features/dsl/mirror_rake_tasks/{with_defined_task_and_valid_options_arguments_and_environment_variables.feature → with_defined_task_and_valid_options_and_cd.feature} +10 -8
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_cd_and_environment_variables.feature +48 -0
- data/features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_environment_variables.feature +98 -0
- data/features/dsl/mirror_rake_tasks/with_environment_variables.feature +61 -4
- data/features/dsl/mirror_rake_tasks/with_rename.feature +27 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_cd.feature +28 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_cd_and_environment_variables.feature +30 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_environment_variables.feature +29 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_valid_options.feature +28 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_cd.feature +29 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_cd_and_environment_variables.feature +31 -0
- data/features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_environment_variables.feature +30 -0
- data/features/dsl/mirror_rake_tasks/{with_undefined_argument.feature → with_undefined_task_or_namespace.feature} +3 -4
- data/features/dsl/mirror_rake_tasks/with_valid_options.feature +46 -0
- data/features/dsl/mirror_rake_tasks/{with_valid_options_argument.feature → with_valid_options_and_cd.feature} +7 -5
- data/features/dsl/mirror_rake_tasks/with_valid_options_and_cd_and_environment_variables.feature +28 -0
- data/features/dsl/mirror_rake_tasks/with_valid_options_and_environment_variables.feature +51 -0
- data/features/dsl/rake_executable.feature +2 -2
- data/features/step_definitions.rb +40 -0
- data/lib/cape.rb +2 -0
- data/lib/cape/capistrano.rb +59 -32
- data/lib/cape/capistrano_deprecated.rb +165 -0
- data/lib/cape/core_ext.rb +2 -0
- data/lib/cape/deprecation.rb +12 -0
- data/lib/cape/deprecation/base.rb +59 -0
- data/lib/cape/deprecation/capistrano_deprecated_define_rake_wrapper.rb +168 -0
- data/lib/cape/deprecation/dsl_deprecated_mirror_rake_tasks.rb +145 -0
- data/lib/cape/dsl.rb +49 -60
- data/lib/cape/dsl_deprecated.rb +157 -0
- data/lib/cape/hash_list.rb +2 -0
- data/lib/cape/recipe_definition.rb +103 -0
- data/lib/cape/recipe_definition_deprecated.rb +41 -0
- data/lib/cape/util.rb +2 -0
- data/lib/cape/version.rb +1 -1
- data/lib/cape/xterm.rb +326 -0
- data/spec/cape/deprecation/base_sharedspec.rb +18 -0
- data/spec/cape/deprecation/capistrano_deprecated_define_rake_wrapper_spec.rb +157 -0
- data/spec/cape/deprecation/dsl_deprecated_mirror_rake_tasks_spec.rb +153 -0
- data/spec/cape/dsl_deprecated_spec.rb +307 -0
- data/spec/cape/dsl_spec.rb +10 -43
- data/spec/cape/recipe_definition_spec.rb +53 -0
- data/spec/cape/xterm_spec.rb +72 -0
- metadata +97 -28
- data/features/dsl/each_rake_task/with_undefined_argument.feature +0 -53
- data/features/dsl/mirror_rake_tasks/with_valid_options_arguments_and_environment_variables.feature +0 -26
data/lib/cape/core_ext.rb
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
::Dir.glob(::File.expand_path('../deprecation/*.rb', __FILE__)) do |f|
|
|
2
|
+
require "cape/deprecation/#{::File.basename f, '.rb'}"
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
module Cape
|
|
6
|
+
|
|
7
|
+
# Contains implementations of deprecation stream printers.
|
|
8
|
+
#
|
|
9
|
+
# @api private
|
|
10
|
+
module Deprecation; end
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'cape/xterm'
|
|
2
|
+
|
|
3
|
+
module Cape
|
|
4
|
+
|
|
5
|
+
module Deprecation
|
|
6
|
+
|
|
7
|
+
# Prints to a stream a message related to deprecated API usage.
|
|
8
|
+
#
|
|
9
|
+
# @abstract
|
|
10
|
+
class Base
|
|
11
|
+
|
|
12
|
+
# Sets the value of {#stream}.
|
|
13
|
+
#
|
|
14
|
+
# @param [IO] value a new value for {#stream}
|
|
15
|
+
#
|
|
16
|
+
# @return [IO] _value_
|
|
17
|
+
attr_writer :stream
|
|
18
|
+
|
|
19
|
+
# Formats {#message_content} for display.
|
|
20
|
+
#
|
|
21
|
+
# @return [String] the full message
|
|
22
|
+
def formatted_message
|
|
23
|
+
[].tap do |fragments|
|
|
24
|
+
fragments << XTerm.bold_and_foreground_red('*** DEPRECATED:')
|
|
25
|
+
fragments << ' '
|
|
26
|
+
fragments << XTerm.bold(message_content)
|
|
27
|
+
end.join
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Prepares a message based on deprecated API usage.
|
|
31
|
+
#
|
|
32
|
+
# @raise [NotImplementedError]
|
|
33
|
+
#
|
|
34
|
+
# @abstract
|
|
35
|
+
def message_content
|
|
36
|
+
raise ::NotImplementedError
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The stream to which deprecation messages are printed. Defaults to
|
|
40
|
+
# $stderr.
|
|
41
|
+
#
|
|
42
|
+
# @return [IO]
|
|
43
|
+
def stream
|
|
44
|
+
@stream ||= $stderr
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Writes {#formatted_message} to {#stream}.
|
|
48
|
+
#
|
|
49
|
+
# @return [Base] the object
|
|
50
|
+
def write_formatted_message_to_stream
|
|
51
|
+
stream.puts formatted_message
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
require 'cape/deprecation/base'
|
|
2
|
+
require 'cape/hash_list'
|
|
3
|
+
|
|
4
|
+
module Cape
|
|
5
|
+
|
|
6
|
+
module Deprecation
|
|
7
|
+
|
|
8
|
+
# Prints to a stream a message related to deprecated usage of
|
|
9
|
+
# {CapistranoDeprecated#define_rake_wrapper}.
|
|
10
|
+
class CapistranoDeprecatedDefineRakeWrapper < Base
|
|
11
|
+
|
|
12
|
+
# The _task_ argument to {CapistranoDeprecated#define_rake_wrapper}.
|
|
13
|
+
#
|
|
14
|
+
# @return [Symbol, String]
|
|
15
|
+
attr_accessor :task
|
|
16
|
+
|
|
17
|
+
# Environment variable names and values set in a call to
|
|
18
|
+
# {CapistranoDeprecated#define_rake_wrapper}.
|
|
19
|
+
#
|
|
20
|
+
# @return [HashList]
|
|
21
|
+
def env
|
|
22
|
+
@env ||= HashList.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Prepares a message based on deprecated usage of
|
|
26
|
+
# {CapistranoDeprecated#define_rake_wrapper}.
|
|
27
|
+
#
|
|
28
|
+
# @return [String] a deprecation message
|
|
29
|
+
def message_content
|
|
30
|
+
[].tap do |fragments|
|
|
31
|
+
fragments << message_content_actual
|
|
32
|
+
fragments << '. '
|
|
33
|
+
fragments << message_content_expected
|
|
34
|
+
end.join
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The _named_arguments_ argument to
|
|
38
|
+
# {CapistranoDeprecated#define_rake_wrapper}.
|
|
39
|
+
#
|
|
40
|
+
# @return [HashList]
|
|
41
|
+
def named_arguments
|
|
42
|
+
@named_arguments ||= HashList.new
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Sets the value of {#named_arguments}.
|
|
46
|
+
#
|
|
47
|
+
# @param [Hash] value a new value for {#named_arguments}
|
|
48
|
+
#
|
|
49
|
+
# @return [HashList] _value_
|
|
50
|
+
def named_arguments=(value)
|
|
51
|
+
@named_arguments = HashList.new(value)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def binding_named_arguments
|
|
57
|
+
named_arguments.select do |name, value|
|
|
58
|
+
name == :binding
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def message_content_env_actual
|
|
63
|
+
[].tap do |fragments|
|
|
64
|
+
env_entries = env.collect do |name, value|
|
|
65
|
+
"env[#{name.inspect}] = #{value.inspect}"
|
|
66
|
+
end
|
|
67
|
+
unless env_entries.empty?
|
|
68
|
+
fragments << ' { |env| '
|
|
69
|
+
fragments << env_entries.join('; ')
|
|
70
|
+
fragments << ' }'
|
|
71
|
+
end
|
|
72
|
+
end.join
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def message_content_options_and_env_expected
|
|
76
|
+
[].tap do |fragments|
|
|
77
|
+
unless named_arguments.empty? && env.empty?
|
|
78
|
+
fragments << ' { |recipes| '
|
|
79
|
+
|
|
80
|
+
options_entries = options.collect do |name, value|
|
|
81
|
+
"recipes.options[#{name.inspect}] = #{value.inspect}"
|
|
82
|
+
end
|
|
83
|
+
env_entries = env.collect do |name, value|
|
|
84
|
+
"recipes.env[#{name.inspect}] = #{value.inspect}"
|
|
85
|
+
end
|
|
86
|
+
fragments << (options_entries + env_entries).join('; ')
|
|
87
|
+
|
|
88
|
+
fragments << ' }'
|
|
89
|
+
end
|
|
90
|
+
end.join
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def message_content_actual
|
|
94
|
+
[].tap do |fragments|
|
|
95
|
+
fragments << '`'
|
|
96
|
+
fragments << message_content_method_name
|
|
97
|
+
fragments << message_content_task_and_named_arguments_actual
|
|
98
|
+
fragments << message_content_env_actual
|
|
99
|
+
fragments << '`'
|
|
100
|
+
end.join
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def message_content_expected
|
|
104
|
+
[].tap do |fragments|
|
|
105
|
+
fragments << 'Use this instead: '
|
|
106
|
+
fragments << '`'
|
|
107
|
+
fragments << message_content_method_name
|
|
108
|
+
fragments << message_content_task_and_named_arguments_expected
|
|
109
|
+
fragments << message_content_options_and_env_expected
|
|
110
|
+
fragments << '`'
|
|
111
|
+
end.join
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def message_content_method_name
|
|
115
|
+
'define_rake_wrapper'
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def message_content_task_and_named_arguments_actual
|
|
119
|
+
[].tap do |fragments|
|
|
120
|
+
arguments = []
|
|
121
|
+
arguments << task.inspect unless task.nil?
|
|
122
|
+
named_arguments_entries = named_arguments.collect do |name, value|
|
|
123
|
+
"#{name.inspect} => #{value.inspect}"
|
|
124
|
+
end
|
|
125
|
+
unless named_arguments_entries.empty?
|
|
126
|
+
arguments << named_arguments_entries.join(', ')
|
|
127
|
+
end
|
|
128
|
+
unless arguments.empty?
|
|
129
|
+
if env.empty?
|
|
130
|
+
fragments << " #{arguments.join ', '}"
|
|
131
|
+
else
|
|
132
|
+
fragments << "(#{arguments.join ', '})"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end.join
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def message_content_task_and_named_arguments_expected
|
|
139
|
+
[].tap do |fragments|
|
|
140
|
+
arguments = []
|
|
141
|
+
arguments << task.inspect unless task.nil?
|
|
142
|
+
binding_named_arguments_entries = binding_named_arguments.collect do |name, value|
|
|
143
|
+
"#{name.inspect} => #{value.inspect}"
|
|
144
|
+
end
|
|
145
|
+
unless binding_named_arguments_entries.empty?
|
|
146
|
+
arguments << binding_named_arguments_entries.join(', ')
|
|
147
|
+
end
|
|
148
|
+
unless arguments.empty?
|
|
149
|
+
if options.empty? && env.empty?
|
|
150
|
+
fragments << " #{arguments.join ', '}"
|
|
151
|
+
else
|
|
152
|
+
fragments << "(#{arguments.join ', '})"
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end.join
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def options
|
|
159
|
+
named_arguments.reject do |name, value|
|
|
160
|
+
name == :binding
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require 'cape/deprecation/base'
|
|
2
|
+
require 'cape/hash_list'
|
|
3
|
+
|
|
4
|
+
module Cape
|
|
5
|
+
|
|
6
|
+
module Deprecation
|
|
7
|
+
|
|
8
|
+
# Prints to a stream a message related to deprecated usage of
|
|
9
|
+
# {DSLDeprecated#mirror_rake_tasks}.
|
|
10
|
+
class DSLDeprecatedMirrorRakeTasks < Base
|
|
11
|
+
|
|
12
|
+
# The _task_expression_ argument to {DSLDeprecated#mirror_rake_tasks}.
|
|
13
|
+
#
|
|
14
|
+
# @return [Symbol, String]
|
|
15
|
+
attr_accessor :task_expression
|
|
16
|
+
|
|
17
|
+
# Environment variable names and values set in a call to
|
|
18
|
+
# {DSLDeprecated#mirror_rake_tasks}.
|
|
19
|
+
#
|
|
20
|
+
# @return [HashList]
|
|
21
|
+
def env
|
|
22
|
+
@env ||= HashList.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Prepares a message based on deprecated usage of
|
|
26
|
+
# {DSLDeprecated#mirror_rake_tasks}.
|
|
27
|
+
#
|
|
28
|
+
# @return [String] a deprecation message
|
|
29
|
+
def message_content
|
|
30
|
+
[].tap do |fragments|
|
|
31
|
+
fragments << message_content_actual
|
|
32
|
+
fragments << '. '
|
|
33
|
+
fragments << message_content_expected
|
|
34
|
+
end.join
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The _options_ argument to {DSLDeprecated#mirror_rake_tasks}.
|
|
38
|
+
#
|
|
39
|
+
# @return [HashList]
|
|
40
|
+
def options
|
|
41
|
+
@options ||= HashList.new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Sets the value of {#options}.
|
|
45
|
+
#
|
|
46
|
+
# @param [Hash] value a new value for {#options}
|
|
47
|
+
#
|
|
48
|
+
# @return [HashList] _value_
|
|
49
|
+
def options=(value)
|
|
50
|
+
@options = HashList.new(value)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def message_content_env_actual
|
|
56
|
+
[].tap do |fragments|
|
|
57
|
+
env_entries = env.collect do |name, value|
|
|
58
|
+
"env[#{name.inspect}] = #{value.inspect}"
|
|
59
|
+
end
|
|
60
|
+
unless env_entries.empty?
|
|
61
|
+
fragments << ' { |env| '
|
|
62
|
+
fragments << env_entries.join('; ')
|
|
63
|
+
fragments << ' }'
|
|
64
|
+
end
|
|
65
|
+
end.join
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def message_content_options_and_env_expected
|
|
69
|
+
[].tap do |fragments|
|
|
70
|
+
unless options.empty? && env.empty?
|
|
71
|
+
fragments << ' { |recipes| '
|
|
72
|
+
|
|
73
|
+
options_entries = options.collect do |name, value|
|
|
74
|
+
"recipes.options[#{name.inspect}] = #{value.inspect}"
|
|
75
|
+
end
|
|
76
|
+
env_entries = env.collect do |name, value|
|
|
77
|
+
"recipes.env[#{name.inspect}] = #{value.inspect}"
|
|
78
|
+
end
|
|
79
|
+
fragments << (options_entries + env_entries).join('; ')
|
|
80
|
+
|
|
81
|
+
fragments << ' }'
|
|
82
|
+
end
|
|
83
|
+
end.join
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def message_content_actual
|
|
87
|
+
[].tap do |fragments|
|
|
88
|
+
fragments << '`'
|
|
89
|
+
fragments << message_content_method_name
|
|
90
|
+
fragments << message_content_task_expression_and_options_actual
|
|
91
|
+
fragments << message_content_env_actual
|
|
92
|
+
fragments << '`'
|
|
93
|
+
end.join
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def message_content_expected
|
|
97
|
+
[].tap do |fragments|
|
|
98
|
+
fragments << 'Use this instead: '
|
|
99
|
+
fragments << '`'
|
|
100
|
+
fragments << message_content_method_name
|
|
101
|
+
fragments << message_content_task_expression_expected
|
|
102
|
+
fragments << message_content_options_and_env_expected
|
|
103
|
+
fragments << '`'
|
|
104
|
+
end.join
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def message_content_method_name
|
|
108
|
+
'mirror_rake_tasks'
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def message_content_task_expression_and_options_actual
|
|
112
|
+
[].tap do |fragments|
|
|
113
|
+
arguments = []
|
|
114
|
+
arguments << task_expression.inspect unless task_expression.nil?
|
|
115
|
+
options_entries = options.collect do |name, value|
|
|
116
|
+
"#{name.inspect} => #{value.inspect}"
|
|
117
|
+
end
|
|
118
|
+
arguments << options_entries.join(', ') unless options_entries.empty?
|
|
119
|
+
unless arguments.empty?
|
|
120
|
+
if env.empty?
|
|
121
|
+
fragments << " #{arguments.join ', '}"
|
|
122
|
+
else
|
|
123
|
+
fragments << "(#{arguments.join ', '})"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end.join
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def message_content_task_expression_expected
|
|
130
|
+
[].tap do |fragments|
|
|
131
|
+
unless task_expression.nil?
|
|
132
|
+
if options.empty? && env.empty?
|
|
133
|
+
fragments << " #{task_expression.inspect}"
|
|
134
|
+
else
|
|
135
|
+
fragments << "(#{task_expression.inspect})"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end.join
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
data/lib/cape/dsl.rb
CHANGED
|
@@ -92,59 +92,26 @@ module Cape
|
|
|
92
92
|
|
|
93
93
|
# Defines Rake tasks as Capistrano recipes.
|
|
94
94
|
#
|
|
95
|
-
# @
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
# @param [String, Symbol] task_expression the full name of a Rake task or
|
|
99
|
-
# namespace to filter
|
|
100
|
-
#
|
|
101
|
-
# @yield [env] a block that defines environment variables for the Rake
|
|
102
|
-
# task; optional
|
|
103
|
-
# @yieldparam [Hash] env the environment variables to set before executing
|
|
104
|
-
# the Rake task
|
|
105
|
-
#
|
|
106
|
-
# @return [DSL] the object
|
|
107
|
-
#
|
|
108
|
-
# @overload mirror_rake_tasks(capistrano_task_options={})
|
|
109
|
-
# Defines all Rake tasks as Capistrano recipes with options.
|
|
110
|
-
#
|
|
111
|
-
# @param [Hash] capistrano_task_options options to pass to the Capistrano
|
|
112
|
-
# +task+ method; optional
|
|
113
|
-
#
|
|
114
|
-
# @yield [env] a block that defines environment variables for the Rake
|
|
115
|
-
# task; optional
|
|
116
|
-
# @yieldparam [Hash] env the environment variables to set before executing
|
|
117
|
-
# the Rake task
|
|
118
|
-
#
|
|
119
|
-
# @return [DSL] the object
|
|
120
|
-
#
|
|
121
|
-
# @overload mirror_rake_tasks(task_expression, capistrano_task_options={})
|
|
122
|
-
# Defines specific Rake tasks as Capistrano recipes with options.
|
|
123
|
-
#
|
|
124
|
-
# @param [String, Symbol] task_expression the full name of a Rake
|
|
125
|
-
# task or namespace to
|
|
126
|
-
# filter
|
|
127
|
-
# @param [Hash] capistrano_task_options options to pass to the
|
|
128
|
-
# Capistrano +task+ method;
|
|
129
|
-
# optional
|
|
95
|
+
# @param [String, Symbol] task_expression the full name of a Rake task or
|
|
96
|
+
# namespace to filter
|
|
130
97
|
#
|
|
131
|
-
#
|
|
132
|
-
#
|
|
133
|
-
#
|
|
134
|
-
#
|
|
98
|
+
# @yield [recipes] a block that customizes the Capistrano recipe(s)
|
|
99
|
+
# generated for the Rake task(s); optional
|
|
100
|
+
# @yieldparam [RecipeDefinition] recipes an interface for customizing the
|
|
101
|
+
# Capistrano recipe(s) generated for
|
|
102
|
+
# the Rake task(s)
|
|
135
103
|
#
|
|
136
|
-
#
|
|
104
|
+
# @return [DSL] the object
|
|
137
105
|
#
|
|
138
106
|
# @note Any parameters that the Rake tasks have are integrated via environment variables, since Capistrano does not support recipe parameters per se.
|
|
139
107
|
#
|
|
140
|
-
# @see http://github.com/capistrano/capistrano/blob/master/lib/capistrano/configuration/actions/invocation.rb#L99-L144 Valid Capistrano ‘task’ method options
|
|
141
|
-
#
|
|
142
108
|
# @example Mirroring all Rake tasks
|
|
143
109
|
# # config/deploy.rb
|
|
144
110
|
#
|
|
145
111
|
# require 'cape'
|
|
146
112
|
#
|
|
147
113
|
# Cape do
|
|
114
|
+
# # Create Capistrano recipes for all Rake tasks.
|
|
148
115
|
# mirror_rake_tasks
|
|
149
116
|
# end
|
|
150
117
|
#
|
|
@@ -159,7 +126,7 @@ module Cape
|
|
|
159
126
|
# mirror_rake_tasks :foo
|
|
160
127
|
# end
|
|
161
128
|
#
|
|
162
|
-
# @example Mirroring Rake tasks that require Capistrano recipe options and/or environment variables
|
|
129
|
+
# @example Mirroring Rake tasks that require renaming, Capistrano recipe options, path switching, and/or environment variables
|
|
163
130
|
# # config/deploy.rb
|
|
164
131
|
#
|
|
165
132
|
# require 'cape'
|
|
@@ -167,13 +134,37 @@ module Cape
|
|
|
167
134
|
# Cape do
|
|
168
135
|
# # Display defined Rails routes on application server remote machines
|
|
169
136
|
# # only.
|
|
170
|
-
# mirror_rake_tasks :routes
|
|
137
|
+
# mirror_rake_tasks :routes do |recipes|
|
|
138
|
+
# recipes.options[:roles] = :app
|
|
139
|
+
# end
|
|
171
140
|
#
|
|
172
141
|
# # Execute database migration on application server remote machines
|
|
173
142
|
# # only, and set the 'RAILS_ENV' environment variable to the value of
|
|
174
143
|
# # the Capistrano variable 'rails_env'.
|
|
175
|
-
# mirror_rake_tasks 'db:migrate'
|
|
176
|
-
#
|
|
144
|
+
# mirror_rake_tasks 'db:migrate' do |recipes|
|
|
145
|
+
# recipes.options[:roles] = :app
|
|
146
|
+
# recipes.env['RAILS_ENV'] = lambda { rails_env }
|
|
147
|
+
# end
|
|
148
|
+
#
|
|
149
|
+
# # Support a Rake task that must be run on application server remote
|
|
150
|
+
# # machines only, and in the remote directory 'release_path' instead of
|
|
151
|
+
# # the default, 'current_path'.
|
|
152
|
+
# before 'deploy:symlink', :spec
|
|
153
|
+
# mirror_rake_tasks :spec do |recipes|
|
|
154
|
+
# recipes.cd { release_path }
|
|
155
|
+
# recipes.options[:roles] = :app
|
|
156
|
+
# end
|
|
157
|
+
#
|
|
158
|
+
# # Avoid collisions with the existing Ruby method #test, run tests on
|
|
159
|
+
# # application server remote machines only, and set the 'RAILS_ENV'
|
|
160
|
+
# # environment variable to the value of the Capistrano variable
|
|
161
|
+
# # 'rails_env'.
|
|
162
|
+
# mirror_rake_tasks :test do |recipes|
|
|
163
|
+
# recipes.rename do |rake_task_name|
|
|
164
|
+
# "#{rake_task_name}_task"
|
|
165
|
+
# end
|
|
166
|
+
# recipes.options[:roles] = :app
|
|
167
|
+
# recipes.env['RAILS_ENV'] = lambda { rails_env }
|
|
177
168
|
# end
|
|
178
169
|
# end
|
|
179
170
|
#
|
|
@@ -187,19 +178,9 @@ module Cape
|
|
|
187
178
|
# cape.mirror_rake_tasks
|
|
188
179
|
# end
|
|
189
180
|
# end
|
|
190
|
-
def mirror_rake_tasks(
|
|
191
|
-
arguments_count = arguments.length
|
|
192
|
-
options = arguments.last.is_a?(Hash) ? arguments.pop.dup : {}
|
|
193
|
-
unless arguments.length <= 1
|
|
194
|
-
raise ::ArgumentError,
|
|
195
|
-
("wrong number of arguments (#{arguments_count} for 0 or 1, " +
|
|
196
|
-
'plus an options hash)')
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
task_expression = arguments.first
|
|
200
|
-
options[:binding] = binding
|
|
181
|
+
def mirror_rake_tasks(task_expression=nil, &block)
|
|
201
182
|
rake.each_task task_expression do |t|
|
|
202
|
-
deployment_library.define_rake_wrapper(t,
|
|
183
|
+
deployment_library.define_rake_wrapper(t, :binding => binding, &block)
|
|
203
184
|
end
|
|
204
185
|
self
|
|
205
186
|
end
|
|
@@ -235,7 +216,7 @@ module Cape
|
|
|
235
216
|
|
|
236
217
|
# Returns an abstraction of the Rake installation and available tasks.
|
|
237
218
|
def rake
|
|
238
|
-
@rake ||=
|
|
219
|
+
@rake ||= new_rake
|
|
239
220
|
end
|
|
240
221
|
|
|
241
222
|
private
|
|
@@ -244,7 +225,15 @@ module Cape
|
|
|
244
225
|
return @deployment_library if @deployment_library
|
|
245
226
|
|
|
246
227
|
raise_unless_capistrano
|
|
247
|
-
@deployment_library =
|
|
228
|
+
@deployment_library = new_capistrano(:rake => rake)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def new_capistrano(*arguments)
|
|
232
|
+
Capistrano.new(*arguments)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def new_rake(*arguments)
|
|
236
|
+
Rake.new(*arguments)
|
|
248
237
|
end
|
|
249
238
|
|
|
250
239
|
def raise_unless_capistrano
|