dryer_services 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +91 -0
- data/dryer_services.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc730ff5d7dc75aed6d18e68f50f2de371535271974ed5d12d6d08ad3cf5207
|
4
|
+
data.tar.gz: 61f6a0e307a4d0b9e7104a870b53ffc234f743515e67ef9a6232ce6f7a15648f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ada4c583fe9f5eded4af12b4bdda7e003376ae55d79de3d3609d9ee19d3d0e4c56483317139e9cee6fa43bf05a0af4df7a53741f01ca7dae6c97999e9649cd6
|
7
|
+
data.tar.gz: 9cbf2836e9b0dde5377c7fc576300dc0894bce93697f4649445f238235b42daf1366820aa8535ec0da1b228fc5c67192b564cbd1b13601d9461105793d2409b1
|
data/README.md
CHANGED
@@ -1 +1,92 @@
|
|
1
1
|
# Dryer Services
|
2
|
+
A gem providing base classes for composable service object that leverages the
|
3
|
+
[dry-monads](https://dry-rb.org/gems/dry-monads/1.6/) gem for error handling.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
add the following to you gemfile
|
7
|
+
```
|
8
|
+
gem "dryer_services"
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
This gem provides two base classes, `SimpleService` and `ResultService`.
|
13
|
+
|
14
|
+
Both classes provide a single class method `call`, and require the inheriting class to
|
15
|
+
define the instance methods `initialize` and `call`
|
16
|
+
|
17
|
+
`SimpleService` is meant to be used for operations that have no failure modes,
|
18
|
+
while `ResultsService` is meant to be used for operations that may fail.
|
19
|
+
|
20
|
+
### SimpleService Example
|
21
|
+
|
22
|
+
```
|
23
|
+
class Add < Dryer::Services::SimpleService
|
24
|
+
def initialize(a, b)
|
25
|
+
@a = a
|
26
|
+
@b = b
|
27
|
+
end
|
28
|
+
|
29
|
+
def call
|
30
|
+
a + b
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
attr_reader :a, :b
|
35
|
+
end
|
36
|
+
|
37
|
+
Add.call(1,2) # returns 3
|
38
|
+
```
|
39
|
+
|
40
|
+
### ResultService Example
|
41
|
+
|
42
|
+
Result Service wraps the value returned from `call` in a `Dry::Monad::Result`.
|
43
|
+
If the return value is an Error, it will return a Failure. If the return value
|
44
|
+
is already a `Dry::Monad::Result`, it will not wrap the result, otherwise it
|
45
|
+
will wrap the result in a `Dry::Monads::Success`
|
46
|
+
|
47
|
+
```
|
48
|
+
class Divide < Dryer::Services::ResultService
|
49
|
+
def initialize(a, b)
|
50
|
+
@a = a
|
51
|
+
@b = b
|
52
|
+
end
|
53
|
+
|
54
|
+
def call
|
55
|
+
if b == 0
|
56
|
+
StandardError.new("Can not divide by zero")
|
57
|
+
else
|
58
|
+
a/b
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
attr_reader :a, :b
|
64
|
+
end
|
65
|
+
|
66
|
+
Add.call(4,2) # returns Dry::Monads::Success(2)
|
67
|
+
Add.call(4,0) # returns Dry::Monads::Failure("Can not divide by zero")
|
68
|
+
```
|
69
|
+
|
70
|
+
## Advantages
|
71
|
+
Using the Service pattern can help to make code more modular, and make it easier
|
72
|
+
to separate data modeling from transformations.
|
73
|
+
|
74
|
+
# Development
|
75
|
+
This gem is set up to be developed using [Nix](https://nixos.org/)
|
76
|
+
Once you have nix installed you can run
|
77
|
+
`make env`
|
78
|
+
to enter the development environment. Then run `make` to see other available
|
79
|
+
commands
|
80
|
+
|
81
|
+
If you don't want to use nix, all the scripts can be run directly from the
|
82
|
+
`scripts` directory.
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
Please create a github issue to report any problems using the Gem.
|
86
|
+
Thanks for your help in making testing easier for everyone!
|
87
|
+
|
88
|
+
## Versioning
|
89
|
+
Dryer Services follows Semantic Versioning 2.0 as defined at https://semver.org.
|
90
|
+
|
91
|
+
## License
|
92
|
+
This code is free to use under the terms of the MIT license.
|
data/dryer_services.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dryer_services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bernier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
rubygems_version: 3.4.
|
92
|
+
rubygems_version: 3.4.22
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: A service object leveraging the dry-monads gem
|