serviz 0.3.0 → 0.4.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: c6a85c4e77120f5d8ad63ede420fc521605ae687ccd6f330e882656dd3f1d0bf
4
- data.tar.gz: f9c6b468e1ec02c6ecc342d5673a855bb5c56c3d8f040d8740c4722aa8789eb5
3
+ metadata.gz: 996c470857cef304582ab365344d4918e3ee35c5baacd64b2d5b068a2b323707
4
+ data.tar.gz: 3c77f8932bee0fb30543975094f8d1ce025e8455ca031e028b9b97f1a134835d
5
5
  SHA512:
6
- metadata.gz: 99df6f74445b1699e0ad55c5816dfdf858b788456fd241d9141015f755f9afb2227b0388ab5b35a6278c2a1672b21018db7d4605853159fbb50daec9b9876938
7
- data.tar.gz: 2a6fcecc5ffc6726d402b053a8a6795d201ac531b2bb69602d1330cb3fde7148072a0095a341ca6e41a98c1c43103ed688148a1a92832ec07808eeed825e1c47
6
+ metadata.gz: d5b429c64601d9a4b9f829cb723e99c995659c64cf5901eb34240047ee2611ab7b10bd2aa27a2ab54339e99c6b63466deab752d5998f3a74efd528d4d16afb9a
7
+ data.tar.gz: 7a89f2b36fe02e78d75cec00280659ae0fc7f740730a373c07e62b444534b844a784b1b828acb0291b9f8328833466d66bcbb1fd476f85337aaefab6604cc7ab
@@ -1,3 +1,3 @@
1
1
  module Serviz
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/serviz.rb CHANGED
@@ -14,6 +14,8 @@ module Serviz
14
14
  end
15
15
  instance.call
16
16
 
17
+ yield(instance) if block_given?
18
+
17
19
  instance
18
20
  end
19
21
 
@@ -25,12 +27,18 @@ module Serviz
25
27
  @errors ||= []
26
28
  end
27
29
 
30
+ def error_messages(separator = ", ")
31
+ errors.join(separator)
32
+ end
33
+
28
34
  def success?
29
35
  !failure?
30
36
  end
37
+ alias_method :ok?, :success?
31
38
 
32
39
  def failure?
33
40
  errors.any?
34
41
  end
42
+ alias_method :error?, :failure?
35
43
  end
36
44
  end
data/spec/serviz_spec.rb CHANGED
@@ -4,8 +4,10 @@ RSpec.describe Serviz::Base do
4
4
  operation = RegisterUser.call(user)
5
5
 
6
6
  expect(operation.success?).to eq true
7
+ expect(operation.ok?).to eq true
7
8
  expect(operation.failure?).to eq false
8
9
  expect(operation.errors).to be_empty
10
+ expect(operation.error_messages).to eq ''
9
11
  expect(operation.result).to eq user
10
12
  end
11
13
 
@@ -14,7 +16,9 @@ RSpec.describe Serviz::Base do
14
16
 
15
17
  expect(operation.success?).to eq false
16
18
  expect(operation.failure?).to eq true
19
+ expect(operation.error?).to eq true
17
20
  expect(operation.errors).not_to be_empty
21
+ expect(operation.error_messages).to eq 'No user!'
18
22
  expect(operation.result).to eq nil
19
23
  end
20
24
 
@@ -28,4 +32,10 @@ RSpec.describe Serviz::Base do
28
32
  expect(operation.success?).to eq true
29
33
  expect(operation.result).to eq(['foo', 'bar'])
30
34
  end
35
+
36
+ it "accepts a block" do
37
+ expect {
38
+ RegisterUser.call { |operation| puts 'error!' if operation.failure? }
39
+ }.to output("error!\n").to_stdout
40
+ end
31
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler