servizio 0.4.2 → 0.5.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
  SHA1:
3
- metadata.gz: 69822bf509a344a55714acfc9a8647aa6c3564d4
4
- data.tar.gz: 4a1495016859c949dbd38c0875ae0730ac842f13
3
+ metadata.gz: 4f6ef5087222978f6a2ed8694736f9b00ff443e0
4
+ data.tar.gz: bf7588a9ee247737b42ffa1c3eea7682fc2ffcd7
5
5
  SHA512:
6
- metadata.gz: 5c889deadb210d2329da6eb8054a7d87e51d2900875b2ff8d85fc6f34006986004e2385cdb2ca4fdf8ca839e918ea02262797c873bde8da7a8ef044d2dcbd665
7
- data.tar.gz: 251430d80518a02a14d06d0879e10cbfcc084ee4557334cd56e7c7d8e527c71ae01cf716654c131a8e6e689259480cd4abc0d4dbc642aeb656e96f9feb27580b
6
+ metadata.gz: 9e7a3eb2938273767c17dc452a7a0c41935cd7558695fdaf2bb2c4b2eeadf2836acb816d61fa6553371b633225d74062e524aea43b4b8c6cec76549100e98ea3
7
+ data.tar.gz: 2fa0ce56e5c20a965e20f15b7f53450783abba148ca7d79321ee2051eb6ab086d8f2b6010040619645d056e6c961411ced76e162ab556ca2b2835cb2b02a64af
@@ -17,10 +17,19 @@ class Servizio::Service
17
17
  super ? super : "__anonymous_servizio_service_class__"
18
18
  end
19
19
 
20
- # shortcut to call operations, which returns the result and/or throws errors
20
+ # shortcut to call operations, which returns the result or nik
21
21
  def self.call(*args)
22
22
  operation = self.new(*args)
23
23
 
24
+ if operation.valid? && operation.call!.succeeded?
25
+ operation.result
26
+ end
27
+ end
28
+
29
+ # shortcut to call operations, which returns the result and/or throws errors
30
+ def self.call!(*args)
31
+ operation = self.new(*args)
32
+
24
33
  if operation.valid?
25
34
  if operation.call!.succeeded?
26
35
  operation.result
@@ -1,3 +1,3 @@
1
1
  module Servizio
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -25,15 +25,33 @@ describe Servizio::Service do
25
25
  expect(service.call(summands: [1,2])).to eq(3)
26
26
  end
27
27
 
28
+ context "if the operation is invalid" do
29
+ subject { service.call }
30
+
31
+ it { is_expected.to be_nil }
32
+ end
33
+
34
+ context "if the operation did not succeeded" do
35
+ subject { service.call(summands: [1,2], should_fail: true) }
36
+
37
+ it { is_expected.to be_nil }
38
+ end
39
+ end
40
+
41
+ describe ".call!" do
42
+ it "creates an instance of the service, calls it with the given arguments and returns the result" do
43
+ expect(service.call!(summands: [1,2])).to eq(3)
44
+ end
45
+
28
46
  context "if the operation is invalid" do
29
47
  it "raises an error" do
30
- expect { service.call }.to raise_error(Servizio::Service::OperationInvalidError)
48
+ expect { service.call! }.to raise_error(Servizio::Service::OperationInvalidError)
31
49
  end
32
50
  end
33
51
 
34
52
  context "if the operation did not succeeded" do
35
53
  it "raises an error" do
36
- expect { service.call(summands: [1,2], should_fail: true) }.to raise_error(Servizio::Service::OperationFailedError)
54
+ expect { service.call!(summands: [1,2], should_fail: true) }.to raise_error(Servizio::Service::OperationFailedError)
37
55
  end
38
56
  end
39
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servizio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel