action_command 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +106 -1
- data/Rakefile +2 -0
- data/doc/ActionCommand/Executable.html +452 -29
- data/doc/ActionCommand/InputOutput.html +559 -158
- data/doc/ActionCommand/Result.html +321 -32
- data/doc/ActionCommand.html +319 -65
- data/doc/_index.html +16 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +101 -2
- data/doc/index.html +101 -2
- data/doc/method_list.html +118 -16
- data/doc/top-level-namespace.html +1 -1
- data/lib/action_command/executable.rb +75 -0
- data/lib/action_command/input_output.rb +149 -0
- data/lib/action_command/result.rb +76 -0
- data/lib/action_command/utils.rb +21 -0
- data/lib/action_command/version.rb +1 -1
- data/lib/action_command.rb +35 -186
- metadata +6 -2
data/doc/file.README.html
CHANGED
@@ -96,7 +96,106 @@ by others.</p>
|
|
96
96
|
|
97
97
|
<h2 id="label-Usage">Usage</h2>
|
98
98
|
|
99
|
-
<p>
|
99
|
+
<p><code>action_command</code> is designed to help you centralize logic which
|
100
|
+
might otherwise end up in a controller or model, and easily invoke it from
|
101
|
+
a controller, a test, or a rake command. I read placing logic in
|
102
|
+
'actions' rather than models in the book <a
|
103
|
+
href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222196">Rails
|
104
|
+
4 Test Prescriptions</a> and liked it.</p>
|
105
|
+
|
106
|
+
<h3 id="label-HelloWorld">HelloWorld</h3>
|
107
|
+
|
108
|
+
<p>You can declare an action with inputs and outputs</p>
|
109
|
+
|
110
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>HelloWorldCommand</span> <span class='op'><</span> <span class='const'>ActionCommand</span><span class='op'>::</span><span class='const'>Executable</span>
|
111
|
+
|
112
|
+
<span class='comment'># You need to declare an attr_accessor for each named parameter
|
113
|
+
</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:name</span>
|
114
|
+
|
115
|
+
<span class='comment'># You can optional describe the input and output of the command,
|
116
|
+
</span> <span class='comment'># the text is used to provide help if you create a rake version of the command.
|
117
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_describe_io'>describe_io</span>
|
118
|
+
<span class='comment'># the text in here is only
|
119
|
+
</span> <span class='kw'>return</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_describe_io'>describe_io</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Say hello to someone</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_io'>io</span><span class='op'>|</span>
|
120
|
+
<span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_input'>input</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Name of person to say hello to</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
121
|
+
<span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_output'>output</span><span class='lparen'>(</span><span class='symbol'>:greeting</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Greeting for the person</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
122
|
+
<span class='kw'>end</span>
|
123
|
+
<span class='kw'>end</span>
|
124
|
+
|
125
|
+
<span class='id identifier rubyid_protected'>protected</span>
|
126
|
+
|
127
|
+
<span class='comment'># Override the execute internal method to provide logic for your action, and
|
128
|
+
</span> <span class='comment'># assign results to the result. You can also use methods like result.fail or
|
129
|
+
</span> <span class='comment'># result.info.
|
130
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute_internal'>execute_internal</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
|
131
|
+
<span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='symbol'>:greeting</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Hello </span><span class='embexpr_beg'>#{</span><span class='ivar'>@name</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_no_output'>no_output</span>
|
132
|
+
<span class='kw'>end</span>
|
133
|
+
<span class='kw'>end</span>
|
134
|
+
</code></pre>
|
135
|
+
|
136
|
+
<h4 id="label-HelloWorld-3A+Execute+from+Rails">HelloWorld: Execute from Rails</h4>
|
137
|
+
|
138
|
+
<p>You can execute it from rails:</p>
|
139
|
+
|
140
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_execute_rails'>execute_rails</span><span class='lparen'>(</span><span class='const'>HelloWorldCommand</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Chris</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
141
|
+
</code></pre>
|
142
|
+
|
143
|
+
<h4 id="label-HelloWorld-3A+Execute+from+Rake">HelloWorld: Execute from Rake</h4>
|
144
|
+
|
145
|
+
<p>When building a system, I find it useful to be able to easily run my
|
146
|
+
actions from the command-line as well. In rails, you can create a
|
147
|
+
lib/tasks/my_rake.task, and configure your actions as task with one line:</p>
|
148
|
+
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_namespace'>namespace</span> <span class='symbol'>:my_namespace</span> <span class='kw'>do</span>
|
150
|
+
|
151
|
+
<span class='comment'># use [:initialize] as the last parameter if you want to do things that require
|
152
|
+
</span> <span class='comment'># rails startup in your command, like connecting to your database.
|
153
|
+
</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_install_rake'>install_rake</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='symbol'>:hello_world</span><span class='comma'>,</span> <span class='const'>HelloWorldCommand</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
154
|
+
|
155
|
+
<span class='kw'>end</span>
|
156
|
+
</code></pre>
|
157
|
+
|
158
|
+
<p>You can always invoke your rake task with [help] to see help on the input
|
159
|
+
and output of the action.</p>
|
160
|
+
|
161
|
+
<h4 id="label-HelloWorld-3A+Execute+from+rspec-2Fetc">HelloWorld: Execute from rspec/etc</h4>
|
162
|
+
|
163
|
+
<p>Or, you can execute it from a testing framework.</p>
|
164
|
+
|
165
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>says hello world</span><span class='tstring_end'>'</span></span> <span class='kw'>do</span>
|
166
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_execute_test'>execute_test</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='const'>HelloWorldCommand</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Chris</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
167
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_be_ok'>be_ok</span>
|
168
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='symbol'>:greeting</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Hello Chris</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
169
|
+
<span class='kw'>end</span>
|
170
|
+
</code></pre>
|
171
|
+
|
172
|
+
<p>If your command does a lot, you might like to do some internal
|
173
|
+
verifications during the testing process to aid debugging. Inside a
|
174
|
+
command's execute_internal method, you can use a block like this</p>
|
175
|
+
|
176
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>def</span> <span class='id identifier rubyid_execute_internal'>execute_internal</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
|
177
|
+
<span class='comment'># ... do some logic
|
178
|
+
</span>
|
179
|
+
<span class='comment'># t is the parameter you passed as the first argument to execute_test.
|
180
|
+
</span> <span class='comment'># so, if you are using rspec, this code block will only be executed when you are
|
181
|
+
</span> <span class='comment'># running in a testing context.
|
182
|
+
</span> <span class='id identifier rubyid_testing'>testing</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_t'>t</span><span class='op'>|</span>
|
183
|
+
<span class='id identifier rubyid_t'>t</span><span class='period'>.</span><span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='id identifier rubyid_my_val'>my_val</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_t'>t</span><span class='period'>.</span><span class='id identifier rubyid_eq'>eq</span><span class='lparen'>(</span><span class='int'>10</span><span class='rparen'>)</span>
|
184
|
+
<span class='kw'>end</span>
|
185
|
+
|
186
|
+
<span class='kw'>end</span>
|
187
|
+
|
188
|
+
<span class='comment'>### Child Actions
|
189
|
+
</span>
|
190
|
+
<span class='const'>Actions</span> <span class='id identifier rubyid_can'>can</span> <span class='id identifier rubyid_execute'>execute</span> <span class='id identifier rubyid_their'>their</span> <span class='id identifier rubyid_own'>own</span> <span class='id identifier rubyid_child'>child</span> <span class='id identifier rubyid_actions'>actions</span><span class='period'>.</span> <span class='const'>Within</span> <span class='id identifier rubyid_an'>an</span> <span class='id identifier rubyid_action'>action</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>s execute_internal method
|
191
|
+
</span></span></code></pre>
|
192
|
+
|
193
|
+
<p>ruby def execute_internal @names.each_with_index do |name, i| # the i
|
194
|
+
parameter will cause the result of the child command to be nested # in the
|
195
|
+
result under that value. For example, here I would expect # <a
|
196
|
+
href="i">result</a>[:greeting] to contain the greeting for each subcommand
|
197
|
+
after # execution. ActionCommand.execute_child(self, HelloWorldCommand,
|
198
|
+
result, i, name: name) end end “`</p>
|
100
199
|
|
101
200
|
<h2 id="label-Development">Development</h2>
|
102
201
|
|
@@ -128,7 +227,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
128
227
|
</div></div>
|
129
228
|
|
130
229
|
<div id="footer">
|
131
|
-
Generated on
|
230
|
+
Generated on Thu Mar 3 16:34:07 2016 by
|
132
231
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
133
232
|
0.8.7.6 (ruby-2.2.3).
|
134
233
|
</div>
|
data/doc/index.html
CHANGED
@@ -96,7 +96,106 @@ by others.</p>
|
|
96
96
|
|
97
97
|
<h2 id="label-Usage">Usage</h2>
|
98
98
|
|
99
|
-
<p>
|
99
|
+
<p><code>action_command</code> is designed to help you centralize logic which
|
100
|
+
might otherwise end up in a controller or model, and easily invoke it from
|
101
|
+
a controller, a test, or a rake command. I read placing logic in
|
102
|
+
'actions' rather than models in the book <a
|
103
|
+
href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222196">Rails
|
104
|
+
4 Test Prescriptions</a> and liked it.</p>
|
105
|
+
|
106
|
+
<h3 id="label-HelloWorld">HelloWorld</h3>
|
107
|
+
|
108
|
+
<p>You can declare an action with inputs and outputs</p>
|
109
|
+
|
110
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>HelloWorldCommand</span> <span class='op'><</span> <span class='const'>ActionCommand</span><span class='op'>::</span><span class='const'>Executable</span>
|
111
|
+
|
112
|
+
<span class='comment'># You need to declare an attr_accessor for each named parameter
|
113
|
+
</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:name</span>
|
114
|
+
|
115
|
+
<span class='comment'># You can optional describe the input and output of the command,
|
116
|
+
</span> <span class='comment'># the text is used to provide help if you create a rake version of the command.
|
117
|
+
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_describe_io'>describe_io</span>
|
118
|
+
<span class='comment'># the text in here is only
|
119
|
+
</span> <span class='kw'>return</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_describe_io'>describe_io</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Say hello to someone</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_io'>io</span><span class='op'>|</span>
|
120
|
+
<span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_input'>input</span><span class='lparen'>(</span><span class='symbol'>:name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Name of person to say hello to</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
121
|
+
<span class='id identifier rubyid_io'>io</span><span class='period'>.</span><span class='id identifier rubyid_output'>output</span><span class='lparen'>(</span><span class='symbol'>:greeting</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Greeting for the person</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
122
|
+
<span class='kw'>end</span>
|
123
|
+
<span class='kw'>end</span>
|
124
|
+
|
125
|
+
<span class='id identifier rubyid_protected'>protected</span>
|
126
|
+
|
127
|
+
<span class='comment'># Override the execute internal method to provide logic for your action, and
|
128
|
+
</span> <span class='comment'># assign results to the result. You can also use methods like result.fail or
|
129
|
+
</span> <span class='comment'># result.info.
|
130
|
+
</span> <span class='kw'>def</span> <span class='id identifier rubyid_execute_internal'>execute_internal</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
|
131
|
+
<span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='symbol'>:greeting</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Hello </span><span class='embexpr_beg'>#{</span><span class='ivar'>@name</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_no_output'>no_output</span>
|
132
|
+
<span class='kw'>end</span>
|
133
|
+
<span class='kw'>end</span>
|
134
|
+
</code></pre>
|
135
|
+
|
136
|
+
<h4 id="label-HelloWorld-3A+Execute+from+Rails">HelloWorld: Execute from Rails</h4>
|
137
|
+
|
138
|
+
<p>You can execute it from rails:</p>
|
139
|
+
|
140
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_execute_rails'>execute_rails</span><span class='lparen'>(</span><span class='const'>HelloWorldCommand</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Chris</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
141
|
+
</code></pre>
|
142
|
+
|
143
|
+
<h4 id="label-HelloWorld-3A+Execute+from+Rake">HelloWorld: Execute from Rake</h4>
|
144
|
+
|
145
|
+
<p>When building a system, I find it useful to be able to easily run my
|
146
|
+
actions from the command-line as well. In rails, you can create a
|
147
|
+
lib/tasks/my_rake.task, and configure your actions as task with one line:</p>
|
148
|
+
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_namespace'>namespace</span> <span class='symbol'>:my_namespace</span> <span class='kw'>do</span>
|
150
|
+
|
151
|
+
<span class='comment'># use [:initialize] as the last parameter if you want to do things that require
|
152
|
+
</span> <span class='comment'># rails startup in your command, like connecting to your database.
|
153
|
+
</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_install_rake'>install_rake</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='symbol'>:hello_world</span><span class='comma'>,</span> <span class='const'>HelloWorldCommand</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
154
|
+
|
155
|
+
<span class='kw'>end</span>
|
156
|
+
</code></pre>
|
157
|
+
|
158
|
+
<p>You can always invoke your rake task with [help] to see help on the input
|
159
|
+
and output of the action.</p>
|
160
|
+
|
161
|
+
<h4 id="label-HelloWorld-3A+Execute+from+rspec-2Fetc">HelloWorld: Execute from rspec/etc</h4>
|
162
|
+
|
163
|
+
<p>Or, you can execute it from a testing framework.</p>
|
164
|
+
|
165
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_it'>it</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>says hello world</span><span class='tstring_end'>'</span></span> <span class='kw'>do</span>
|
166
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_execute_test'>execute_test</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='const'>HelloWorldCommand</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Chris</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
167
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_be_ok'>be_ok</span>
|
168
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='symbol'>:greeting</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Hello Chris</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
169
|
+
<span class='kw'>end</span>
|
170
|
+
</code></pre>
|
171
|
+
|
172
|
+
<p>If your command does a lot, you might like to do some internal
|
173
|
+
verifications during the testing process to aid debugging. Inside a
|
174
|
+
command's execute_internal method, you can use a block like this</p>
|
175
|
+
|
176
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>def</span> <span class='id identifier rubyid_execute_internal'>execute_internal</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
|
177
|
+
<span class='comment'># ... do some logic
|
178
|
+
</span>
|
179
|
+
<span class='comment'># t is the parameter you passed as the first argument to execute_test.
|
180
|
+
</span> <span class='comment'># so, if you are using rspec, this code block will only be executed when you are
|
181
|
+
</span> <span class='comment'># running in a testing context.
|
182
|
+
</span> <span class='id identifier rubyid_testing'>testing</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_t'>t</span><span class='op'>|</span>
|
183
|
+
<span class='id identifier rubyid_t'>t</span><span class='period'>.</span><span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='id identifier rubyid_my_val'>my_val</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_t'>t</span><span class='period'>.</span><span class='id identifier rubyid_eq'>eq</span><span class='lparen'>(</span><span class='int'>10</span><span class='rparen'>)</span>
|
184
|
+
<span class='kw'>end</span>
|
185
|
+
|
186
|
+
<span class='kw'>end</span>
|
187
|
+
|
188
|
+
<span class='comment'>### Child Actions
|
189
|
+
</span>
|
190
|
+
<span class='const'>Actions</span> <span class='id identifier rubyid_can'>can</span> <span class='id identifier rubyid_execute'>execute</span> <span class='id identifier rubyid_their'>their</span> <span class='id identifier rubyid_own'>own</span> <span class='id identifier rubyid_child'>child</span> <span class='id identifier rubyid_actions'>actions</span><span class='period'>.</span> <span class='const'>Within</span> <span class='id identifier rubyid_an'>an</span> <span class='id identifier rubyid_action'>action</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>s execute_internal method
|
191
|
+
</span></span></code></pre>
|
192
|
+
|
193
|
+
<p>ruby def execute_internal @names.each_with_index do |name, i| # the i
|
194
|
+
parameter will cause the result of the child command to be nested # in the
|
195
|
+
result under that value. For example, here I would expect # <a
|
196
|
+
href="i">result</a>[:greeting] to contain the greeting for each subcommand
|
197
|
+
after # execution. ActionCommand.execute_child(self, HelloWorldCommand,
|
198
|
+
result, i, name: name) end end “`</p>
|
100
199
|
|
101
200
|
<h2 id="label-Development">Development</h2>
|
102
201
|
|
@@ -128,7 +227,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
128
227
|
</div></div>
|
129
228
|
|
130
229
|
<div id="footer">
|
131
|
-
Generated on
|
230
|
+
Generated on Thu Mar 3 16:34:07 2016 by
|
132
231
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
133
232
|
0.8.7.6 (ruby-2.2.3).
|
134
233
|
</div>
|
data/doc/method_list.html
CHANGED
@@ -64,8 +64,8 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
<li class="r1 ">
|
67
|
-
<span class='object_link'><a href="ActionCommand/
|
68
|
-
<small>ActionCommand::
|
67
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#child_context%3F-instance_method" title="ActionCommand::Executable#child_context? (method)">#child_context?</a></span>
|
68
|
+
<small>ActionCommand::Executable</small>
|
69
69
|
</li>
|
70
70
|
|
71
71
|
|
@@ -82,23 +82,35 @@
|
|
82
82
|
|
83
83
|
|
84
84
|
<li class="r2 ">
|
85
|
-
<span class='object_link'><a href="ActionCommand.html#
|
86
|
-
<small>ActionCommand</small>
|
85
|
+
<span class='object_link'><a href="ActionCommand/Result.html#current-instance_method" title="ActionCommand::Result#current (method)">#current</a></span>
|
86
|
+
<small>ActionCommand::Result</small>
|
87
87
|
</li>
|
88
88
|
|
89
89
|
|
90
90
|
<li class="r1 ">
|
91
|
-
<span class='object_link'><a href="ActionCommand/InputOutput.html#
|
91
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#desc-instance_method" title="ActionCommand::InputOutput#desc (method)">#desc</a></span>
|
92
92
|
<small>ActionCommand::InputOutput</small>
|
93
93
|
</li>
|
94
94
|
|
95
95
|
|
96
96
|
<li class="r2 ">
|
97
|
+
<span class='object_link'><a href="ActionCommand.html#describe_io-class_method" title="ActionCommand.describe_io (method)">describe_io</a></span>
|
98
|
+
<small>ActionCommand</small>
|
99
|
+
</li>
|
100
|
+
|
101
|
+
|
102
|
+
<li class="r1 ">
|
97
103
|
<span class='object_link'><a href="ActionCommand/Executable.html#execute-instance_method" title="ActionCommand::Executable#execute (method)">#execute</a></span>
|
98
104
|
<small>ActionCommand::Executable</small>
|
99
105
|
</li>
|
100
106
|
|
101
107
|
|
108
|
+
<li class="r2 ">
|
109
|
+
<span class='object_link'><a href="ActionCommand.html#execute_child-class_method" title="ActionCommand.execute_child (method)">execute_child</a></span>
|
110
|
+
<small>ActionCommand</small>
|
111
|
+
</li>
|
112
|
+
|
113
|
+
|
102
114
|
<li class="r1 ">
|
103
115
|
<span class='object_link'><a href="ActionCommand/Executable.html#execute_internal-instance_method" title="ActionCommand::Executable#execute_internal (method)">#execute_internal</a></span>
|
104
116
|
<small>ActionCommand::Executable</small>
|
@@ -130,65 +142,149 @@
|
|
130
142
|
|
131
143
|
|
132
144
|
<li class="r2 ">
|
145
|
+
<span class='object_link'><a href="ActionCommand/Utils.html#find_object-class_method" title="ActionCommand::Utils.find_object (method)">find_object</a></span>
|
146
|
+
<small>ActionCommand::Utils</small>
|
147
|
+
</li>
|
148
|
+
|
149
|
+
|
150
|
+
<li class="r1 ">
|
133
151
|
<span class='object_link'><a href="ActionCommand/InputOutput.html#help%3F-instance_method" title="ActionCommand::InputOutput#help? (method)">#help?</a></span>
|
134
152
|
<small>ActionCommand::InputOutput</small>
|
135
153
|
</li>
|
136
154
|
|
137
155
|
|
138
|
-
<li class="
|
156
|
+
<li class="r2 ">
|
139
157
|
<span class='object_link'><a href="ActionCommand/Result.html#info-instance_method" title="ActionCommand::Result#info (method)">#info</a></span>
|
140
158
|
<small>ActionCommand::Result</small>
|
141
159
|
</li>
|
142
160
|
|
143
161
|
|
162
|
+
<li class="r1 ">
|
163
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#initialize-instance_method" title="ActionCommand::InputOutput#initialize (method)">#initialize</a></span>
|
164
|
+
<small>ActionCommand::InputOutput</small>
|
165
|
+
</li>
|
166
|
+
|
167
|
+
|
144
168
|
<li class="r2 ">
|
169
|
+
<span class='object_link'><a href="ActionCommand/Result.html#initialize-instance_method" title="ActionCommand::Result#initialize (method)">#initialize</a></span>
|
170
|
+
<small>ActionCommand::Result</small>
|
171
|
+
</li>
|
172
|
+
|
173
|
+
|
174
|
+
<li class="r1 ">
|
145
175
|
<span class='object_link'><a href="ActionCommand/Executable.html#initialize-instance_method" title="ActionCommand::Executable#initialize (method)">#initialize</a></span>
|
146
176
|
<small>ActionCommand::Executable</small>
|
147
177
|
</li>
|
148
178
|
|
149
179
|
|
180
|
+
<li class="r2 ">
|
181
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#input-instance_method" title="ActionCommand::InputOutput#input (method)">#input</a></span>
|
182
|
+
<small>ActionCommand::InputOutput</small>
|
183
|
+
</li>
|
184
|
+
|
185
|
+
|
150
186
|
<li class="r1 ">
|
151
|
-
<span class='object_link'><a href="ActionCommand
|
187
|
+
<span class='object_link'><a href="ActionCommand.html#install_rake-class_method" title="ActionCommand.install_rake (method)">install_rake</a></span>
|
188
|
+
<small>ActionCommand</small>
|
189
|
+
</li>
|
190
|
+
|
191
|
+
|
192
|
+
<li class="r2 ">
|
193
|
+
<span class='object_link'><a href="ActionCommand/Result.html#key%3F-instance_method" title="ActionCommand::Result#key? (method)">#key?</a></span>
|
152
194
|
<small>ActionCommand::Result</small>
|
153
195
|
</li>
|
154
196
|
|
155
197
|
|
198
|
+
<li class="r1 ">
|
199
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#keys-instance_method" title="ActionCommand::InputOutput#keys (method)">#keys</a></span>
|
200
|
+
<small>ActionCommand::InputOutput</small>
|
201
|
+
</li>
|
202
|
+
|
203
|
+
|
156
204
|
<li class="r2 ">
|
157
|
-
<span class='object_link'><a href="ActionCommand
|
205
|
+
<span class='object_link'><a href="ActionCommand.html#logger%3D-class_method" title="ActionCommand.logger= (method)">logger=</a></span>
|
206
|
+
<small>ActionCommand</small>
|
207
|
+
</li>
|
208
|
+
|
209
|
+
|
210
|
+
<li class="r1 ">
|
211
|
+
<span class='object_link'><a href="ActionCommand/Result.html#ok%3F-instance_method" title="ActionCommand::Result#ok? (method)">#ok?</a></span>
|
212
|
+
<small>ActionCommand::Result</small>
|
213
|
+
</li>
|
214
|
+
|
215
|
+
|
216
|
+
<li class="r2 ">
|
217
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#output-instance_method" title="ActionCommand::InputOutput#output (method)">#output</a></span>
|
158
218
|
<small>ActionCommand::InputOutput</small>
|
159
219
|
</li>
|
160
220
|
|
161
221
|
|
162
222
|
<li class="r1 ">
|
163
|
-
<span class='object_link'><a href="ActionCommand/
|
223
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#parent-instance_method" title="ActionCommand::Executable#parent (method)">#parent</a></span>
|
224
|
+
<small>ActionCommand::Executable</small>
|
225
|
+
</li>
|
226
|
+
|
227
|
+
|
228
|
+
<li class="r2 ">
|
229
|
+
<span class='object_link'><a href="ActionCommand/Result.html#pop-instance_method" title="ActionCommand::Result#pop (method)">#pop</a></span>
|
230
|
+
<small>ActionCommand::Result</small>
|
231
|
+
</li>
|
232
|
+
|
233
|
+
|
234
|
+
<li class="r1 ">
|
235
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#print_output-instance_method" title="ActionCommand::InputOutput#print_output (method)">#print_output</a></span>
|
164
236
|
<small>ActionCommand::InputOutput</small>
|
165
237
|
</li>
|
166
238
|
|
167
239
|
|
168
240
|
<li class="r2 ">
|
169
|
-
<span class='object_link'><a href="ActionCommand/InputOutput.html#
|
241
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#process_input-instance_method" title="ActionCommand::InputOutput#process_input (method)">#process_input</a></span>
|
170
242
|
<small>ActionCommand::InputOutput</small>
|
171
243
|
</li>
|
172
244
|
|
173
245
|
|
174
246
|
<li class="r1 ">
|
175
|
-
<span class='object_link'><a href="ActionCommand.html#
|
176
|
-
<small>ActionCommand</small>
|
247
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#process_output-instance_method" title="ActionCommand::InputOutput#process_output (method)">#process_output</a></span>
|
248
|
+
<small>ActionCommand::InputOutput</small>
|
177
249
|
</li>
|
178
250
|
|
179
251
|
|
180
252
|
<li class="r2 ">
|
181
|
-
<span class='object_link'><a href="ActionCommand/Result.html#
|
253
|
+
<span class='object_link'><a href="ActionCommand/Result.html#push-instance_method" title="ActionCommand::Result#push (method)">#push</a></span>
|
182
254
|
<small>ActionCommand::Result</small>
|
183
255
|
</li>
|
184
256
|
|
185
257
|
|
186
258
|
<li class="r1 ">
|
187
|
-
<span class='object_link'><a href="ActionCommand/Executable.html#
|
259
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#rails_context%3F-instance_method" title="ActionCommand::Executable#rails_context? (method)">#rails_context?</a></span>
|
188
260
|
<small>ActionCommand::Executable</small>
|
189
261
|
</li>
|
190
262
|
|
191
263
|
|
264
|
+
<li class="r2 ">
|
265
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#rake_context%3F-instance_method" title="ActionCommand::Executable#rake_context? (method)">#rake_context?</a></span>
|
266
|
+
<small>ActionCommand::Executable</small>
|
267
|
+
</li>
|
268
|
+
|
269
|
+
|
270
|
+
<li class="r1 ">
|
271
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#rake_input-instance_method" title="ActionCommand::InputOutput#rake_input (method)">#rake_input</a></span>
|
272
|
+
<small>ActionCommand::InputOutput</small>
|
273
|
+
</li>
|
274
|
+
|
275
|
+
|
276
|
+
<li class="r2 ">
|
277
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#root_context-instance_method" title="ActionCommand::Executable#root_context (method)">#root_context</a></span>
|
278
|
+
<small>ActionCommand::Executable</small>
|
279
|
+
</li>
|
280
|
+
|
281
|
+
|
282
|
+
<li class="r1 ">
|
283
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#should_validate-instance_method" title="ActionCommand::InputOutput#should_validate (method)">#should_validate</a></span>
|
284
|
+
<small>ActionCommand::InputOutput</small>
|
285
|
+
</li>
|
286
|
+
|
287
|
+
|
192
288
|
<li class="r2 ">
|
193
289
|
<span class='object_link'><a href="ActionCommand/InputOutput.html#show_help-instance_method" title="ActionCommand::InputOutput#show_help (method)">#show_help</a></span>
|
194
290
|
<small>ActionCommand::InputOutput</small>
|
@@ -202,13 +298,19 @@
|
|
202
298
|
|
203
299
|
|
204
300
|
<li class="r2 ">
|
205
|
-
<span class='object_link'><a href="ActionCommand/Executable.html#
|
301
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#test_context%3F-instance_method" title="ActionCommand::Executable#test_context? (method)">#test_context?</a></span>
|
206
302
|
<small>ActionCommand::Executable</small>
|
207
303
|
</li>
|
208
304
|
|
209
305
|
|
210
306
|
<li class="r1 ">
|
211
|
-
<span class='object_link'><a href="ActionCommand/
|
307
|
+
<span class='object_link'><a href="ActionCommand/Executable.html#testing-instance_method" title="ActionCommand::Executable#testing (method)">#testing</a></span>
|
308
|
+
<small>ActionCommand::Executable</small>
|
309
|
+
</li>
|
310
|
+
|
311
|
+
|
312
|
+
<li class="r2 ">
|
313
|
+
<span class='object_link'><a href="ActionCommand/InputOutput.html#validate_input-instance_method" title="ActionCommand::InputOutput#validate_input (method)">#validate_input</a></span>
|
212
314
|
<small>ActionCommand::InputOutput</small>
|
213
315
|
</li>
|
214
316
|
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Thu Mar 3 16:34:07 2016 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7.6 (ruby-2.2.3).
|
109
109
|
</div>
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
module ActionCommand
|
3
|
+
# Root class for action commands that can be executed by this library.
|
4
|
+
# Override execute_internal to implement one, call one of the variants
|
5
|
+
# of ActionCommand.execute_... to execute one.
|
6
|
+
class Executable
|
7
|
+
|
8
|
+
attr_accessor :parent, :test
|
9
|
+
|
10
|
+
# Do not call new directly, instead use ActionCommand#execute_... variants.
|
11
|
+
def initialize(args)
|
12
|
+
self.class.describe_io.process_input(self, args)
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Symbol] the symbol indicating what context this
|
16
|
+
# action was executed in, see the ActionCommand::CONTEXT_ constants.
|
17
|
+
def root_context
|
18
|
+
|
19
|
+
context = parent
|
20
|
+
context = context.parent until context.is_a? Symbol
|
21
|
+
return context
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return true if this command was executed using ActionCommand.execute_test
|
25
|
+
def test_context?
|
26
|
+
return root_context == ActionCommand::CONTEXT_TEST
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return true if this command was executed using ActionCommand.execute_rails
|
30
|
+
def rails_context?
|
31
|
+
return root_context == ActionCommand::CONTEXT_RAILS
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return true if this command was executed using ActionCommand.execute_rake
|
35
|
+
def rake_context?
|
36
|
+
return root_context == ActionCommand::CONTEXT_RAKE
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return true if this command is a child of another command
|
40
|
+
def child_context?
|
41
|
+
return !parent.is_a?(Symbol)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Execute the logic of a command. Should not usually be called
|
45
|
+
# directly. Command executors should call one of the ActionCommand.execute_...
|
46
|
+
# variants. Command implementors should override
|
47
|
+
# execute_internal.
|
48
|
+
# @return [ActionCommand::Result]
|
49
|
+
def execute(result)
|
50
|
+
execute_internal(result)
|
51
|
+
self.class.describe_io.process_output(self, result)
|
52
|
+
return result
|
53
|
+
end
|
54
|
+
|
55
|
+
# Call this within a commands execution if you'd like to perform validations
|
56
|
+
# within the testing context.
|
57
|
+
# @yield [context] Yields back the testing context that you
|
58
|
+
# passed in to ActionCommand#execute_test.
|
59
|
+
def testing
|
60
|
+
yield @test if @test
|
61
|
+
end
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
|
66
|
+
# @!visibility public
|
67
|
+
# Override this method to implement the logic of your command
|
68
|
+
# @param result [ActionCommand::Result] a result object where you can store
|
69
|
+
# the results of your logic, or indicate that the command failed.
|
70
|
+
def execute_internal(result)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|