service_pattern 0.0.6 → 0.0.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77863da179021d925441d0bf4a64fe8756ce925c45262523e7e34ff35e03956b
|
4
|
+
data.tar.gz: 815cac6f2393f6f92181a14fd311c565d63069e96c9aebc3827c315fa24d2832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 370ba577ae9fc3a77746e518502c71d872e22ee49ddab016124c1c3105a48b8cc6667e22ea4f9369f4224b9de298c3ff04940031eb86aeb1e8d9f8890fcb0289
|
7
|
+
data.tar.gz: a80e81f4419b97fa4721a747a180729484264635d4feff4edb572d5e4dabda6a11d86928d1ba5fb1fcf11c9bd94734d82c9449bce4c8ee7d762af3c5e47de19c
|
data/lib/service_pattern.rb
CHANGED
@@ -7,6 +7,14 @@ class ServicePattern::Response
|
|
7
7
|
@success = !errors || errors.empty?
|
8
8
|
end
|
9
9
|
|
10
|
+
def error_messages
|
11
|
+
@error_messages ||= @errors.map(&:message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_types
|
15
|
+
@error_types ||= @errors.map(&:type).reject(&:blank?)
|
16
|
+
end
|
17
|
+
|
10
18
|
def success?
|
11
19
|
@success
|
12
20
|
end
|
@@ -35,8 +35,16 @@ class ServicePattern::Service
|
|
35
35
|
|
36
36
|
def self.fail!(errors)
|
37
37
|
errors = [errors] unless errors.is_a?(Array)
|
38
|
-
|
38
|
+
errors = errors.map do |error|
|
39
|
+
error = ServicePattern::FailError.new(message: error) unless error.is_a?(ServicePattern::FailError)
|
40
|
+
error
|
41
|
+
end
|
42
|
+
|
43
|
+
error_messages = errors.map(&:message)
|
44
|
+
|
45
|
+
error = ServicePattern::FailedError.new(error_messages.join(". "))
|
39
46
|
error.errors = errors
|
47
|
+
|
40
48
|
raise error
|
41
49
|
end
|
42
50
|
|
@@ -48,7 +56,9 @@ class ServicePattern::Service
|
|
48
56
|
raise NoMethodError, "You should implement the `execute` method on your service"
|
49
57
|
end
|
50
58
|
|
51
|
-
def fail!(errors)
|
59
|
+
def fail!(errors, type: nil)
|
60
|
+
errors = [ServicePattern::FailError.new(message: errors, type: type)] if type
|
61
|
+
|
52
62
|
ServicePattern::Service.fail!(errors)
|
53
63
|
end
|
54
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_pattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ServicePattern for Ruby on Rails.
|
14
14
|
email:
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- Rakefile
|
23
23
|
- lib/service_pattern.rb
|
24
|
+
- lib/service_pattern/fail_error.rb
|
24
25
|
- lib/service_pattern/failed_error.rb
|
25
26
|
- lib/service_pattern/response.rb
|
26
27
|
- lib/service_pattern/service.rb
|