bbservices 3.1.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bbservices/extensions/with_params.rb +52 -0
- data/lib/bbservices/service.rb +72 -171
- data/lib/bbservices/service_chain.rb +50 -29
- data/lib/bbservices/service_provider.rb +14 -23
- data/lib/bbservices.rb +33 -4
- metadata +11 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bfbb265ecdb59d185f9dcca455a161320e596aefa68ff089b9c5fe393281282
|
4
|
+
data.tar.gz: d69045637f1877db91be419d99d916c8021f5dee49c9192fe2c12ff6ed816cfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073e84467f9d639fad01eacfed718e83379e6b895079f9da68dfee1f83116de9f1cfbfd225e9b24e43c88851dcfee101d570ca30744c44f1fa90314e827d3725
|
7
|
+
data.tar.gz: c2c540f5dd58ba9c426fb280b15f65de19d762f2c9f832eddd8c0de4707d5779c60e8a132612b5da1d5b414ddf49c128296292c4ddee6f1a49684eaa12bede08
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module BBServices
|
2
|
+
module Extensions
|
3
|
+
# Developer Notes
|
4
|
+
# The module WithParams hasn't been decided if it will enter into a production
|
5
|
+
# state due to the confusion over *args vs *kwargs
|
6
|
+
|
7
|
+
# module WithParams
|
8
|
+
|
9
|
+
# # Default initalizer override which takes in the params.
|
10
|
+
# # This will run through the run / run! methods which can take these params
|
11
|
+
# def initialize(*args, **kwargs)
|
12
|
+
# @params = initialization_params
|
13
|
+
# end
|
14
|
+
|
15
|
+
# protected
|
16
|
+
|
17
|
+
# # Returns true / false if the service has any params
|
18
|
+
# # @return [Boolean] true/false if the service has any params
|
19
|
+
# def has_params?
|
20
|
+
# @params.length > 0
|
21
|
+
# end
|
22
|
+
|
23
|
+
# def number_of_params
|
24
|
+
# @params.count
|
25
|
+
# end
|
26
|
+
|
27
|
+
# #
|
28
|
+
# # Developer Notes
|
29
|
+
# # Not sure if this functionality will be used at all...
|
30
|
+
|
31
|
+
# # # Sets the service_class on the instance. This will override the self.class.internal_service_class.
|
32
|
+
# # # @param [Class] new_service_class The new service class.
|
33
|
+
# # def set_service_class(new_service_class)
|
34
|
+
# # @service_class = new_service_class
|
35
|
+
# # end
|
36
|
+
|
37
|
+
# # # Sets the service_class on the instance. This will override the self.class.internal_service_class.
|
38
|
+
# # # @param [Class] new_service_class The new service class.
|
39
|
+
# # def service_class=(new_service_class)
|
40
|
+
# # set_service_class(new_service_class)
|
41
|
+
# # end
|
42
|
+
|
43
|
+
# # # Gets the current service class. This will use @service_class if set, otherwise will fallback to
|
44
|
+
# # # self.class.internal_service_class.
|
45
|
+
# # # @return [Class] new_service_class The new service class.
|
46
|
+
# # def service_class
|
47
|
+
# # @service_class ||= self.class.internal_service_class
|
48
|
+
# # end
|
49
|
+
|
50
|
+
# end
|
51
|
+
end
|
52
|
+
end
|
data/lib/bbservices/service.rb
CHANGED
@@ -2,206 +2,110 @@
|
|
2
2
|
|
3
3
|
require_relative 'service_chain'
|
4
4
|
|
5
|
-
# The BBServices namespace.
|
6
5
|
module BBServices
|
7
|
-
# Error thrown when a Hash type isn't given
|
8
|
-
class ServiceHashTypeError < StandardError
|
9
|
-
def message
|
10
|
-
'Params need to be a Hash'
|
11
|
-
end
|
12
|
-
end
|
13
6
|
|
14
|
-
# The lightweight service object provided by BBServices.
|
7
|
+
# The lightweight service object provided by BBServices. The basic functionality includes:
|
8
|
+
# - Ability to access user defined initalization. E.g. initalize(one = 1, two = 2)
|
9
|
+
# - Ability to chain services via '.then'
|
10
|
+
# - Ability to check success / failure
|
11
|
+
# - Ability to store errors thrown via services
|
15
12
|
class Service
|
16
|
-
|
13
|
+
|
17
14
|
|
18
15
|
class << self
|
19
|
-
|
16
|
+
|
20
17
|
# Creates the service instances and calls run upon said instance
|
21
|
-
# @param [
|
18
|
+
# @param [Array] args The array of params which has been passed to run
|
22
19
|
# @param [Block] block The block which will be called upon the service finishing running
|
23
20
|
# @return [BBServices.Service] returns the service instance
|
24
|
-
def run(
|
25
|
-
new(
|
21
|
+
def run(*args, **kwargs, &block)
|
22
|
+
new(*args, **kwargs).tap do |service|
|
26
23
|
service.run(&block)
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
30
27
|
# Creates the service instances and calls run! upon said instance
|
31
|
-
# @param [
|
32
|
-
# @param [Block] block The block which will be called upon the service finishing running
|
28
|
+
# @param [Array] args The array of params which has been passed to run!
|
29
|
+
# @param [Block] block The block which will be called upon the service finishing running successfully
|
33
30
|
# @return [BBServices.Service] returns the service instance
|
34
|
-
def run!(
|
35
|
-
new(
|
31
|
+
def run!(*args, **kwargs, &block)
|
32
|
+
new(*args, **kwargs).tap do |service|
|
36
33
|
service.run!(&block)
|
37
34
|
end
|
38
35
|
end
|
39
|
-
|
40
|
-
# An alias to {BBServices::Service}'s run method
|
41
|
-
alias call run
|
42
|
-
|
43
|
-
# An alias to {BBServices::Service}'s run! method
|
44
|
-
alias call! run!
|
45
|
-
|
46
|
-
# Sets the service class on the Class. Please note this is an internal method.
|
47
|
-
# @param [Class] klass The class which will be set as the service_class
|
48
|
-
# @return [BBServices.Service] returns the service instance
|
49
|
-
def service_class(klass)
|
50
|
-
@service_class = klass
|
51
|
-
end
|
52
|
-
|
53
|
-
# Gets the current service class
|
54
|
-
# @return [Class] returns the service class. Please note this is an internal method.
|
55
|
-
def internal_service_class
|
56
|
-
@service_class
|
57
|
-
end
|
58
36
|
end
|
59
37
|
|
60
|
-
#
|
61
|
-
#
|
62
|
-
def initialize(params = {})
|
63
|
-
@object = nil
|
64
|
-
@successful = false
|
65
|
-
@ran = false
|
66
|
-
@error = nil
|
67
|
-
@service_class = nil
|
68
|
-
|
69
|
-
@params = params
|
70
|
-
end
|
71
|
-
|
72
|
-
# Runs the service using 'safe' execution. The @run variable will be set to true, initialize_service and run_service
|
73
|
-
# will then be called.
|
38
|
+
# Runs the service using 'safe' execution. The @run variable will be set to true, then
|
39
|
+
# the run method will be called
|
74
40
|
# @param [Block] block The block which will be called upon the service finishing running
|
75
41
|
# @return [BBServices.Service] returns the service instance
|
76
42
|
def run(&block)
|
77
|
-
set_ran
|
78
43
|
begin
|
79
|
-
|
80
|
-
|
44
|
+
@ran = true
|
45
|
+
successful = on_run
|
46
|
+
set_successful(successful == nil ? true : !!successful)
|
81
47
|
rescue => e
|
82
48
|
set_successful(false)
|
83
|
-
|
49
|
+
register_error(e)
|
84
50
|
ensure
|
85
|
-
call_block(
|
51
|
+
call_block(block) if block_given?
|
86
52
|
end
|
87
53
|
end
|
88
54
|
|
89
|
-
# Runs the service using 'unsafe' execution. The @run variable will be set to true,
|
90
|
-
#
|
55
|
+
# Runs the service using 'unsafe' execution. The @run variable will be set to true, then
|
56
|
+
# the run! method will be called
|
91
57
|
# @param [Block] block The block which will be called upon the service finishing running
|
92
58
|
# @return [BBServices.Service] returns the service instance
|
93
59
|
def run!(&block)
|
94
|
-
set_ran
|
95
60
|
begin
|
96
|
-
|
97
|
-
|
98
|
-
|
61
|
+
@ran = true
|
62
|
+
successful = on_run!
|
63
|
+
set_successful(successful == nil ? true : !!successful)
|
64
|
+
call_block(block) if block_given?
|
99
65
|
rescue => e
|
100
66
|
set_successful(false)
|
101
|
-
|
67
|
+
register_error(e)
|
102
68
|
raise e
|
103
69
|
end
|
104
70
|
end
|
105
71
|
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
alias call! run!
|
111
|
-
|
112
|
-
# Sets the service_class on the instance. This will override the self.class.internal_service_class.
|
113
|
-
# @param [Class] new_service_class The new service class.
|
114
|
-
def set_service_class(new_service_class)
|
115
|
-
@service_class = new_service_class
|
116
|
-
end
|
117
|
-
|
118
|
-
# Sets the service_class on the instance. This will override the self.class.internal_service_class.
|
119
|
-
# @param [Class] new_service_class The new service class.
|
120
|
-
def service_class=(new_service_class)
|
121
|
-
set_service_class(new_service_class)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Gets the current service class. This will use @service_class if set, otherwise will fallback to
|
125
|
-
# self.class.internal_service_class.
|
126
|
-
# @return [Class] new_service_class The new service class.
|
127
|
-
def service_class
|
128
|
-
@service_class ||= self.class.internal_service_class
|
129
|
-
end
|
130
|
-
|
131
|
-
# Sets the params variable (@params) on the service.
|
132
|
-
# @param [Hash] new_params The new params Hash.
|
133
|
-
def set_params(new_params)
|
134
|
-
raise BBServices::ServiceHashTypeError unless new_params.is_a?(Hash)
|
72
|
+
# Returns a ServiceChain with the service as a registered service.
|
73
|
+
# The service must have been ran in order to call this chaining method.
|
74
|
+
def then(*args, &block)
|
75
|
+
raise BBServices::ServiceMustRunBeforeChainingError if !self.ran?
|
135
76
|
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
# Sets the params variable (@params) on the service.
|
140
|
-
# @param [Hash] new_params The new params Hash.
|
141
|
-
def params=(new_params)
|
142
|
-
set_params(new_params)
|
143
|
-
end
|
144
|
-
|
145
|
-
# Gets a single param using a key
|
146
|
-
# @param [String/Symbol] key The key which is used to find the param
|
147
|
-
# @return [Hash] The param found using the key
|
148
|
-
def param_for(key)
|
149
|
-
param(key)
|
150
|
-
end
|
151
|
-
|
152
|
-
# Gets a single param using a key
|
153
|
-
# @param [String/Symbol] key The key which is used to find the param
|
154
|
-
# @return [Hash] The param found using the key
|
155
|
-
def param(key)
|
156
|
-
@params[key] if @params
|
157
|
-
end
|
158
|
-
|
159
|
-
# Gets the number of params
|
160
|
-
# @return [Number] The number of params
|
161
|
-
def number_of_params
|
162
|
-
@params ? @params.length : 0
|
77
|
+
BBServices::ServiceChain.new(self).then(block)
|
163
78
|
end
|
164
79
|
|
165
80
|
# Returns true/false on if the service has been ran
|
166
81
|
# @return [Boolean] True/False value on if the service has been ran
|
167
82
|
def ran?
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
# Returns true / false if the service has any params
|
172
|
-
# @return [Boolean] true/false if the service has any params
|
173
|
-
def params?
|
174
|
-
!!(@params && @params.length)
|
83
|
+
!!@ran
|
175
84
|
end
|
176
85
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
# Returns true/false on if the service did succeed.
|
181
|
-
# @return [Boolean] true/false on if the service did succeed.
|
182
|
-
def succeeded?
|
183
|
-
successful?
|
86
|
+
def run?
|
87
|
+
!!@ran
|
184
88
|
end
|
185
89
|
|
186
90
|
# Returns true/false on if the service was successful.
|
187
91
|
# @return [Boolean] true/false on if the service was successful.
|
188
92
|
def successful?
|
189
|
-
@successful
|
93
|
+
(@successful == nil ? false : @successful)
|
190
94
|
end
|
191
95
|
|
192
96
|
# Returns true/false on if the service was unsuccessful. This will always be the inverse of successful?
|
193
97
|
# @return [Boolean] true/false on if the service failed.
|
194
98
|
def failed?
|
195
|
-
|
99
|
+
(@successful == nil ? false : !@successful)
|
196
100
|
end
|
197
101
|
|
198
102
|
# Calls the given block if the service was successful
|
199
|
-
def success
|
103
|
+
def success(&block)
|
200
104
|
yield(self) if succeeded?
|
201
105
|
end
|
202
106
|
|
203
107
|
# Calls the given block if the service failed
|
204
|
-
def failure
|
108
|
+
def failure(&block)
|
205
109
|
yield(self) if failed?
|
206
110
|
end
|
207
111
|
|
@@ -212,66 +116,63 @@ module BBServices
|
|
212
116
|
def on(success: proc {}, failure: proc {})
|
213
117
|
if successful?
|
214
118
|
success.call
|
215
|
-
|
119
|
+
elsif failed?
|
216
120
|
failure.call
|
217
121
|
end
|
218
122
|
end
|
219
123
|
|
220
|
-
# Returns true / false if the service threw an error
|
124
|
+
# Returns true / false if the service threw an error.
|
221
125
|
# @return [Boolean] true/false on if an error has occurred
|
222
126
|
def error?
|
223
|
-
|
127
|
+
errors.count > 0
|
224
128
|
end
|
225
129
|
|
226
|
-
|
130
|
+
def error
|
131
|
+
errors.first
|
132
|
+
end
|
227
133
|
|
228
|
-
|
229
|
-
|
230
|
-
|
134
|
+
def errors
|
135
|
+
@errors ||= []
|
136
|
+
end
|
137
|
+
|
138
|
+
alias_method :succeeded?, :successful?
|
139
|
+
alias_method :call, :run
|
140
|
+
alias_method :call!, :run!
|
231
141
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
142
|
+
protected
|
143
|
+
|
144
|
+
# Called upon run.
|
145
|
+
# @return (nil, boolean) a nil value will automatically set the successful value as
|
146
|
+
# success upon exiting of this method, a true / false value will set the successful value
|
147
|
+
# to that return
|
148
|
+
def on_run
|
149
|
+
raise NotImplementedError.new('#run must be implemented on subclass')
|
237
150
|
end
|
238
151
|
|
239
|
-
# Called upon run
|
240
|
-
#
|
241
|
-
|
242
|
-
|
243
|
-
|
152
|
+
# Called upon run.
|
153
|
+
# @return (nil, boolean) a nil value will automatically set the successful value as
|
154
|
+
# success upon exiting of this method, a true / false value will set the successful value
|
155
|
+
# to that return
|
156
|
+
def on_run!
|
157
|
+
raise NotImplementedError.new('#run must be implemented on subclass')
|
244
158
|
end
|
245
159
|
|
246
|
-
|
247
|
-
|
248
|
-
def set_object(obj)
|
249
|
-
@object = obj
|
160
|
+
def call_block(block)
|
161
|
+
block.call(self)
|
250
162
|
end
|
251
163
|
|
252
164
|
private
|
253
165
|
|
254
|
-
# Sets the internal @ran instance variable
|
255
|
-
# @param [Boolean] ran True / False if the service has been ran
|
256
|
-
def set_ran(ran = true)
|
257
|
-
@ran = ran
|
258
|
-
end
|
259
|
-
|
260
166
|
# Sets the internal @successful instance variable
|
261
167
|
# @param [Boolean] successful True / False if the service has been successful
|
262
168
|
def set_successful(successful = true)
|
263
169
|
@successful = successful
|
264
170
|
end
|
265
171
|
|
266
|
-
#
|
172
|
+
# Adds an error to the errors list
|
267
173
|
# @param [Error] error The error to be assigned
|
268
|
-
def
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
# Calls the block which has been passed
|
273
|
-
def call_block
|
274
|
-
yield(self) if block_given?
|
174
|
+
def register_error(error)
|
175
|
+
errors << error
|
275
176
|
end
|
276
177
|
end
|
277
178
|
end
|
@@ -1,30 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The BBServices namespace.
|
4
3
|
module BBServices
|
4
|
+
|
5
5
|
# Container for chained services.
|
6
6
|
class ServiceChain
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :services
|
9
9
|
|
10
10
|
# Initializes the ServiceChain
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
# @services a list of the services in the chain
|
12
|
+
def initialize(service)
|
13
|
+
|
14
|
+
raise NilServiceInChainError if service.nil?
|
15
|
+
|
16
|
+
@successful = nil
|
17
|
+
@services = [service]
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
# Creates a new chain in the service with block, returns the chain instance for method chaining.
|
21
|
+
# The block should be used to call the next service and recieves the following params:
|
22
|
+
# - BBServices::ServiceChain (self)
|
23
|
+
def chain(&block)
|
24
|
+
self.tap do |c|
|
25
|
+
c.send(:_chain, block)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
|
26
|
-
return nil unless @services.length
|
29
|
+
alias_method :then, :chain
|
27
30
|
|
31
|
+
# Returns the last service which was ran. This will return the last
|
32
|
+
# service, if the previous chain returned a non-service instance
|
33
|
+
def last_service
|
28
34
|
@services.last
|
29
35
|
end
|
30
36
|
|
@@ -34,16 +40,16 @@ module BBServices
|
|
34
40
|
successful?
|
35
41
|
end
|
36
42
|
|
37
|
-
# Returns true/false on if the
|
38
|
-
# @return [Boolean] true/false on if the
|
43
|
+
# Returns true/false on if the service was successful.
|
44
|
+
# @return [Boolean] true/false on if the service was successful.
|
39
45
|
def successful?
|
40
|
-
@successful
|
46
|
+
(@successful == nil ? false : @successful)
|
41
47
|
end
|
42
48
|
|
43
|
-
# Returns true/false on if the
|
44
|
-
# @return [Boolean] true/false on if the
|
49
|
+
# Returns true/false on if the service was unsuccessful. This will always be the inverse of successful?
|
50
|
+
# @return [Boolean] true/false on if the service failed.
|
45
51
|
def failed?
|
46
|
-
|
52
|
+
(@successful == nil ? false : !@successful)
|
47
53
|
end
|
48
54
|
|
49
55
|
# Calls the given block if the chain was successful
|
@@ -68,25 +74,40 @@ module BBServices
|
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
71
|
-
# Returns true / false if
|
77
|
+
# Returns a true / false value if an error has been thrown, this
|
78
|
+
# will be passed to the last_service if one is avalible, otherwise
|
79
|
+
# false will be returned
|
72
80
|
# @return [Boolean] true/false on if an error has occurred
|
73
81
|
def error?
|
74
|
-
|
82
|
+
last_service ? last_service.error? : false
|
75
83
|
end
|
76
84
|
|
77
|
-
|
78
|
-
|
85
|
+
# Returns all of the errors from the last_service, if no last_service
|
86
|
+
# is avalible then an empty array will be returned
|
87
|
+
def errors
|
88
|
+
last_service ? last_service.errors : []
|
79
89
|
end
|
80
90
|
|
81
91
|
private
|
82
92
|
|
83
|
-
def
|
84
|
-
if
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
93
|
+
def _chain(block)
|
94
|
+
if _continue_chain?
|
95
|
+
service = block.call(self)
|
96
|
+
|
97
|
+
if BBServices.is_a_service?(service)
|
98
|
+
@successful = service.successful?
|
99
|
+
@services << service
|
100
|
+
else
|
101
|
+
raise BBServices::ServiceExpectedError
|
102
|
+
end
|
89
103
|
end
|
90
104
|
end
|
105
|
+
|
106
|
+
# Returns true / false if the chain is able to continue, follows the following:
|
107
|
+
# - If we don't have a last service, return true
|
108
|
+
# - If we have a last service check the successful? method
|
109
|
+
def _continue_chain?
|
110
|
+
last_service.successful?
|
111
|
+
end
|
91
112
|
end
|
92
113
|
end
|
@@ -1,20 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The BBServices namespace.
|
4
3
|
module BBServices
|
5
|
-
|
4
|
+
|
5
|
+
# Module to allow external classes to interact with underlying service objects
|
6
|
+
# in a structured way. This will allow the setting of services upon the calling
|
7
|
+
# of given methods. Services will also be bound to the provider.
|
6
8
|
module ServiceProvider
|
7
9
|
def self.included(base)
|
8
10
|
base.class_eval do
|
11
|
+
|
9
12
|
# Creates a service with a given type and params, the service instance will not be ran.
|
10
13
|
# Sets the @service instance on the object which includes this provider.
|
11
14
|
# @param [Class] service_type The class which should be instanciated
|
12
15
|
# @param [Hash] service_params The params which will be passed to the service
|
13
16
|
# @return [{BBServices::Service}] The service type instance
|
14
|
-
def create_service(service_type,
|
15
|
-
@service = service_type.new
|
16
|
-
new_service.set_params(service_params)
|
17
|
-
end
|
17
|
+
def create_service(service_type, *args, **kwargs)
|
18
|
+
@service = service_type.new(*args, **kwargs)
|
18
19
|
end
|
19
20
|
|
20
21
|
# Creates a service with a given type and params, the service instance will be ran using the run method.
|
@@ -23,9 +24,8 @@ module BBServices
|
|
23
24
|
# @param [Hash] service_params The params which will be passed to the service
|
24
25
|
# @param [Block] block The block to call upon running of the service is complete
|
25
26
|
# @return [{BBServices::Service}] The service type instance
|
26
|
-
def run_service(service_type,
|
27
|
-
create_service(service_type,
|
28
|
-
service.service_class = service_type
|
27
|
+
def run_service(service_type, *args, **kwargs, &block)
|
28
|
+
create_service(service_type, *args, **kwargs).tap do |service|
|
29
29
|
service.run(&block)
|
30
30
|
end
|
31
31
|
end
|
@@ -36,28 +36,19 @@ module BBServices
|
|
36
36
|
# @param [Hash] service_params The params which will be passed to the service
|
37
37
|
# @param [Block] block The block to call upon running of the service is complete
|
38
38
|
# @return [{BBServices::Service}] The service type instance
|
39
|
-
def run_service!(service_type,
|
40
|
-
create_service(service_type,
|
41
|
-
service.service_class = service_type
|
39
|
+
def run_service!(service_type, *args, **kwargs, &block)
|
40
|
+
create_service(service_type, *args, **kwargs).tap do |service|
|
42
41
|
service.run!(&block)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# Returns the {BBService::Service} instance currently stored within @service
|
45
|
+
# Returns the {BBService::Service} instance currently stored within @service. This is set
|
46
|
+
# when a single service is ran. It will not be set when chain_service is used and service_chain
|
47
|
+
# should be used instead.
|
51
48
|
# @return [{BBService::Service}] The current service
|
52
49
|
def service
|
53
50
|
@service
|
54
51
|
end
|
55
|
-
|
56
|
-
# Returns the {BBServices::ServiceChain} instance currently stored within @service_chain
|
57
|
-
# @return [{BBServices::ServiceChain}] The current service
|
58
|
-
def service_chain
|
59
|
-
@service_chain
|
60
|
-
end
|
61
52
|
end
|
62
53
|
end
|
63
54
|
end
|
data/lib/bbservices.rb
CHANGED
@@ -4,11 +4,40 @@ require_relative 'bbservices/service'
|
|
4
4
|
require_relative 'bbservices/service_chain'
|
5
5
|
require_relative 'bbservices/service_provider'
|
6
6
|
|
7
|
-
|
7
|
+
require_relative 'bbservices/extensions/with_params'
|
8
|
+
|
9
|
+
# The BBServices namespace. Provides helper methods to aid with
|
10
|
+
# service resolution
|
8
11
|
module BBServices
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
|
13
|
+
class NilServiceInChainError < StandardError
|
14
|
+
def message
|
15
|
+
'BBServices - A BBService must be passed to a chain'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ServiceMustRunBeforeChainingError < StandardError
|
20
|
+
def message
|
21
|
+
'BBServices - Service must be ran before chaining via then can occur'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ServiceExpectedError < StandardError
|
26
|
+
def message
|
27
|
+
'BBServices - A service must be returned from the given block'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
|
33
|
+
# Returns true if a BBServices::Service is passed, false for all other types
|
34
|
+
def is_a_service?(service)
|
35
|
+
service.is_a?(BBServices::Service)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns false if a BBServices::Service is passed, true for all other types
|
39
|
+
def is_not_a_service?(service)
|
40
|
+
!BBServices.is_a_service?(service)
|
12
41
|
end
|
13
42
|
end
|
14
43
|
end
|
metadata
CHANGED
@@ -1,85 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbservices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Farnaby, Big Bear Studios
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: guard-rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.7.3
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.7.3
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rspec
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - '='
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
19
|
+
version: 3.4.0
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - '='
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rubocop
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.13'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.13'
|
26
|
+
version: 3.4.0
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
28
|
name: simplecov
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
31
|
- - '='
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
33
|
+
version: 0.22.0
|
62
34
|
type: :development
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
38
|
- - '='
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: yard
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.8.7.6
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.8.7.6
|
40
|
+
version: 0.22.0
|
83
41
|
description:
|
84
42
|
email:
|
85
43
|
executables: []
|
@@ -87,10 +45,11 @@ extensions: []
|
|
87
45
|
extra_rdoc_files: []
|
88
46
|
files:
|
89
47
|
- lib/bbservices.rb
|
48
|
+
- lib/bbservices/extensions/with_params.rb
|
90
49
|
- lib/bbservices/service.rb
|
91
50
|
- lib/bbservices/service_chain.rb
|
92
51
|
- lib/bbservices/service_provider.rb
|
93
|
-
homepage: https://
|
52
|
+
homepage: https://github.com/bigbearstudios/bbservices-ruby
|
94
53
|
licenses:
|
95
54
|
- MIT
|
96
55
|
metadata: {}
|
@@ -102,16 +61,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
61
|
requirements:
|
103
62
|
- - ">="
|
104
63
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
64
|
+
version: 3.2.0
|
106
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
66
|
requirements:
|
108
67
|
- - ">="
|
109
68
|
- !ruby/object:Gem::Version
|
110
69
|
version: '0'
|
111
70
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.4.1
|
113
72
|
signing_key:
|
114
73
|
specification_version: 4
|
115
|
-
summary: A simple service library for Ruby
|
116
|
-
a Rails / AR service library
|
74
|
+
summary: A simple service library for Ruby
|
117
75
|
test_files: []
|