single_action_service 0.1.1 → 0.2.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 +64 -12
- data/lib/single_action_service/exceptions.rb +13 -0
- data/lib/single_action_service/result.rb +6 -0
- data/lib/single_action_service/version.rb +1 -1
- data/lib/single_action_service.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4d4eb3fec3dc55edbf5aab8460812be72f6ff3f088a75a530b42a00ad904b1c
|
4
|
+
data.tar.gz: a1f12498a8534810f69ba23df56ceff9cc3d3f2ea3cbea91a0429d61bac70551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c192083a4ffba6795f46eb684b9f7e1b3b6805f0c1a87d889c78a64c73aba4c4bed6e9a1daa4fb84a9bfd97a5160dabe3d5b982a43a3f0f656f40d8299f24c1
|
7
|
+
data.tar.gz: ceced5347723cc62ea5f4fe30b8721a6e295ebc8163d5c075cdc424f3b9b1b321d79ba00e64ceace8634f6d60732e7536ec3dab477989bb5f0cbba0390240b01
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# SingleActionService
|
2
2
|
|
3
|
-
|
3
|
+
[](https://rubygems.org/gems/single_action_service)
|
4
4
|
|
5
|
-
|
5
|
+
Implementation of a Service Object pattern in Ruby.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,22 +22,74 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
1. Inherit:
|
26
|
+
```ruby
|
27
|
+
class MySingleAction < SingleActionService::Base
|
28
|
+
end
|
29
|
+
```
|
30
|
+
2. Create a constructor with parameters or pass them to call:
|
31
|
+
```ruby
|
32
|
+
# Usually a data source is passed
|
33
|
+
def initialize(x, y)
|
34
|
+
@x = x
|
35
|
+
@y = y
|
36
|
+
end
|
37
|
+
```
|
38
|
+
or
|
39
|
+
```ruby
|
40
|
+
def call(x, y)
|
41
|
+
end
|
42
|
+
```
|
43
|
+
3. Perform the action:
|
44
|
+
```ruby
|
45
|
+
sum = x + y
|
46
|
+
```
|
47
|
+
4. Return the result:
|
48
|
+
```ruby
|
49
|
+
success(sum)
|
50
|
+
```
|
51
|
+
or without data
|
52
|
+
```ruby
|
53
|
+
success
|
54
|
+
```
|
55
|
+
5. Or return an error:
|
56
|
+
```ruby
|
57
|
+
return error(sum, code: 1) unless sum.positive?
|
58
|
+
```
|
59
|
+
The first parameter is any data (optional).
|
28
60
|
|
29
|
-
|
61
|
+
The 'code' parameter is used to identify the error (optional).
|
30
62
|
|
31
|
-
|
63
|
+
6. You can process the result received from the service as follows:
|
64
|
+
```ruby
|
65
|
+
action = MySingleAction.new
|
66
|
+
result = action.call(1,2)
|
67
|
+
# or uses result.error?
|
68
|
+
if result.success?
|
69
|
+
result.data
|
70
|
+
else
|
71
|
+
{
|
72
|
+
error_code: result.error_code,
|
73
|
+
data: result.data
|
74
|
+
}
|
75
|
+
end
|
76
|
+
```
|
77
|
+
or uses data! if you want to throw an exception
|
78
|
+
```ruby
|
79
|
+
begin
|
80
|
+
result = MySingleAction.new.call(1,2).data!
|
81
|
+
rescue SingleActionService::InvalidResult => e
|
82
|
+
{
|
83
|
+
error_code: e.result.error_code,
|
84
|
+
data: e.result.data
|
85
|
+
}
|
86
|
+
end
|
87
|
+
```
|
32
88
|
|
33
89
|
## Contributing
|
34
90
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sequenia/single_action_service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
92
|
|
37
93
|
## License
|
38
94
|
|
39
95
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the SingleActionService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/single_action_service/blob/master/CODE_OF_CONDUCT.md).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: single_action_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bazov Peter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- bin/setup
|
73
73
|
- lib/single_action_service.rb
|
74
74
|
- lib/single_action_service/base.rb
|
75
|
+
- lib/single_action_service/exceptions.rb
|
75
76
|
- lib/single_action_service/result.rb
|
76
77
|
- lib/single_action_service/version.rb
|
77
78
|
- single_action_service.gemspec
|
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
- !ruby/object:Gem::Version
|
95
96
|
version: '0'
|
96
97
|
requirements: []
|
97
|
-
rubygems_version: 3.0.
|
98
|
+
rubygems_version: 3.0.4
|
98
99
|
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: Single Action Service
|