response_state 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/lib/response_state/service.rb +3 -4
- data/lib/response_state/version.rb +1 -1
- data/spec/features/full_example_spec.rb +0 -1
- data/spec/lib/response_state/service_spec.rb +6 -29
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf386174f6638df5e17ded37f76a1cef1cf87eec
|
|
4
|
+
data.tar.gz: 76903168615aafedf6697076a572478c2dc447eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5cc91bc3692bc86448069d4e888be54d6b2452a8cbcadaa7706430d9d2b9dbdecfc060aedc910bf18e0b6021937b392ebd29ce1d51c50c1f7863b7e2291c217
|
|
7
|
+
data.tar.gz: d884192fe765cd69f93ac6583027d1afa65a77b75e48273dc2fba90be77d2f109fe71019a0c333a2a9a7200d686297d2fb70531c976e1451709c164d5db690c1
|
data/README.md
CHANGED
|
@@ -24,8 +24,6 @@ Create a service class and subclass ResponseState::Service.
|
|
|
24
24
|
|
|
25
25
|
```ruby
|
|
26
26
|
class MyService < ResponseState::Service
|
|
27
|
-
response_states :success, :failure
|
|
28
|
-
|
|
29
27
|
def initialize(param)
|
|
30
28
|
@param = param
|
|
31
29
|
end
|
|
@@ -37,8 +35,7 @@ class MyService < ResponseState::Service
|
|
|
37
35
|
end
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
You must implement a `call` method.
|
|
41
|
-
using the `response_states` class macro method.
|
|
38
|
+
You must implement a `call` method.
|
|
42
39
|
|
|
43
40
|
Your call method should yield with a call to `send_state` which will create a `ResponseState::Response`.
|
|
44
41
|
|
|
@@ -47,6 +44,16 @@ take a message and a context. The message by convention should be a string but t
|
|
|
47
44
|
The context can be any object. An error will be raised if a state is specified that is not in the list
|
|
48
45
|
of valid response states.
|
|
49
46
|
|
|
47
|
+
The valid response states default to `[:success, :failure]`.
|
|
48
|
+
You can override the valid response states for a class using the `response_states` class macro method.
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
class MyOtherService < ResponseState::Service
|
|
52
|
+
response_states :done, :error
|
|
53
|
+
# ...
|
|
54
|
+
end
|
|
55
|
+
```
|
|
56
|
+
|
|
50
57
|
### Your service API
|
|
51
58
|
|
|
52
59
|
Your service can now be used as such:
|
|
@@ -6,7 +6,7 @@ module ResponseState
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def self.valid_states
|
|
9
|
-
@valid_states || []
|
|
9
|
+
@valid_states || [:success, :failure]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.call(*args, &block)
|
|
@@ -17,9 +17,8 @@ module ResponseState
|
|
|
17
17
|
fail NotImplementedError, "A ResponseState::Service should implement the call method.\nThe call method should perform the relevant work of the service and yield a ResponseState::Response object.\n"
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def send_state(state, message=nil, context=nil
|
|
21
|
-
|
|
22
|
-
ResponseState::Response.new(state, message, context, valid_states)
|
|
20
|
+
def send_state(state, message=nil, context=nil)
|
|
21
|
+
ResponseState::Response.new(state, message, context, self.class.valid_states)
|
|
23
22
|
end
|
|
24
23
|
end
|
|
25
24
|
end
|
|
@@ -15,16 +15,16 @@ module ResponseState
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
describe '.
|
|
19
|
-
it '
|
|
20
|
-
Service.response_states :success, :failure
|
|
18
|
+
describe '.valid_states' do
|
|
19
|
+
it 'defaults to [:success, :failure]' do
|
|
21
20
|
expect(Service.valid_states).to eq [:success, :failure]
|
|
22
21
|
end
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
describe '.
|
|
26
|
-
it '
|
|
27
|
-
|
|
24
|
+
describe '.response_states' do
|
|
25
|
+
it 'sets the valid response states' do
|
|
26
|
+
Service.response_states :success, :error
|
|
27
|
+
expect(Service.valid_states).to eq [:success, :error]
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -35,29 +35,8 @@ module ResponseState
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
describe '#send_state' do
|
|
38
|
-
context 'given :success, "a message", {}, [:success, :failure]' do
|
|
39
|
-
let(:response) { service.send_state(:success, 'a message', {}, [:success, :failure]) }
|
|
40
|
-
|
|
41
|
-
it 'has a success state' do
|
|
42
|
-
expect(response.state).to eq :success
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'has the message "a message"' do
|
|
46
|
-
expect(response.message).to eq 'a message'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'has the context {}' do
|
|
50
|
-
expect(response.context).to eq Hash.new
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'has valid_states [:success, :failure]' do
|
|
54
|
-
expect(response.valid_states).to eq [:success, :failure]
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
38
|
context 'given :success, "a message", {}' do
|
|
59
39
|
let(:response) { service.send_state(:success, 'a message', {}) }
|
|
60
|
-
before { Service.response_states :success, :failure }
|
|
61
40
|
|
|
62
41
|
it 'has a success state' do
|
|
63
42
|
expect(response.state).to eq :success
|
|
@@ -78,7 +57,6 @@ module ResponseState
|
|
|
78
57
|
|
|
79
58
|
context 'given :success, "a message"' do
|
|
80
59
|
let(:response) { service.send_state(:success, 'a message') }
|
|
81
|
-
before { Service.response_states :success, :failure }
|
|
82
60
|
|
|
83
61
|
it 'has a success state' do
|
|
84
62
|
expect(response.state).to eq :success
|
|
@@ -99,7 +77,6 @@ module ResponseState
|
|
|
99
77
|
|
|
100
78
|
context 'given :success' do
|
|
101
79
|
let(:response) { service.send_state(:success) }
|
|
102
|
-
before { Service.response_states :success, :failure }
|
|
103
80
|
|
|
104
81
|
it 'has a success state' do
|
|
105
82
|
expect(response.state).to eq :success
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: response_state
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- alexpeachey
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|