responsive_service 0.1.0 → 0.1.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 +4 -4
- data/README.md +39 -8
- data/lib/responsive_service/version.rb +1 -1
- data/responsive_service.gemspec +4 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5613d9e5f1add88d5b60cbe10659ac1fe968d815
|
4
|
+
data.tar.gz: eb8e0e330a4d96a647a7bf72aa5c5146e4e328ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 739afba739f4c4beceb23d53e0cb52c8817240503b6d0eea4955a90df32e6e9187328e4830f0ee6c7b5d54efda1418371f3c4138ea1c81cf3d6499eb8d6d9724
|
7
|
+
data.tar.gz: 7dcc8dd1aa178e2519ff7c0e9e34dbdd36955b81c1e56f75c1547923a0daaa7874df6c2cecd9df3c1a7a51689e11e9d9beed330bbde720997f216f6e277ebfac
|
data/README.md
CHANGED
@@ -19,30 +19,61 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
### ResponsiveService
|
23
|
+
|
22
24
|
Create a service class, either your own or feel free to subclass from `ResponsiveService::ResponsiveService`.
|
23
25
|
|
24
26
|
```ruby
|
25
27
|
class MyService < ResponsiveService::ResponsiveService
|
26
28
|
def call(&block)
|
27
29
|
# do some work
|
28
|
-
yield ResponsiveService::
|
30
|
+
yield ResponsiveService::Response.new(:success)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
```
|
32
34
|
|
33
35
|
You must implement a `call` method if you subclass `ResponsiveService::ResponsiveService`.
|
34
|
-
Your call method should yield with a `ResponsiveService::
|
36
|
+
Your call method should yield with a `ResponsiveService::Response`.
|
37
|
+
|
38
|
+
### Response
|
39
|
+
|
40
|
+
A `ResponsiveService::Response` can take up to 4 arguments but must at least have the first argument which is the type of the response. In addition it can take a message, a context, and a set of valid states. The message by convention should
|
41
|
+
be a string but there are no restrictions. The context can be any object. The valid states should be an array of symbols
|
42
|
+
that are the allowed states. An exception will be thrown if initialized with a type of response that is not in the valid states if a set of valid states was specified.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
response = Response.new(:success, 'You win!', {an_important_value: 'some value'})
|
46
|
+
response.type # :success
|
47
|
+
response.message # 'You win!'
|
48
|
+
response.context # {an_important_value: 'some value'}
|
49
|
+
|
50
|
+
response.success { puts 'I succeeded' } # I succeeded
|
51
|
+
response.failure { puts 'I failed' } # nil
|
35
52
|
|
36
|
-
|
37
|
-
|
53
|
+
response = Response.new(:foo, 'FOO!', {}, [:success, :failure])
|
54
|
+
# exception => Invalid type of response: foo
|
55
|
+
|
56
|
+
response = Response.new(:success, '', {}, [:success, :failure])
|
57
|
+
response.foo { puts 'Not going to work' }
|
58
|
+
# exception => NoMethodError: undefined method `foo'
|
59
|
+
```
|
60
|
+
|
61
|
+
You can also choose to subclass `ResponsiveService::Response` and define valid states for all instances of that class.
|
38
62
|
|
39
63
|
```ruby
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
64
|
+
class MyResponse < ResponsiveService::Response
|
65
|
+
valid_states :success, :failure
|
66
|
+
end
|
67
|
+
|
68
|
+
response = MyResponse.new(:success)
|
69
|
+
response.success { puts 'I succeeded' } # I succeeded
|
70
|
+
response.failure { puts 'I failed' } # nil
|
71
|
+
response.foo { puts 'Not going to work' }
|
72
|
+
# exception => NoMethodError: undefined method `foo'
|
44
73
|
```
|
45
74
|
|
75
|
+
### Your service API
|
76
|
+
|
46
77
|
Your service can now be used as such:
|
47
78
|
|
48
79
|
```ruby
|
data/responsive_service.gemspec
CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'responsive_service'
|
8
8
|
spec.version = ResponsiveService::VERSION
|
9
9
|
spec.authors = ['alexpeachey']
|
10
|
-
spec.email = ['alex.peachey@
|
11
|
-
spec.description = 'Easy to use
|
12
|
-
spec.summary = 'Easy to use
|
13
|
-
spec.homepage = 'http://github.com/
|
10
|
+
spec.email = ['alex.peachey@originate.com']
|
11
|
+
spec.description = 'Easy to use response state pattern'
|
12
|
+
spec.summary = 'Easy to use response state pattern'
|
13
|
+
spec.homepage = 'http://github.com/Originate/response_state'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responsive_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,9 +66,9 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Easy to use
|
69
|
+
description: Easy to use response state pattern
|
70
70
|
email:
|
71
|
-
- alex.peachey@
|
71
|
+
- alex.peachey@originate.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -87,7 +87,7 @@ files:
|
|
87
87
|
- spec/lib/responsive_service/response_spec.rb
|
88
88
|
- spec/lib/responsive_service/responsive_service_spec.rb
|
89
89
|
- spec/spec_helper.rb
|
90
|
-
homepage: http://github.com/
|
90
|
+
homepage: http://github.com/Originate/response_state
|
91
91
|
licenses:
|
92
92
|
- MIT
|
93
93
|
metadata: {}
|
@@ -107,10 +107,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.2.
|
110
|
+
rubygems_version: 2.2.2
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
|
-
summary: Easy to use
|
113
|
+
summary: Easy to use response state pattern
|
114
114
|
test_files:
|
115
115
|
- spec/lib/responsive_service/response_spec.rb
|
116
116
|
- spec/lib/responsive_service/responsive_service_spec.rb
|