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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0155a0d0cbcf7c649725deedc1eb51e64ebe4f6a5f77ea4fbb6022768598afd
4
- data.tar.gz: 82f50992961ad30130760307434340c180a459052fe4fa04c1bd295472be8a19
3
+ metadata.gz: 7852028628b07b8e1cb66afa9b93551f7b8d1c617ba3161adf20d05355e53da4
4
+ data.tar.gz: 414e35fa95fadd0b904c82699958279c029bc2047f7c21b46631beed0a80ae3f
5
5
  SHA512:
6
- metadata.gz: ec1adf3b57089d4849ca5ce70b2ed8b9938ee03aabd55b3e0952ee0d3cb0734e87bac765794b023c83b80276312c1e754a3ce517a97af9eaed80ac1f94e242b0
7
- data.tar.gz: ff3622cb3f407734e8adfe0b4f844d9db437f72a642b17669920339027bdd62cf1a0aaf27d11fa4e35bcfdb2c878572579f1066cb5ec25567a6d0253dc6f32ab
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- civil_service (2.0.0)
4
+ civil_service (2.1.0)
5
5
  activemodel (>= 3.0.0)
6
6
 
7
7
  GEM
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 `#errors`. 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.)
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
 
@@ -1,6 +1,7 @@
1
1
  class CivilService::Result
2
2
  include ActiveModel::Model
3
- attr_accessor :success, :errors, :exception
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
@@ -1,3 +1,3 @@
1
1
  module CivilService
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  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.0.0
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-06-26 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel