dryer_services 1.0.0 → 1.1.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 +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba13ef8192d27da5fda2b291efb698e4fc11638b2e46e8faad4108aeba7129fa
|
4
|
+
data.tar.gz: 6624e849a4b7c36ae41900bf41aee44d5303fb1443f0654d49a13b3bce60450d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d01980e96ed796b2b0c292fd1763a579daddb0aaf03f5ad74ddcf6d25a76109c9481d49b9cd00aa6c1496df95d13d6d6addd4d6784dff33cdbdced444275f028
|
7
|
+
data.tar.gz: 5a9447e7d141ba65dc7398e55ba22a35f47330d8c4b6f70f9ec12619aa513e472167eda4142a77f7dc421781d58bdef12dbe66339e2d0d7108d982102a236fa0
|
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
|
+
StandError.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.1.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
|