action_command 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ff531e1eca24b2ebde5421dc5bfb145a3060658
4
- data.tar.gz: 157affdb256a84d6a8afd79ef73b2dbf7b684917
3
+ metadata.gz: 879f72610d61724fbc97d332f42f5747684fcf87
4
+ data.tar.gz: 6708760e32d75083d4bf016df78879ef76e385d7
5
5
  SHA512:
6
- metadata.gz: a23a99e55f8fbd985631f5e55f983f0f6bb8f7fa76f96b81c371bfade67f76628dbfa8e949e72a8eae87df7d9555d8259d6be7c9467e9a2ab67750d5118dbeb9
7
- data.tar.gz: 107d8d93f7d3877f171b0bafc7b605e4bd49f251e1d6681d0fdc830701c9e574bd2b8fb2187eef120919b87ea83b66c9d2643acf76fe1a7c3cf361187d7ebb66
6
+ metadata.gz: aefeb76599b455594b3e07b2c8ce73615b4f34a161f0ef36d148b7a2b348bea923bab3ef7fd4d2a5e8c8b389192f098b06bcaeec2e4089e582333a1c3e308bdb
7
+ data.tar.gz: 9ff15a57e4c1f95837787dbd2574ae5d0f751c1effd340bc6bdd6798558fe927ecb23bf4b5b95c2f4fb67c0097dd6404075cf95d3fd975253dd3d006f7b8282a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action_command (0.1.1)
4
+ action_command (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -26,8 +26,8 @@ Or install it yourself as:
26
26
  ## Usage
27
27
 
28
28
  `action_command` is designed to help you centralize logic which might otherwise end up in a controller or model, and easily invoke it from a controller, a test,
29
- or a rake command. I read placing logic in 'actions' rather than models in the book [Rails 4 Test Prescriptions](http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222196)
30
- and liked it.
29
+ or a rake command. I encountered the idea in the book [Rails 4 Test Prescriptions](http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222196),
30
+ tried it and liked it.
31
31
 
32
32
  ### HelloWorld
33
33
 
@@ -55,7 +55,7 @@ class HelloWorldCommand < ActionCommand::Executable
55
55
  # assign results to the result. You can also use methods like result.fail or
56
56
  # result.info.
57
57
  def execute_internal(result)
58
- result[:greeting] = "Hello #{@name}" unless no_output
58
+ result[:greeting] = "Hello #{@name}"
59
59
  end
60
60
  end
61
61
  ```
@@ -71,7 +71,7 @@ You can execute it from rails:
71
71
  #### HelloWorld: Execute from Rake
72
72
 
73
73
  When building a system, I find it useful to be able to easily run my actions from
74
- the command-line as well. In rails, you can create a lib/tasks/my_rake.task, and
74
+ the command-line as well. In rails, you can create a lib/tasks/my_task.rake, and
75
75
  configure your actions as task with one line:
76
76
 
77
77
  ```
@@ -85,7 +85,34 @@ end
85
85
  ```
86
86
 
87
87
  You can always invoke your rake task with [help] to see help on the input and output
88
- of the action.
88
+ of the action. Then
89
+
90
+ ```
91
+ rake my_namespace:hello_world[help]
92
+ ```
93
+
94
+ will produce:
95
+
96
+ ```
97
+ HelloWorldCommand: Say hello to someone
98
+ Input:
99
+ name: Name of person to say hello to
100
+ no_output: If true, intentionally produces no output (optional)
101
+ Output:
102
+ greeting: Greeting for the person
103
+ ```
104
+
105
+ and
106
+
107
+ ```
108
+ rake my_namespace:hello_world[chris]
109
+ ```
110
+
111
+ will produce:
112
+
113
+ ```
114
+ greeting: Hello chris
115
+ ```
89
116
 
90
117
  #### HelloWorld: Execute from rspec/etc
91
118
 
@@ -100,7 +127,7 @@ Or, you can execute it from a testing framework.
100
127
  ```
101
128
 
102
129
  If your command does a lot, you might like to do some internal verifications during the testing process to aid
103
- debugging. Inside a command's execute_internal method, you can use a block like this
130
+ debugging. Inside a command's execute_internal method, you can use a block like this:
104
131
 
105
132
  ```ruby
106
133
  def execute_internal(result)
@@ -114,6 +141,7 @@ debugging. Inside a command's execute_internal method, you can use a block lik
114
141
  end
115
142
 
116
143
  end
144
+ ```
117
145
 
118
146
  ### Child Actions
119
147
 
@@ -594,12 +594,12 @@ validations within the testing context.</p>
594
594
  <pre class="lines">
595
595
 
596
596
 
597
+ 39
597
598
  40
598
- 41
599
- 42</pre>
599
+ 41</pre>
600
600
  </td>
601
601
  <td>
602
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 40</span>
602
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 39</span>
603
603
 
604
604
  <span class='kw'>def</span> <span class='id identifier rubyid_child_context?'>child_context?</span>
605
605
  <span class='kw'>return</span> <span class='op'>!</span><span class='id identifier rubyid_parent'>parent</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Symbol</span><span class='rparen'>)</span>
@@ -650,14 +650,14 @@ Command implementors should override execute_internal.</p>
650
650
  <pre class="lines">
651
651
 
652
652
 
653
+ 48
653
654
  49
654
655
  50
655
656
  51
656
- 52
657
- 53</pre>
657
+ 52</pre>
658
658
  </td>
659
659
  <td>
660
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 49</span>
660
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 48</span>
661
661
 
662
662
  <span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
663
663
  <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>
@@ -716,12 +716,12 @@ that the command failed.</p>
716
716
  <pre class="lines">
717
717
 
718
718
 
719
+ 69
719
720
  70
720
- 71
721
- 72</pre>
721
+ 71</pre>
722
722
  </td>
723
723
  <td>
724
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 70</span>
724
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 69</span>
725
725
 
726
726
  <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>
727
727
 
@@ -775,12 +775,12 @@ that the command failed.</p>
775
775
  <pre class="lines">
776
776
 
777
777
 
778
+ 29
778
779
  30
779
- 31
780
- 32</pre>
780
+ 31</pre>
781
781
  </td>
782
782
  <td>
783
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 30</span>
783
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 29</span>
784
784
 
785
785
  <span class='kw'>def</span> <span class='id identifier rubyid_rails_context?'>rails_context?</span>
786
786
  <span class='kw'>return</span> <span class='id identifier rubyid_root_context'>root_context</span> <span class='op'>==</span> <span class='const'>ActionCommand</span><span class='op'>::</span><span class='const'>CONTEXT_RAILS</span>
@@ -834,12 +834,12 @@ that the command failed.</p>
834
834
  <pre class="lines">
835
835
 
836
836
 
837
+ 34
837
838
  35
838
- 36
839
- 37</pre>
839
+ 36</pre>
840
840
  </td>
841
841
  <td>
842
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 35</span>
842
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 34</span>
843
843
 
844
844
  <span class='kw'>def</span> <span class='id identifier rubyid_rake_context?'>rake_context?</span>
845
845
  <span class='kw'>return</span> <span class='id identifier rubyid_root_context'>root_context</span> <span class='op'>==</span> <span class='const'>ActionCommand</span><span class='op'>::</span><span class='const'>CONTEXT_RAKE</span>
@@ -897,14 +897,12 @@ that the command failed.</p>
897
897
  18
898
898
  19
899
899
  20
900
- 21
901
- 22</pre>
900
+ 21</pre>
902
901
  </td>
903
902
  <td>
904
903
  <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 17</span>
905
904
 
906
905
  <span class='kw'>def</span> <span class='id identifier rubyid_root_context'>root_context</span>
907
-
908
906
  <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='id identifier rubyid_parent'>parent</span>
909
907
  <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='id identifier rubyid_context'>context</span><span class='period'>.</span><span class='id identifier rubyid_parent'>parent</span> <span class='kw'>until</span> <span class='id identifier rubyid_context'>context</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Symbol</span>
910
908
  <span class='kw'>return</span> <span class='id identifier rubyid_context'>context</span>
@@ -958,12 +956,12 @@ that the command failed.</p>
958
956
  <pre class="lines">
959
957
 
960
958
 
959
+ 24
961
960
  25
962
- 26
963
- 27</pre>
961
+ 26</pre>
964
962
  </td>
965
963
  <td>
966
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 25</span>
964
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 24</span>
967
965
 
968
966
  <span class='kw'>def</span> <span class='id identifier rubyid_test_context?'>test_context?</span>
969
967
  <span class='kw'>return</span> <span class='id identifier rubyid_root_context'>root_context</span> <span class='op'>==</span> <span class='const'>ActionCommand</span><span class='op'>::</span><span class='const'>CONTEXT_TEST</span>
@@ -1019,12 +1017,12 @@ ActionCommand#execute_test.</p>
1019
1017
  <pre class="lines">
1020
1018
 
1021
1019
 
1020
+ 58
1022
1021
  59
1023
- 60
1024
- 61</pre>
1022
+ 60</pre>
1025
1023
  </td>
1026
1024
  <td>
1027
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 59</span>
1025
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 58</span>
1028
1026
 
1029
1027
  <span class='kw'>def</span> <span class='id identifier rubyid_testing'>testing</span>
1030
1028
  <span class='kw'>yield</span> <span class='ivar'>@test</span> <span class='kw'>if</span> <span class='ivar'>@test</span>
@@ -1039,7 +1037,7 @@ ActionCommand#execute_test.</p>
1039
1037
  </div>
1040
1038
 
1041
1039
  <div id="footer">
1042
- Generated on Thu Mar 3 16:34:07 2016 by
1040
+ Generated on Fri Mar 4 10:20:15 2016 by
1043
1041
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1044
1042
  0.8.7.6 (ruby-2.2.3).
1045
1043
  </div>
@@ -989,7 +989,7 @@ missing</p>
989
989
  <pre class="code"><span class="info file"># File 'lib/action_command/input_output.rb', line 67</span>
990
990
 
991
991
  <span class='kw'>def</span> <span class='id identifier rubyid_process_output'>process_output</span><span class='lparen'>(</span><span class='id identifier rubyid_dest'>dest</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
992
- <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_should_validate'>should_validate</span><span class='lparen'>(</span><span class='id identifier rubyid_dest'>dest</span><span class='rparen'>)</span>
992
+ <span class='kw'>return</span> <span class='kw'>unless</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_ok?'>ok?</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_should_validate'>should_validate</span><span class='lparen'>(</span><span class='id identifier rubyid_dest'>dest</span><span class='rparen'>)</span>
993
993
 
994
994
  <span class='ivar'>@output</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_param'>param</span><span class='op'>|</span>
995
995
  <span class='id identifier rubyid_sym'>sym</span> <span class='op'>=</span> <span class='id identifier rubyid_param'>param</span><span class='lbracket'>[</span><span class='symbol'>:symbol</span><span class='rbracket'>]</span>
@@ -1268,7 +1268,7 @@ description.</p>
1268
1268
  </div>
1269
1269
 
1270
1270
  <div id="footer">
1271
- Generated on Thu Mar 3 16:34:07 2016 by
1271
+ Generated on Fri Mar 4 10:20:15 2016 by
1272
1272
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1273
1273
  0.8.7.6 (ruby-2.2.3).
1274
1274
  </div>
@@ -869,7 +869,7 @@ result.</p>
869
869
  </div>
870
870
 
871
871
  <div id="footer">
872
- Generated on Thu Mar 3 16:34:07 2016 by
872
+ Generated on Fri Mar 4 10:20:15 2016 by
873
873
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
874
874
  0.8.7.6 (ruby-2.2.3).
875
875
  </div>
@@ -192,7 +192,7 @@ controller, etc)</p>
192
192
 
193
193
  </div>
194
194
  </dt>
195
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>0.1.0</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
195
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>0.1.2</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
196
196
 
197
197
  <dt id="logger-classvariable" class="">@@logger =
198
198
  <div class="docstring">
@@ -1227,7 +1227,7 @@ validations. See <span class='object_link'><a href="ActionCommand/Executable.ht
1227
1227
  </div>
1228
1228
 
1229
1229
  <div id="footer">
1230
- Generated on Thu Mar 3 16:34:07 2016 by
1230
+ Generated on Fri Mar 4 10:20:15 2016 by
1231
1231
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1232
1232
  0.8.7.6 (ruby-2.2.3).
1233
1233
  </div>
data/doc/_index.html CHANGED
@@ -161,7 +161,7 @@
161
161
  </div>
162
162
 
163
163
  <div id="footer">
164
- Generated on Thu Mar 3 16:34:06 2016 by
164
+ Generated on Fri Mar 4 10:20:14 2016 by
165
165
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
166
166
  0.8.7.6 (ruby-2.2.3).
167
167
  </div>
data/doc/file.README.html CHANGED
@@ -98,10 +98,10 @@ by others.</p>
98
98
 
99
99
  <p><code>action_command</code> is designed to help you centralize logic which
100
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
- &#39;actions&#39; rather than models in the book <a
101
+ a controller, a test, or a rake command. I encountered the idea in the book
102
+ <a
103
103
  href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222196">Rails
104
- 4 Test Prescriptions</a> and liked it.</p>
104
+ 4 Test Prescriptions</a>, tried it and liked it.</p>
105
105
 
106
106
  <h3 id="label-HelloWorld">HelloWorld</h3>
107
107
 
@@ -128,7 +128,7 @@ href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222
128
128
  </span> <span class='comment'># assign results to the result. You can also use methods like result.fail or
129
129
  </span> <span class='comment'># result.info.
130
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'>&quot;</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'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_no_output'>no_output</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'>&quot;</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'>&quot;</span></span>
132
132
  <span class='kw'>end</span>
133
133
  <span class='kw'>end</span>
134
134
  </code></pre>
@@ -144,7 +144,7 @@ href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222
144
144
 
145
145
  <p>When building a system, I find it useful to be able to easily run my
146
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>
147
+ lib/tasks/my_task.rake, and configure your actions as task with one line:</p>
148
148
 
149
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
150
 
@@ -156,7 +156,28 @@ lib/tasks/my_rake.task, and configure your actions as task with one line:</p>
156
156
  </code></pre>
157
157
 
158
158
  <p>You can always invoke your rake task with [help] to see help on the input
159
- and output of the action.</p>
159
+ and output of the action. Then</p>
160
+
161
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_rake'>rake</span> <span class='label'>my_namespace:</span><span class='id identifier rubyid_hello_world'>hello_world</span><span class='lbracket'>[</span><span class='id identifier rubyid_help'>help</span><span class='rbracket'>]</span>
162
+ </code></pre>
163
+
164
+ <p>will produce:</p>
165
+
166
+ <pre class="code ruby"><code class="ruby">HelloWorldCommand: Say hello to someone
167
+ Input:
168
+ name: Name of person to say hello to
169
+ no_output: If true, intentionally produces no output (optional)
170
+ Output:
171
+ greeting: Greeting for the person</code></pre>
172
+
173
+ <p>and</p>
174
+
175
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_rake'>rake</span> <span class='label'>my_namespace:</span><span class='id identifier rubyid_hello_world'>hello_world</span><span class='lbracket'>[</span><span class='id identifier rubyid_chris'>chris</span><span class='rbracket'>]</span>
176
+ </code></pre>
177
+
178
+ <p>will produce:</p>
179
+
180
+ <pre class="code ruby"><code class="ruby">greeting: Hello chris</code></pre>
160
181
 
161
182
  <h4 id="label-HelloWorld-3A+Execute+from+rspec-2Fetc">HelloWorld: Execute from rspec/etc</h4>
162
183
 
@@ -171,7 +192,7 @@ and output of the action.</p>
171
192
 
172
193
  <p>If your command does a lot, you might like to do some internal
173
194
  verifications during the testing process to aid debugging. Inside a
174
- command&#39;s execute_internal method, you can use a block like this</p>
195
+ command&#39;s execute_internal method, you can use a block like this:</p>
175
196
 
176
197
  <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
198
  <span class='comment'># ... do some logic
@@ -184,18 +205,23 @@ command&#39;s execute_internal method, you can use a block like this</p>
184
205
  <span class='kw'>end</span>
185
206
 
186
207
  <span class='kw'>end</span>
208
+ </code></pre>
209
+
210
+ <h3 id="label-Child+Actions">Child Actions</h3>
187
211
 
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'>&#39;</span><span class='tstring_end'>s execute_internal method
191
- </span></span></code></pre>
212
+ <p>Actions can execute their own child actions. Within an action&#39;s
213
+ execute_internal method you should call additional actions via:</p>
192
214
 
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>
215
+ <pre class="code ruby"><code class="ruby"><span class='kw'>def</span> <span class='id identifier rubyid_execute_internal'>execute_internal</span>
216
+ <span class='ivar'>@names</span><span class='period'>.</span><span class='id identifier rubyid_each_with_index'>each_with_index</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_i'>i</span><span class='op'>|</span>
217
+ <span class='comment'># the i parameter will cause the result of the child command to be nested
218
+ </span> <span class='comment'># in the result under that value. For example, here I would expect
219
+ </span> <span class='comment'># result[i][:greeting] to contain the greeting for each subcommand after
220
+ </span> <span class='comment'># execution.
221
+ </span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_execute_child'>execute_child</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='id identifier rubyid_result'>result</span><span class='comma'>,</span> <span class='id identifier rubyid_i'>i</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
222
+ <span class='kw'>end</span>
223
+ <span class='kw'>end</span>
224
+ </code></pre>
199
225
 
200
226
  <h2 id="label-Development">Development</h2>
201
227
 
@@ -227,7 +253,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
227
253
  </div></div>
228
254
 
229
255
  <div id="footer">
230
- Generated on Thu Mar 3 16:34:07 2016 by
256
+ Generated on Fri Mar 4 10:20:14 2016 by
231
257
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
232
258
  0.8.7.6 (ruby-2.2.3).
233
259
  </div>
data/doc/index.html CHANGED
@@ -98,10 +98,10 @@ by others.</p>
98
98
 
99
99
  <p><code>action_command</code> is designed to help you centralize logic which
100
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
- &#39;actions&#39; rather than models in the book <a
101
+ a controller, a test, or a rake command. I encountered the idea in the book
102
+ <a
103
103
  href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222196">Rails
104
- 4 Test Prescriptions</a> and liked it.</p>
104
+ 4 Test Prescriptions</a>, tried it and liked it.</p>
105
105
 
106
106
  <h3 id="label-HelloWorld">HelloWorld</h3>
107
107
 
@@ -128,7 +128,7 @@ href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222
128
128
  </span> <span class='comment'># assign results to the result. You can also use methods like result.fail or
129
129
  </span> <span class='comment'># result.info.
130
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'>&quot;</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'>&quot;</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_no_output'>no_output</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'>&quot;</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'>&quot;</span></span>
132
132
  <span class='kw'>end</span>
133
133
  <span class='kw'>end</span>
134
134
  </code></pre>
@@ -144,7 +144,7 @@ href="http://www.amazon.com/Rails-Test-Prescriptions-Healthy-Codebase/dp/1941222
144
144
 
145
145
  <p>When building a system, I find it useful to be able to easily run my
146
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>
147
+ lib/tasks/my_task.rake, and configure your actions as task with one line:</p>
148
148
 
149
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
150
 
@@ -156,7 +156,28 @@ lib/tasks/my_rake.task, and configure your actions as task with one line:</p>
156
156
  </code></pre>
157
157
 
158
158
  <p>You can always invoke your rake task with [help] to see help on the input
159
- and output of the action.</p>
159
+ and output of the action. Then</p>
160
+
161
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_rake'>rake</span> <span class='label'>my_namespace:</span><span class='id identifier rubyid_hello_world'>hello_world</span><span class='lbracket'>[</span><span class='id identifier rubyid_help'>help</span><span class='rbracket'>]</span>
162
+ </code></pre>
163
+
164
+ <p>will produce:</p>
165
+
166
+ <pre class="code ruby"><code class="ruby">HelloWorldCommand: Say hello to someone
167
+ Input:
168
+ name: Name of person to say hello to
169
+ no_output: If true, intentionally produces no output (optional)
170
+ Output:
171
+ greeting: Greeting for the person</code></pre>
172
+
173
+ <p>and</p>
174
+
175
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_rake'>rake</span> <span class='label'>my_namespace:</span><span class='id identifier rubyid_hello_world'>hello_world</span><span class='lbracket'>[</span><span class='id identifier rubyid_chris'>chris</span><span class='rbracket'>]</span>
176
+ </code></pre>
177
+
178
+ <p>will produce:</p>
179
+
180
+ <pre class="code ruby"><code class="ruby">greeting: Hello chris</code></pre>
160
181
 
161
182
  <h4 id="label-HelloWorld-3A+Execute+from+rspec-2Fetc">HelloWorld: Execute from rspec/etc</h4>
162
183
 
@@ -171,7 +192,7 @@ and output of the action.</p>
171
192
 
172
193
  <p>If your command does a lot, you might like to do some internal
173
194
  verifications during the testing process to aid debugging. Inside a
174
- command&#39;s execute_internal method, you can use a block like this</p>
195
+ command&#39;s execute_internal method, you can use a block like this:</p>
175
196
 
176
197
  <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
198
  <span class='comment'># ... do some logic
@@ -184,18 +205,23 @@ command&#39;s execute_internal method, you can use a block like this</p>
184
205
  <span class='kw'>end</span>
185
206
 
186
207
  <span class='kw'>end</span>
208
+ </code></pre>
209
+
210
+ <h3 id="label-Child+Actions">Child Actions</h3>
187
211
 
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'>&#39;</span><span class='tstring_end'>s execute_internal method
191
- </span></span></code></pre>
212
+ <p>Actions can execute their own child actions. Within an action&#39;s
213
+ execute_internal method you should call additional actions via:</p>
192
214
 
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>
215
+ <pre class="code ruby"><code class="ruby"><span class='kw'>def</span> <span class='id identifier rubyid_execute_internal'>execute_internal</span>
216
+ <span class='ivar'>@names</span><span class='period'>.</span><span class='id identifier rubyid_each_with_index'>each_with_index</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_i'>i</span><span class='op'>|</span>
217
+ <span class='comment'># the i parameter will cause the result of the child command to be nested
218
+ </span> <span class='comment'># in the result under that value. For example, here I would expect
219
+ </span> <span class='comment'># result[i][:greeting] to contain the greeting for each subcommand after
220
+ </span> <span class='comment'># execution.
221
+ </span> <span class='const'>ActionCommand</span><span class='period'>.</span><span class='id identifier rubyid_execute_child'>execute_child</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='id identifier rubyid_result'>result</span><span class='comma'>,</span> <span class='id identifier rubyid_i'>i</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
222
+ <span class='kw'>end</span>
223
+ <span class='kw'>end</span>
224
+ </code></pre>
199
225
 
200
226
  <h2 id="label-Development">Development</h2>
201
227
 
@@ -227,7 +253,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
227
253
  </div></div>
228
254
 
229
255
  <div id="footer">
230
- Generated on Thu Mar 3 16:34:07 2016 by
256
+ Generated on Fri Mar 4 10:20:14 2016 by
231
257
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
232
258
  0.8.7.6 (ruby-2.2.3).
233
259
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Thu Mar 3 16:34:07 2016 by
106
+ Generated on Fri Mar 4 10:20:14 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>
@@ -15,7 +15,6 @@ module ActionCommand
15
15
  # @return [Symbol] the symbol indicating what context this
16
16
  # action was executed in, see the ActionCommand::CONTEXT_ constants.
17
17
  def root_context
18
-
19
18
  context = parent
20
19
  context = context.parent until context.is_a? Symbol
21
20
  return context
@@ -65,7 +65,7 @@ module ActionCommand
65
65
 
66
66
  # Goes through, and makes sure that required output parameters exist
67
67
  def process_output(dest, result)
68
- return unless should_validate(dest)
68
+ return unless result.ok? && should_validate(dest)
69
69
 
70
70
  @output.each do |param|
71
71
  sym = param[:symbol]
@@ -6,7 +6,6 @@ module ActionCommand
6
6
  # Used for cases where you might want to pass an action a User object, or
7
7
  # the integer ID of a user object, or the unique email of a user object, and
8
8
  # have the command operate on the user object.
9
-
10
9
  # Converts an item into an object as follows:
11
10
  # 1. If item is an object of cls, then returns it
12
11
  # 2. If item is an integer, then assumes its and id and returns cls.find(item)
@@ -16,6 +15,11 @@ module ActionCommand
16
15
  return cls.find(item) if item.is_a? Integer
17
16
  return yield(item)
18
17
  end
18
+
19
+
20
+
21
+
22
+
19
23
  end
20
24
 
21
25
  end
@@ -1,4 +1,4 @@
1
1
  module ActionCommand
2
2
  # Version of this Gem
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Jones
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler