skywalker 1.2.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2694a53679e9a4856529718e3d7a80108aa32273
4
- data.tar.gz: 030762cf30ce2e24fef88a41098744ab65036965
3
+ metadata.gz: 409bd338e84e6633417f194fe89fd1ea74b12fc5
4
+ data.tar.gz: 51beb6b911c2b142f74900bfa59420cca6b26848
5
5
  SHA512:
6
- metadata.gz: ceed550cb8e32449ba3897c46a8b53ca4d89dc96874d66ebef9aa142227fddf928d8f2f4c6bfde3982239d348732035e31e90f472b6cb60a97b6d78b9ba422b5
7
- data.tar.gz: 550fdeacbc19bebc36bab1eaf51c5171eb638f7a7364fa3d3d2079b9139e2244362fa1b8cc4b5ce4742c4010c63d9e8115d6e3526a8d58264dcfc4a75154e8f9
6
+ metadata.gz: e237880ca6fc003a627c071922a3c345679f85f7db88b0026f3641c421b4feb8f703898134323c5e84b47164f028d07e1304fa2e7c1f180852a48d4b61b37520
7
+ data.tar.gz: 0a0de39ec25816c5272d0c15f56cfd973c532526de8d21b0799312b9d9e13d19aa53dce794784eb491d4fa7fe5453bc2398a3ccb207b5d839adf45fc50ba40ed
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  All commits by Rob Yurkowski unless otherwise noted.
2
2
 
3
+ ## 1.2.1 (2014-11-23)
4
+
5
+ - Fix a bug where callbacks would be called even if they were nil.
6
+
7
+ ## 1.2.0 (2014-11-16)
8
+
9
+ - Add `required_args`, which allows marking certain attributes as required at initialization. Defaults to an empty list.
10
+ - Add testing section of README.
11
+ - Add example files.
3
12
 
4
13
  ## 1.1.0 (2014-11-03)
5
14
 
data/README.md CHANGED
@@ -241,6 +241,12 @@ command = AddGroupCommand.call(
241
241
 
242
242
  You can pass any object responding to `#call` to the `on_success` and `on_failure` handlers, including procs, lambdas, controller methods, or other commands themselves.
243
243
 
244
+ ### What happens when callbacks fail?
245
+
246
+ Exceptions thrown inside the success callbacks (`on_success` or your own callbacks defined in `run_success_callbacks`) will cause the command to fail and run the failure callbacks.
247
+
248
+ Exceptions thrown inside the failure callbacks (`on_failure` or your own callbacks defined in `run_failure_callbacks`) will not be caught and will bubble out of the command.
249
+
244
250
  ### Overriding Methods
245
251
 
246
252
  The following methods are overridable for easy customization:
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- skywalker (1.1.1)
4
+ skywalker (1.2.1)
5
5
  activerecord (~> 4.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (4.1.7)
11
- activesupport (= 4.1.7)
10
+ activemodel (4.1.8)
11
+ activesupport (= 4.1.8)
12
12
  builder (~> 3.1)
13
- activerecord (4.1.7)
14
- activemodel (= 4.1.7)
15
- activesupport (= 4.1.7)
13
+ activerecord (4.1.8)
14
+ activemodel (= 4.1.8)
15
+ activesupport (= 4.1.8)
16
16
  arel (~> 5.0.0)
17
- activesupport (4.1.7)
17
+ activesupport (4.1.8)
18
18
  i18n (~> 0.6, >= 0.6.9)
19
19
  json (~> 1.7, >= 1.7.7)
20
20
  minitest (~> 5.1)
@@ -101,7 +101,7 @@ module Skywalker
101
101
 
102
102
 
103
103
  private def run_success_callbacks
104
- on_success.call(self) if self.respond_to?(:on_success)
104
+ on_success.call(self) unless on_success.nil?
105
105
  end
106
106
 
107
107
 
@@ -115,7 +115,7 @@ module Skywalker
115
115
 
116
116
 
117
117
  private def run_failure_callbacks
118
- on_failure.call(self) if self.respond_to?(:on_failure)
118
+ on_failure.call(self) unless on_failure.nil?
119
119
  end
120
120
  end
121
121
  end
@@ -1,3 +1,3 @@
1
1
  module Skywalker
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -83,18 +83,30 @@ module Skywalker
83
83
  end
84
84
 
85
85
  describe "on_success" do
86
- context "when on_success is defined" do
86
+ context "when on_success is not nil" do
87
87
  it "calls the on_success callback with itself" do
88
88
  expect(on_success).to receive(:call).with(command)
89
89
  command.call
90
90
  end
91
+
92
+ context "when on_success is not callable" do
93
+ let(:on_failure) { double("on_failure") }
94
+ let(:command) { Command.new(on_success: "a string", on_failure: on_failure) }
95
+
96
+ it "confirms failure if the on_success callback fails" do
97
+ expect(on_failure).to receive(:call).with(command)
98
+ command.call
99
+ end
100
+ end
91
101
  end
92
102
 
93
- context "when on_success is not defined" do
94
- let(:command) { Command.new }
103
+ context "when on_success is nil" do
104
+ let(:nil_callback) { double("fakenil", nil?: true) }
105
+ let(:command) { Command.new(on_success: nil_callback) }
95
106
 
96
107
  it "does not call on_success" do
97
- expect(command).not_to receive(:on_success)
108
+ expect(nil_callback).not_to receive(:call)
109
+ command.call
98
110
  end
99
111
  end
100
112
  end
@@ -131,18 +143,28 @@ module Skywalker
131
143
  allow(command).to receive(:error=)
132
144
  end
133
145
 
134
- context "when on_failure is defined" do
146
+ context "when on_failure is not nil" do
135
147
  it "calls the on_failure callback with itself" do
136
148
  expect(on_failure).to receive(:call).with(command)
137
149
  command.call
138
150
  end
151
+
152
+ context "when on_failure is not callable" do
153
+ let(:command) { Command.new(on_failure: "a string") }
154
+
155
+ it "raises an error" do
156
+ expect { command.call }.to raise_error
157
+ end
158
+ end
139
159
  end
140
160
 
141
- context "when on_failure is not defined" do
142
- let(:command) { Command.new }
161
+ context "when on_failure is nil" do
162
+ let(:nil_callback) { double("fakenil", nil?: true) }
163
+ let(:command) { Command.new(on_failure: nil_callback) }
143
164
 
144
165
  it "does not call on_failure" do
145
- expect(command).not_to receive(:on_failure)
166
+ expect(nil_callback).not_to receive(:call)
167
+ command.call
146
168
  end
147
169
  end
148
170
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skywalker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Yurkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord