response_state 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49640a1d8e13c04e6904e1672de5233b74e10577
4
- data.tar.gz: 5ecc66ed44412cedb76b30afc5b8021d1d2ef96d
3
+ metadata.gz: bf386174f6638df5e17ded37f76a1cef1cf87eec
4
+ data.tar.gz: 76903168615aafedf6697076a572478c2dc447eb
5
5
  SHA512:
6
- metadata.gz: 5104ca4e50e10cf325155e4c6e5108f353a8dd91a7a2dfd0e7775b7054def88814ec3b9dd27dac8fbdbeef61a2fdb6392fa1b01d0bb58a47f8adab96b8892bab
7
- data.tar.gz: dfcc5f13dd9c9b6d8fa60ce39363d2a4f7fece15c17888ea2bcdca0f9158dcda349e2786e4e473a3405ed276003240d69bb26069fd93f87438696d5ed6c6a4f5
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. You must also indicated the valid response states
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, valid_states=nil)
21
- valid_states ||= self.class.valid_states
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
@@ -1,3 +1,3 @@
1
1
  module ResponseState
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
  require 'ostruct'
3
3
 
4
4
  class MyService < ResponseState::Service
5
- response_states :success, :failure
6
5
  attr_reader :object, :pass
7
6
 
8
7
  def initialize(object, pass)
@@ -15,16 +15,16 @@ module ResponseState
15
15
  end
16
16
  end
17
17
 
18
- describe '.response_states' do
19
- it 'sets the valid response states' do
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 '.valid_states' do
26
- it 'defaults to []' do
27
- expect(Service.valid_states).to eq []
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.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-08-04 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler