action_command 0.1.3 → 0.1.4

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: 1f453f4bd9d5de25bb5d0509ce6572f83d9fb61f
4
- data.tar.gz: 180d47f86c8e4121c5daa5e6ad22220ce8925907
3
+ metadata.gz: 2cd366bbe081e13a248bcff7ef460127574f2c73
4
+ data.tar.gz: 3d8a05a55480d5d10fa609d4e9d69ede0bd849c2
5
5
  SHA512:
6
- metadata.gz: 93c26718dd95a05f3d739d757bcbed33ecde64b27a8b566cf31a188fb8cc8133f21fbc28843920ecad0170dc03102560ae5618c5dc8efce7ac43cf1ce16958ee
7
- data.tar.gz: 09328459ee69b500f94c9931f816b3c27283d073ac01212982af0a50749cde885942468a129218795afab652b10857982e4be4eefca40ba906fc8f6659519310
6
+ metadata.gz: 1e7674270076303b570cd4687d4816218edd54eb8afa96a01611c9c0cc42a4eea0827dc769e8690958f3b737bdee6a2bcb09d7171fe9faee545b793c4b2c84f7
7
+ data.tar.gz: 3adbd8341c395686657dd8d9dd8a840e760dc1f0c96f93aa2c8af935b9a3b3ea6c4035f1efaa46f1a6342c7c12de9288acb991cd37233f94dd62a5fbe9425370
data/.byebug_history ADDED
@@ -0,0 +1,5 @@
1
+ quit
2
+ exit
3
+ User.all
4
+ created
5
+ user
data/.codeclimate.yml CHANGED
@@ -24,3 +24,4 @@ ratings:
24
24
  - "**.go"
25
25
  exclude_paths:
26
26
  - doc/**/*
27
+ - spec/**/*
data/.rubocop.yml CHANGED
@@ -1,9 +1,13 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - Guardfile
4
+ - spec/**/*
4
5
  Metrics/LineLength:
5
6
  Max: 99
6
7
 
8
+ Metrics/MethodLength:
9
+ Max: 15
10
+
7
11
  Style/TrailingWhitespace:
8
12
  Enabled: false
9
13
 
data/Gemfile.lock CHANGED
@@ -1,15 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action_command (0.1.3)
4
+ action_command (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ activemodel (4.0.13)
10
+ activesupport (= 4.0.13)
11
+ builder (~> 3.1.0)
12
+ activerecord (4.0.13)
13
+ activemodel (= 4.0.13)
14
+ activerecord-deprecated_finders (~> 1.0.2)
15
+ activesupport (= 4.0.13)
16
+ arel (~> 4.0.0)
17
+ activerecord-deprecated_finders (1.0.4)
18
+ activesupport (4.0.13)
19
+ i18n (~> 0.6, >= 0.6.9)
20
+ minitest (~> 4.2)
21
+ multi_json (~> 1.3)
22
+ thread_safe (~> 0.1)
23
+ tzinfo (~> 0.3.37)
24
+ arel (4.0.2)
9
25
  ast (2.2.0)
10
- codeclimate-test-reporter (0.4.8)
26
+ builder (3.1.4)
27
+ byebug (8.2.2)
28
+ codeclimate-test-reporter (0.5.0)
11
29
  simplecov (>= 0.7.1, < 1.0.0)
12
- coderay (1.1.0)
30
+ coderay (1.1.1)
13
31
  colorize (0.7.7)
14
32
  diff-lcs (1.2.5)
15
33
  docile (1.1.5)
@@ -32,17 +50,20 @@ GEM
32
50
  guard-rubocop (1.2.0)
33
51
  guard (~> 2.0)
34
52
  rubocop (~> 0.20)
53
+ i18n (0.7.0)
35
54
  json (1.8.3)
36
55
  listen (3.0.6)
37
56
  rb-fsevent (>= 0.9.3)
38
57
  rb-inotify (>= 0.9.7)
39
58
  lumberjack (1.0.10)
40
59
  method_source (0.8.2)
60
+ minitest (4.7.5)
61
+ multi_json (1.11.2)
41
62
  nenv (0.3.0)
42
63
  notiffany (0.0.8)
43
64
  nenv (~> 0.1)
44
65
  shellany (~> 0.0)
45
- parser (2.3.0.5)
66
+ parser (2.3.0.6)
46
67
  ast (~> 2.2)
47
68
  powerpack (0.1.1)
48
69
  pry (0.10.3)
@@ -60,7 +81,7 @@ GEM
60
81
  rspec-core (~> 3.4.0)
61
82
  rspec-expectations (~> 3.4.0)
62
83
  rspec-mocks (~> 3.4.0)
63
- rspec-core (3.4.2)
84
+ rspec-core (3.4.3)
64
85
  rspec-support (~> 3.4.0)
65
86
  rspec-expectations (3.4.0)
66
87
  diff-lcs (>= 1.2.0, < 2.0)
@@ -83,9 +104,12 @@ GEM
83
104
  simplecov-html (~> 0.10.0)
84
105
  simplecov-html (0.10.0)
85
106
  slop (3.6.0)
107
+ sqlite3 (1.3.11)
86
108
  terminal-notifier (1.6.3)
87
- terminal-notifier-guard (1.6.4)
109
+ terminal-notifier-guard (1.7.0)
88
110
  thor (0.19.1)
111
+ thread_safe (0.3.5)
112
+ tzinfo (0.3.46)
89
113
  unicode-display_width (0.3.1)
90
114
  yard (0.8.7.6)
91
115
 
@@ -94,7 +118,9 @@ PLATFORMS
94
118
 
95
119
  DEPENDENCIES
96
120
  action_command!
121
+ activerecord (~> 4.0.0)
97
122
  bundler (~> 1.11)
123
+ byebug
98
124
  codeclimate-test-reporter
99
125
  guard
100
126
  guard-rspec
@@ -104,6 +130,7 @@ DEPENDENCIES
104
130
  rspec (~> 3.0)
105
131
  rubocop (~> 0.37.0)
106
132
  simplecov (~> 0.11)
133
+ sqlite3
107
134
  terminal-notifier
108
135
  terminal-notifier-guard
109
136
  yard (~> 0.8)
data/README.md CHANGED
@@ -160,6 +160,68 @@ you should call additional actions via:
160
160
  end
161
161
  ```
162
162
 
163
+ ### Error Handling and Logging
164
+
165
+ #### Error Handling
166
+
167
+ Within a command, you can generically fail with an error message, or fail with a
168
+ particular custom error code
169
+
170
+ ```ruby
171
+ def execute_internal(result)
172
+ # fail generically
173
+ result.failed("Something bad happened")
174
+
175
+ my_custom_error = 10
176
+ result.failed_with_code("Something bad happened", my_custom_error)
177
+ end
178
+ ```
179
+
180
+ You can check for errors in the result:
181
+
182
+ ```ruby
183
+ result = ActionCommand.execute_rails...
184
+
185
+ return unless result.ok? # generic failure
186
+
187
+ switch(result.result_code)
188
+ when ActionCommand::RESULT_CODE_OK
189
+ ...
190
+ when my_custom_error
191
+ ...
192
+ end
193
+ ```
194
+
195
+ #### Logging
196
+
197
+ You can turn on logging either globally, or for specific
198
+ command executions:
199
+
200
+ ```ruby
201
+ # turn it on globally
202
+ ActionCommand.logger = your_logger
203
+
204
+ # turn it on only for this command
205
+ params = {
206
+ logger: your_logger,
207
+ # your other parameters
208
+ }
209
+ ActionCommand.execute_rails(YourCommand, params)
210
+ ```
211
+
212
+ When logging is on, the logger will receive single-line JSON messages
213
+ at the debugging level for all command inputs and outputs. All child
214
+ commands under a parent will automatically be tagged with a serial
215
+ number for correlation. The result looks like this:
216
+
217
+ TODO
218
+
219
+ You can also optionally add your own entries to the log by calling
220
+ `result.debug`, `result.info`, or `result.failed`. If you pass these
221
+ calls a string, they will include it as `msg` in the JSON. If you
222
+ pass them a hash, its contents will be merged into the JSON.
223
+
224
+
163
225
  ## Development
164
226
 
165
227
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.11'
24
+ spec.add_development_dependency 'byebug'
24
25
  spec.add_development_dependency 'rake', '~> 10.0'
25
26
  spec.add_development_dependency 'rspec', '~> 3.0'
26
27
  spec.add_development_dependency 'rubocop', '~> 0.37.0'
@@ -33,4 +34,6 @@ Gem::Specification.new do |spec|
33
34
  spec.add_development_dependency 'terminal-notifier'
34
35
  spec.add_development_dependency 'terminal-notifier-guard'
35
36
  spec.add_development_dependency 'rake_command_filter'
37
+ spec.add_development_dependency 'activerecord', '~> 4.0.0'
38
+ spec.add_development_dependency 'sqlite3'
36
39
  end
@@ -112,10 +112,14 @@ ActionCommand.execute_… to execute one.</p>
112
112
  <div class="tags">
113
113
 
114
114
 
115
+ </div><div id="subclasses">
116
+ <h2>Direct Known Subclasses</h2>
117
+ <p class="children"><span class='object_link'><a href="ExecutableTransaction.html" title="ActionCommand::ExecutableTransaction (class)">ExecutableTransaction</a></span>, <span class='object_link'><a href="PrettyPrintLogAction.html" title="ActionCommand::PrettyPrintLogAction (class)">PrettyPrintLogAction</a></span></p>
115
118
  </div>
116
119
 
117
120
 
118
121
 
122
+
119
123
  <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
120
124
  <ul class="summary">
121
125
 
@@ -189,6 +193,30 @@ ActionCommand.execute_… to execute one.</p>
189
193
  <li class="public ">
190
194
  <span class="summary_signature">
191
195
 
196
+ <a href="#api_context%3F-instance_method" title="#api_context? (instance method)">- (Boolean) <strong>api_context?</strong> </a>
197
+
198
+
199
+
200
+ </span>
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+ <span class="summary_desc"><div class='inline'>
211
+ <p>True if this command was executed using ActionCommand.execute_api.</p>
212
+ </div></span>
213
+
214
+ </li>
215
+
216
+
217
+ <li class="public ">
218
+ <span class="summary_signature">
219
+
192
220
  <a href="#child_context%3F-instance_method" title="#child_context? (instance method)">- (Boolean) <strong>child_context?</strong> </a>
193
221
 
194
222
 
@@ -551,9 +579,9 @@ validations within the testing context.</p>
551
579
 
552
580
 
553
581
  <div class="method_details first">
554
- <h3 class="signature first" id="child_context?-instance_method">
582
+ <h3 class="signature first" id="api_context?-instance_method">
555
583
 
556
- - (<tt>Boolean</tt>) <strong>child_context?</strong>
584
+ - (<tt>Boolean</tt>) <strong>api_context?</strong>
557
585
 
558
586
 
559
587
 
@@ -562,7 +590,7 @@ validations within the testing context.</p>
562
590
  </h3><div class="docstring">
563
591
  <div class="discussion">
564
592
 
565
- <p>Returns true if this command is a child of another command</p>
593
+ <p>Returns true if this command was executed using ActionCommand.execute_api</p>
566
594
 
567
595
 
568
596
  </div>
@@ -581,7 +609,7 @@ validations within the testing context.</p>
581
609
 
582
610
  &mdash;
583
611
  <div class='inline'>
584
- <p>true if this command is a child of another command</p>
612
+ <p>true if this command was executed using ActionCommand.execute_api</p>
585
613
  </div>
586
614
 
587
615
  </li>
@@ -601,6 +629,65 @@ validations within the testing context.</p>
601
629
  <td>
602
630
  <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 39</span>
603
631
 
632
+ <span class='kw'>def</span> <span class='id identifier rubyid_api_context?'>api_context?</span>
633
+ <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_API</span>
634
+ <span class='kw'>end</span></pre>
635
+ </td>
636
+ </tr>
637
+ </table>
638
+ </div>
639
+
640
+ <div class="method_details ">
641
+ <h3 class="signature " id="child_context?-instance_method">
642
+
643
+ - (<tt>Boolean</tt>) <strong>child_context?</strong>
644
+
645
+
646
+
647
+
648
+
649
+ </h3><div class="docstring">
650
+ <div class="discussion">
651
+
652
+ <p>Returns true if this command is a child of another command</p>
653
+
654
+
655
+ </div>
656
+ </div>
657
+ <div class="tags">
658
+
659
+ <p class="tag_title">Returns:</p>
660
+ <ul class="return">
661
+
662
+ <li>
663
+
664
+
665
+ <span class='type'>(<tt>Boolean</tt>)</span>
666
+
667
+
668
+
669
+ &mdash;
670
+ <div class='inline'>
671
+ <p>true if this command is a child of another command</p>
672
+ </div>
673
+
674
+ </li>
675
+
676
+ </ul>
677
+
678
+ </div><table class="source_code">
679
+ <tr>
680
+ <td>
681
+ <pre class="lines">
682
+
683
+
684
+ 45
685
+ 46
686
+ 47</pre>
687
+ </td>
688
+ <td>
689
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 45</span>
690
+
604
691
  <span class='kw'>def</span> <span class='id identifier rubyid_child_context?'>child_context?</span>
605
692
  <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>
606
693
  <span class='kw'>end</span></pre>
@@ -650,14 +737,14 @@ Command implementors should override execute_internal.</p>
650
737
  <pre class="lines">
651
738
 
652
739
 
653
- 48
654
- 49
655
- 50
656
- 51
657
- 52</pre>
740
+ 54
741
+ 55
742
+ 56
743
+ 57
744
+ 58</pre>
658
745
  </td>
659
746
  <td>
660
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 48</span>
747
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 54</span>
661
748
 
662
749
  <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
750
  <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 +803,12 @@ that the command failed.</p>
716
803
  <pre class="lines">
717
804
 
718
805
 
719
- 69
720
- 70
721
- 71</pre>
806
+ 75
807
+ 76
808
+ 77</pre>
722
809
  </td>
723
810
  <td>
724
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 69</span>
811
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 75</span>
725
812
 
726
813
  <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
814
 
@@ -1017,12 +1104,12 @@ ActionCommand#execute_test.</p>
1017
1104
  <pre class="lines">
1018
1105
 
1019
1106
 
1020
- 58
1021
- 59
1022
- 60</pre>
1107
+ 64
1108
+ 65
1109
+ 66</pre>
1023
1110
  </td>
1024
1111
  <td>
1025
- <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 58</span>
1112
+ <pre class="code"><span class="info file"># File 'lib/action_command/executable.rb', line 64</span>
1026
1113
 
1027
1114
  <span class='kw'>def</span> <span class='id identifier rubyid_testing'>testing</span>
1028
1115
  <span class='kw'>yield</span> <span class='ivar'>@test</span> <span class='kw'>if</span> <span class='ivar'>@test</span>
@@ -1037,7 +1124,7 @@ ActionCommand#execute_test.</p>
1037
1124
  </div>
1038
1125
 
1039
1126
  <div id="footer">
1040
- Generated on Fri Mar 4 10:20:15 2016 by
1127
+ Generated on Mon Mar 7 14:27:17 2016 by
1041
1128
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1042
1129
  0.8.7.6 (ruby-2.2.3).
1043
1130
  </div>