service_pattern 0.0.7 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/service_pattern/response.rb +1 -1
- data/lib/service_pattern/service.rb +27 -19
- data/lib/service_pattern/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a0cc423721d1d11a5e300f3719b01dcd3eba89dcad83d97cc168372acc01593
|
4
|
+
data.tar.gz: de7dcffe6dd6ac6bda7d5195e75622ca1bda3c37b3cca394ca11e2a827445da6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c304984c8080f2234c44cb07f96566f8830ca7a17e1564f76f7d5f52183dd0317c4584dc36a990ae6a7a97f77e1719d8fcb3fb36463be9e62c694d6e69521210
|
7
|
+
data.tar.gz: 0a168abccb3b302f15987e67515214e16565e4ba654f8c7079131eeeb2cbbb2ddeb3976ce4b0645215278df8c0f180feeaba9f36eb511d796624f22823a79eaa
|
@@ -6,7 +6,7 @@ class ServicePattern::Service
|
|
6
6
|
can_execute_response = service.can_execute?
|
7
7
|
ServicePattern::Service.fail!(can_execute_response.errors) unless can_execute_response.success?
|
8
8
|
|
9
|
-
service.
|
9
|
+
service.perform
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.call(*args, &blk)
|
@@ -14,32 +14,23 @@ class ServicePattern::Service
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.execute(*args, &blk)
|
17
|
-
|
18
|
-
|
19
|
-
can_execute_response = service.can_execute?
|
20
|
-
return can_execute_response unless can_execute_response.success?
|
21
|
-
|
22
|
-
service.execute
|
23
|
-
rescue ServicePattern::FailedError => e
|
24
|
-
ServicePattern::Response.new(errors: e.errors)
|
17
|
+
new(*args, &blk).execute
|
25
18
|
end
|
26
19
|
|
27
20
|
def self.execute!(*args, &blk)
|
28
|
-
|
29
|
-
can_execute_response = service.can_execute?
|
30
|
-
ServicePattern::Service.fail!(can_execute_response.errors) unless can_execute_response.success?
|
31
|
-
response = service.execute
|
32
|
-
ServicePattern::Service.fail!(response.errors) unless response.success?
|
33
|
-
response.result
|
21
|
+
new(*args, &blk).execute!
|
34
22
|
end
|
35
23
|
|
36
|
-
def self.
|
24
|
+
def self.convert_errors(errors)
|
37
25
|
errors = [errors] unless errors.is_a?(Array)
|
38
|
-
errors
|
26
|
+
errors.map do |error|
|
39
27
|
error = ServicePattern::FailError.new(message: error) unless error.is_a?(ServicePattern::FailError)
|
40
28
|
error
|
41
29
|
end
|
30
|
+
end
|
42
31
|
|
32
|
+
def self.fail!(errors)
|
33
|
+
errors = convert_errors(errors)
|
43
34
|
error_messages = errors.map(&:message)
|
44
35
|
|
45
36
|
error = ServicePattern::FailedError.new(error_messages.join(". "))
|
@@ -52,8 +43,25 @@ class ServicePattern::Service
|
|
52
43
|
succeed!
|
53
44
|
end
|
54
45
|
|
55
|
-
def execute
|
56
|
-
|
46
|
+
def execute
|
47
|
+
can_execute_response = can_execute?
|
48
|
+
return can_execute_response unless can_execute_response.success?
|
49
|
+
|
50
|
+
perform
|
51
|
+
rescue ServicePattern::FailedError => e
|
52
|
+
ServicePattern::Response.new(errors: e.errors)
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute!
|
56
|
+
can_execute_response = can_execute?
|
57
|
+
ServicePattern::Service.fail!(can_execute_response.errors) unless can_execute_response.success?
|
58
|
+
response = perform
|
59
|
+
ServicePattern::Service.fail!(response.errors) unless response.success?
|
60
|
+
response.result
|
61
|
+
end
|
62
|
+
|
63
|
+
def perform(*_args)
|
64
|
+
raise NoMethodError, "You should implement the `perform` method on your service"
|
57
65
|
end
|
58
66
|
|
59
67
|
def fail!(errors, type: nil)
|
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:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ServicePattern for Ruby on Rails.
|
14
14
|
email:
|
@@ -39,14 +39,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 2.5.0
|
43
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
|
-
rubygems_version: 3.
|
49
|
+
rubygems_version: 3.1.6
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: ServicePattern for Ruby on Rails.
|