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 +4 -4
- data/lib/servizio/service.rb +10 -1
- data/lib/servizio/version.rb +1 -1
- data/spec/servizio/service_spec.rb +20 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f6ef5087222978f6a2ed8694736f9b00ff443e0
|
4
|
+
data.tar.gz: bf7588a9ee247737b42ffa1c3eea7682fc2ffcd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e7a3eb2938273767c17dc452a7a0c41935cd7558695fdaf2bb2c4b2eeadf2836acb816d61fa6553371b633225d74062e524aea43b4b8c6cec76549100e98ea3
|
7
|
+
data.tar.gz: 2fa0ce56e5c20a965e20f15b7f53450783abba148ca7d79321ee2051eb6ab086d8f2b6010040619645d056e6c961411ced76e162ab556ca2b2835cb2b02a64af
|
data/lib/servizio/service.rb
CHANGED
@@ -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
|
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
|
data/lib/servizio/version.rb
CHANGED
@@ -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
|
+
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-
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|