service_pattern 1.0.4 → 1.0.7
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 +6 -0
- data/lib/service_pattern/service.rb +46 -9
- data/lib/service_pattern/version.rb +1 -1
- data/lib/service_pattern.rb +2 -0
- metadata +144 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7ec1a1bdbbf5c1579ff34c0acdf54220b88ce43e845a4dcbc99ab930f8a6f49
|
4
|
+
data.tar.gz: fb09e4e6237d5eb07f028fab2968bbe178775b4b1fdae3d34a23550139b2c7cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8410e3bbde7f41d0f66ac4d7e4acc347901259ae4bd4817cdf66f1b872380915b3579359579ce2c137e14436d0d96e0b65360569003488ea4a9455b76513e447
|
7
|
+
data.tar.gz: 9802cae2a1eca34b23962af137890f226dfb274d2bd219d5aaf8d23fd6c9225423406525acd7720c94e6332a4ca101dfc75257781a6399db310865a95ee1e1df
|
@@ -1,6 +1,12 @@
|
|
1
1
|
class ServicePattern::Response
|
2
2
|
attr_reader :errors, :result
|
3
3
|
|
4
|
+
def self.check_response!(service, response)
|
5
|
+
return if response.is_a?(ServicePattern::Response)
|
6
|
+
|
7
|
+
raise ServicePattern::InvalidResponseError, "Expected a ServicePattern::Response from #{service.class.name} but it was instead: #{response.class.name}"
|
8
|
+
end
|
9
|
+
|
4
10
|
def initialize(errors: [], result: nil)
|
5
11
|
@errors = ServicePattern::Service.convert_errors(errors)
|
6
12
|
@result = result
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ServicePattern::Service
|
2
2
|
# The same as execute but doesn't catch FailedError so they are passed on to the parent service call
|
3
|
-
def self.chain(*args, &blk)
|
4
|
-
service = new(*args, &blk)
|
3
|
+
def self.chain(*args, **opts, &blk)
|
4
|
+
service = new(*args, **opts, &blk)
|
5
5
|
|
6
6
|
can_execute_response = service.can_execute?
|
7
7
|
ServicePattern::Service.fail!(can_execute_response.errors) unless can_execute_response.success?
|
@@ -9,16 +9,16 @@ class ServicePattern::Service
|
|
9
9
|
service.perform
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.call(*args, &blk)
|
13
|
-
execute(*args, &blk)
|
12
|
+
def self.call(*args, **opts, &blk)
|
13
|
+
execute(*args, **opts, &blk)
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.execute(*args, &blk)
|
17
|
-
new(*args, &blk).execute
|
16
|
+
def self.execute(*args, **opts, &blk)
|
17
|
+
new(*args, **opts, &blk).execute
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.execute!(*args, &blk)
|
21
|
-
new(*args, &blk).execute!
|
20
|
+
def self.execute!(*args, **opts, &blk)
|
21
|
+
new(*args, **opts, &blk).execute!
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.convert_errors(errors)
|
@@ -39,6 +39,40 @@ class ServicePattern::Service
|
|
39
39
|
raise error
|
40
40
|
end
|
41
41
|
|
42
|
+
def self.arguments(*arguments)
|
43
|
+
arguments.each do |argument_name|
|
44
|
+
argument argument_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.argument(argument_name, **args)
|
49
|
+
attr_accessor argument_name
|
50
|
+
|
51
|
+
@arguments ||= {}
|
52
|
+
@arguments[argument_name] ||= {}
|
53
|
+
|
54
|
+
args.each do |key, value|
|
55
|
+
if key == :default
|
56
|
+
@arguments[argument_name][key] = value
|
57
|
+
else
|
58
|
+
raise ArgumentError, "Invalid argument: #{argument_name}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize(**args)
|
64
|
+
arguments = self.class.instance_variable_get(:@arguments)
|
65
|
+
arguments&.each do |argument_name, argument_options|
|
66
|
+
raise ArgumentError, "missing keyword: #{argument_name}" if !args.key?(argument_name) && !argument_options.key?(:default)
|
67
|
+
end
|
68
|
+
|
69
|
+
args.each do |key, value|
|
70
|
+
raise ArgumentError, "unknown keyword: #{key}" unless arguments&.key?(key)
|
71
|
+
|
72
|
+
__send__("#{key}=", value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
42
76
|
def can_execute?
|
43
77
|
succeed!
|
44
78
|
end
|
@@ -47,7 +81,9 @@ class ServicePattern::Service
|
|
47
81
|
can_execute_response = can_execute?
|
48
82
|
return can_execute_response unless can_execute_response.success?
|
49
83
|
|
50
|
-
perform
|
84
|
+
response = perform
|
85
|
+
ServicePattern::Response.check_response!(self, response)
|
86
|
+
response
|
51
87
|
rescue ServicePattern::FailedError => e
|
52
88
|
ServicePattern::Response.new(errors: e.errors)
|
53
89
|
end
|
@@ -56,6 +92,7 @@ class ServicePattern::Service
|
|
56
92
|
can_execute_response = can_execute?
|
57
93
|
ServicePattern::Service.fail!(can_execute_response.errors) unless can_execute_response.success?
|
58
94
|
response = perform
|
95
|
+
ServicePattern::Response.check_response!(self, response)
|
59
96
|
ServicePattern::Service.fail!(response.errors) unless response.success?
|
60
97
|
response.result
|
61
98
|
end
|
data/lib/service_pattern.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,155 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_pattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.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:
|
12
|
-
dependencies:
|
11
|
+
date: 2022-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: best_practice_project
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 6.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-performance
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sqlite3
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: tzinfo-data
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
13
153
|
description: ServicePattern for Ruby on Rails.
|
14
154
|
email:
|
15
155
|
- kaspernj@gmail.com
|
@@ -46,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
186
|
- !ruby/object:Gem::Version
|
47
187
|
version: '0'
|
48
188
|
requirements: []
|
49
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.2.32
|
50
190
|
signing_key:
|
51
191
|
specification_version: 4
|
52
192
|
summary: ServicePattern for Ruby on Rails.
|