civil_service 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/lib/civil_service/result.rb +6 -1
- data/lib/civil_service/version.rb +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: 7852028628b07b8e1cb66afa9b93551f7b8d1c617ba3161adf20d05355e53da4
|
4
|
+
data.tar.gz: 414e35fa95fadd0b904c82699958279c029bc2047f7c21b46631beed0a80ae3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7752f150f11331751baf46f61c69cdf338196edc9ff5b4e86e42035c1d524c3d3bffa54d1c58a08f869b27ec05219cfe142c334a5582ed53ae4b8380e802fdd9
|
7
|
+
data.tar.gz: 10c2096c1ff5e6b967969d00be432d72c6a3811dbd7bdc6ee7d4b04fbea4da52676cb0f5f1344fadb65e842f9b3b494cbe3c7ec1370c269d4f613d22dfe31888
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# Version 2.1.0 - September 25, 2019
|
2
|
+
|
3
|
+
* `CivilService::Result#errors` now always returns an Errors object even if it hasn't been
|
4
|
+
explicitly set.
|
5
|
+
|
1
6
|
# Version 2.0.0 - June 26, 2019
|
2
7
|
|
3
8
|
* BREAKING CHANGE: The behavior of `CivilService::Service#call` has changed when exceptions are
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,8 +26,10 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
CivilService::Service is really a pretty tiny class. It does, however, have some opinions that create a potentially-useful abstraction for app developers:
|
28
28
|
|
29
|
-
* When called, services always return a result object that responds to (at least) `#success?`, `#failure?`, and `#
|
29
|
+
* When called, services always return a result object that responds to (at least) `#success?`, `#failure?`, `#errors`, and `#exception`. This lets your code paths that call services be consistent and simple. (If you want to return more information as a result of running the service, it's easy to define a custom result class for your service.)
|
30
|
+
* What's the difference between `#errors` and `#exception`? `#errors` is an instance of `ActiveModel::Errors`, whereas `#exception` is an instance of an exception class (it's only present if an exception was raised inside the service call). If an exception is raised, the service result will respond true to `#failure?`, false to `#success?`, and the exception's message will be added to `#errors`, so most of the time you can ignore `#exception` - but it's there in case you need to dig into the details.
|
30
31
|
* Services include `ActiveModel::Validations` so they can easily do pre-flight checks. That means you can call `my_service.valid?` and `my_service.errors` just like you can for a model, and it also means that the service will fail if it's not valid.
|
32
|
+
* In addition to `#call`, which always returns a result object, services have a `#call!` method, which will raise a `CivilService::ServiceFailure` exception if the service fails, or pass through an exception if one is raised inside the service call. This might be easier in some workflows; for example, it will cause a rollback if used inside an ActiveRecord transaction block.
|
31
33
|
|
32
34
|
## Basic example
|
33
35
|
|
data/lib/civil_service/result.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class CivilService::Result
|
2
2
|
include ActiveModel::Model
|
3
|
-
attr_accessor :success, :
|
3
|
+
attr_accessor :success, :exception
|
4
|
+
attr_writer :errors
|
4
5
|
|
5
6
|
def self.success(attributes = {})
|
6
7
|
new(attributes.merge(success: true))
|
@@ -17,4 +18,8 @@ class CivilService::Result
|
|
17
18
|
def failure?
|
18
19
|
!success?
|
19
20
|
end
|
21
|
+
|
22
|
+
def errors
|
23
|
+
@errors ||= ActiveModel::Errors.new(self)
|
24
|
+
end
|
20
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civil_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nat Budin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|