servitium 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile +1 -1
- data/Rakefile +6 -6
- data/lib/generators/servitium/service_generator.rb +6 -6
- data/lib/servitium/capture_exceptions_mixin.rb +4 -4
- data/lib/servitium/configuration.rb +1 -2
- data/lib/servitium/context.rb +7 -7
- data/lib/servitium/context_failure.rb +1 -1
- data/lib/servitium/context_model.rb +5 -4
- data/lib/servitium/i18n.rb +6 -6
- data/lib/servitium/rails/railtie.rb +1 -1
- data/lib/servitium/rails.rb +2 -2
- data/lib/servitium/scoped_attributes.rb +4 -4
- data/lib/servitium/service.rb +46 -46
- data/lib/servitium/service_active_job.rb +2 -2
- data/lib/servitium/service_sidekiq_job.rb +2 -2
- data/lib/servitium/sub_contexts.rb +32 -32
- data/lib/servitium/transactional_mixin.rb +5 -5
- data/lib/servitium/version.rb +1 -1
- data/lib/servitium.rb +20 -21
- data/lib/tasks/servitium_tasks.rake +7 -9
- data/servitium.gemspec +32 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69acb44ae4a39d61e34493dd4c295bf9c202e35757e5c11235cb988e81fa4c2
|
4
|
+
data.tar.gz: 4c17667332f963b0686a71654ce944af6ca021bc57a1a4b25b094fa8c94c00a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80181d971d20a9686faf0882c69ab8e0c1c17af829c444267b41ce62cd0d63e7b7594722999072042adebfe70c9e0124db6349f537540229f423f50c1006b339
|
7
|
+
data.tar.gz: 9b06e3e670be995a0cbb8d47fc22b5805117ca7802d35514b1a8379c7609ae3e25606517f6db8915ded834713fceb4c97c44410f42442ab57bb17e13a314e07c
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
5
|
|
6
6
|
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs <<
|
8
|
-
t.libs <<
|
9
|
-
t.test_files = FileList[
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
10
|
end
|
11
11
|
|
12
|
-
Rake.add_rakelib
|
12
|
+
Rake.add_rakelib "lib/tasks"
|
13
13
|
|
14
14
|
task default: :test
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rails/generators"
|
4
4
|
|
5
5
|
module Servitium
|
6
6
|
class ServiceGenerator < ::Rails::Generators::NamedBase
|
7
|
-
desc
|
7
|
+
desc "Generates a service and context"
|
8
8
|
|
9
|
-
source_root File.expand_path(
|
9
|
+
source_root File.expand_path("templates", __dir__)
|
10
10
|
|
11
11
|
def copy_initializer_file
|
12
|
-
template
|
13
|
-
template
|
14
|
-
template
|
12
|
+
template "service.rb", "app/services/#{file_name}_service.rb"
|
13
|
+
template "context.rb", "app/services/#{file_name}_context.rb"
|
14
|
+
template "service_test.rb", "test/services/#{file_name}_service_test.rb"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -14,10 +14,10 @@ module Servitium
|
|
14
14
|
@capture_exceptions = nil unless defined?(@capture_exceptions)
|
15
15
|
if @capture_exceptions.nil?
|
16
16
|
@capture_exceptions = if superclass < Servitium::Service
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
superclass.capture_exceptions
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
21
|
end
|
22
22
|
@capture_exceptions
|
23
23
|
end
|
data/lib/servitium/context.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "active_model/naming"
|
4
|
+
require "active_model/translation"
|
5
5
|
|
6
6
|
module Servitium
|
7
7
|
class Context
|
@@ -18,9 +18,9 @@ module Servitium
|
|
18
18
|
define_callbacks :perform
|
19
19
|
|
20
20
|
def initialize(*args)
|
21
|
-
@success
|
22
|
-
@called
|
23
|
-
@errors
|
21
|
+
@success = true
|
22
|
+
@called = false
|
23
|
+
@errors = ActiveModel::Errors.new(self)
|
24
24
|
@subcontexts = {}
|
25
25
|
|
26
26
|
run_callbacks :initialize do
|
@@ -36,8 +36,8 @@ module Servitium
|
|
36
36
|
!success?
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
alias_method :fail?, :failure?
|
40
|
+
alias_method :failed?, :failure?
|
41
41
|
|
42
42
|
def fail!(attr, message = :invalid, options = {})
|
43
43
|
@success = false
|
@@ -25,14 +25,14 @@ module Servitium
|
|
25
25
|
|
26
26
|
def inspect
|
27
27
|
message = super
|
28
|
-
message += " (success: #{success?}, valid: #{@errors.size.zero?}, errors: #{@errors.full_messages.join(
|
28
|
+
message += " (success: #{success?}, valid: #{@errors.size.zero?}, errors: #{@errors.full_messages.join(", ")})"
|
29
29
|
message
|
30
30
|
end
|
31
31
|
|
32
32
|
remove_method :model_name
|
33
33
|
|
34
34
|
def model_name
|
35
|
-
@model_name ||= ActiveModel::Name.new(self.class, nil, self.class.name.gsub(
|
35
|
+
@model_name ||= ActiveModel::Name.new(self.class, nil, self.class.name.gsub("Context", ""))
|
36
36
|
end
|
37
37
|
|
38
38
|
def id
|
@@ -53,13 +53,14 @@ module Servitium
|
|
53
53
|
end.to_h
|
54
54
|
end
|
55
55
|
|
56
|
-
def _destroy
|
56
|
+
def _destroy
|
57
|
+
end
|
57
58
|
|
58
59
|
private
|
59
60
|
|
60
61
|
def validate_subcontexts
|
61
62
|
@subcontexts.each do |key, value|
|
62
|
-
errors.add(key,
|
63
|
+
errors.add(key, "invalid") unless [*value].find_all { |v| v.respond_to?(:invalid?) && v.invalid? }.empty?
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
data/lib/servitium/i18n.rb
CHANGED
@@ -6,14 +6,14 @@ module Servitium
|
|
6
6
|
@service_scope ||= nil
|
7
7
|
|
8
8
|
unless @service_scope.present?
|
9
|
-
parts = (is_a?(Class) ? self : self.class).to_s.underscore.
|
10
|
-
parts[-1] = "#{parts.last.gsub(
|
11
|
-
parts[-1] = "#{parts.last.gsub(
|
12
|
-
@service_scope = parts.compact.join(
|
9
|
+
parts = (is_a?(Class) ? self : self.class).to_s.underscore.tr("/", ".").split(".")
|
10
|
+
parts[-1] = "#{parts.last.gsub("_service", "").pluralize}.service" if parts.last.end_with?("_service")
|
11
|
+
parts[-1] = "#{parts.last.gsub("_context", "").pluralize}.context" if parts.last.end_with?("_context")
|
12
|
+
@service_scope = parts.compact.join(".")
|
13
13
|
end
|
14
14
|
|
15
|
-
options = {
|
16
|
-
options[:default] = ::I18n.t(key) unless key.start_with?(
|
15
|
+
options = {scope: @service_scope}
|
16
|
+
options[:default] = ::I18n.t(key) unless key.start_with?(".")
|
17
17
|
|
18
18
|
::I18n.t(key, **options.merge(passed_options))
|
19
19
|
end
|
data/lib/servitium/rails.rb
CHANGED
@@ -10,9 +10,9 @@ module Servitium
|
|
10
10
|
@validation_context = validation_context
|
11
11
|
end
|
12
12
|
|
13
|
-
def attribute(name, *
|
13
|
+
def attribute(name, *)
|
14
14
|
store << name.to_s
|
15
|
-
context.send(:attribute, name, *
|
15
|
+
context.send(:attribute, name, *)
|
16
16
|
end
|
17
17
|
|
18
18
|
def validates(name, options = {})
|
@@ -20,9 +20,9 @@ module Servitium
|
|
20
20
|
context.send(:validates, name, options)
|
21
21
|
end
|
22
22
|
|
23
|
-
def validate(name, options = {}, &
|
23
|
+
def validate(name, options = {}, &)
|
24
24
|
options[:on] ||= validation_context if validation_context
|
25
|
-
context.send(:validate, name, options, &
|
25
|
+
context.send(:validate, name, options, &)
|
26
26
|
end
|
27
27
|
|
28
28
|
def call(block)
|
data/lib/servitium/service.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "transactional_mixin"
|
4
|
+
require_relative "capture_exceptions_mixin"
|
5
5
|
|
6
6
|
module Servitium
|
7
7
|
class Service
|
@@ -12,7 +12,7 @@ module Servitium
|
|
12
12
|
|
13
13
|
attr_reader :context, :raise_on_error
|
14
14
|
|
15
|
-
|
15
|
+
alias_method :ctx, :context
|
16
16
|
|
17
17
|
define_callbacks :commit
|
18
18
|
define_callbacks :perform
|
@@ -63,7 +63,7 @@ module Servitium
|
|
63
63
|
send(@command)
|
64
64
|
rescue Servitium::ContextFailure => e
|
65
65
|
raise_if_needed(e)
|
66
|
-
rescue
|
66
|
+
rescue => e
|
67
67
|
# If capture exceptions is true, eat the exception and set the context errors.
|
68
68
|
raise unless capture_exceptions
|
69
69
|
|
@@ -88,7 +88,7 @@ module Servitium
|
|
88
88
|
if e
|
89
89
|
raise e
|
90
90
|
elsif context.errors.present?
|
91
|
-
errors = context.errors.full_messages.join(
|
91
|
+
errors = context.errors.full_messages.join(", ")
|
92
92
|
log :error, "raising: #{errors}"
|
93
93
|
raise StandardError, errors
|
94
94
|
end
|
@@ -121,17 +121,17 @@ module Servitium
|
|
121
121
|
end
|
122
122
|
|
123
123
|
class << self
|
124
|
-
def perform_async(*
|
125
|
-
perform_later(*
|
124
|
+
def perform_async(*)
|
125
|
+
perform_later(*)
|
126
126
|
end
|
127
127
|
|
128
|
-
def perform_sync(*
|
129
|
-
perform(*
|
128
|
+
def perform_sync(*)
|
129
|
+
perform(*)
|
130
130
|
end
|
131
131
|
|
132
132
|
# Main point of entry for services, will raise in case of errors
|
133
|
-
def perform!(*
|
134
|
-
inst = new(*
|
133
|
+
def perform!(*)
|
134
|
+
inst = new(*)
|
135
135
|
|
136
136
|
begin
|
137
137
|
inst.context.validate!(:in) if inst.context.class.inbound_scope_used
|
@@ -148,13 +148,13 @@ module Servitium
|
|
148
148
|
end
|
149
149
|
|
150
150
|
# Main point of entry for services
|
151
|
-
def perform(*
|
152
|
-
call(*
|
151
|
+
def perform(*)
|
152
|
+
call(*).context
|
153
153
|
end
|
154
154
|
|
155
155
|
# Call the service returning the service instance
|
156
|
-
def call(*
|
157
|
-
inst = new(*
|
156
|
+
def call(*)
|
157
|
+
inst = new(*)
|
158
158
|
valid_in = inst.context.valid?
|
159
159
|
valid_in &&= inst.context.valid?(:in) if inst.context.class.inbound_scope_used
|
160
160
|
if valid_in
|
@@ -170,8 +170,8 @@ module Servitium
|
|
170
170
|
end
|
171
171
|
|
172
172
|
# Perform this service async
|
173
|
-
def perform_later(*
|
174
|
-
inst = new(*
|
173
|
+
def perform_later(*)
|
174
|
+
inst = new(*)
|
175
175
|
valid_in = inst.context.valid?
|
176
176
|
valid_in &&= inst.context.valid?(:in) if inst.context.class.inbound_scope_used
|
177
177
|
|
@@ -220,44 +220,44 @@ module Servitium
|
|
220
220
|
end
|
221
221
|
|
222
222
|
def queue_name
|
223
|
-
|
223
|
+
"default"
|
224
224
|
end
|
225
225
|
|
226
226
|
# Callbacks
|
227
|
-
def after_commit(*filters, &
|
228
|
-
set_callback(:commit, :after, *filters, &
|
227
|
+
def after_commit(*filters, &)
|
228
|
+
set_callback(:commit, :after, *filters, &)
|
229
229
|
end
|
230
230
|
|
231
|
-
def before_perform(*filters, &
|
232
|
-
set_callback(:perform, :before, *filters, &
|
231
|
+
def before_perform(*filters, &)
|
232
|
+
set_callback(:perform, :before, *filters, &)
|
233
233
|
end
|
234
234
|
|
235
|
-
def around_perform(*filters, &
|
236
|
-
set_callback(:perform, :around, *filters, &
|
235
|
+
def around_perform(*filters, &)
|
236
|
+
set_callback(:perform, :around, *filters, &)
|
237
237
|
end
|
238
238
|
|
239
|
-
def after_perform(*filters, &
|
240
|
-
set_callback(:perform, :after, *filters, &
|
239
|
+
def after_perform(*filters, &)
|
240
|
+
set_callback(:perform, :after, *filters, &)
|
241
241
|
end
|
242
242
|
|
243
|
-
def after_failure(*filters, &
|
244
|
-
set_callback(:failure, :after, *filters, &
|
243
|
+
def after_failure(*filters, &)
|
244
|
+
set_callback(:failure, :after, *filters, &)
|
245
245
|
end
|
246
246
|
|
247
|
-
def around_async_success(*filters, &
|
248
|
-
set_callback(:async_success, :around, *filters, &
|
247
|
+
def around_async_success(*filters, &)
|
248
|
+
set_callback(:async_success, :around, *filters, &)
|
249
249
|
end
|
250
250
|
|
251
|
-
def around_async_failure(*filters, &
|
252
|
-
set_callback(:async_failure, :around, *filters, &
|
251
|
+
def around_async_failure(*filters, &)
|
252
|
+
set_callback(:async_failure, :around, *filters, &)
|
253
253
|
end
|
254
254
|
|
255
|
-
def after_async_success(*filters, &
|
256
|
-
set_callback(:async_success, :after, *filters, &
|
255
|
+
def after_async_success(*filters, &)
|
256
|
+
set_callback(:async_success, :after, *filters, &)
|
257
257
|
end
|
258
258
|
|
259
|
-
def after_async_failure(*filters, &
|
260
|
-
set_callback(:async_failure, :after, *filters, &
|
259
|
+
def after_async_failure(*filters, &)
|
260
|
+
set_callback(:async_failure, :after, *filters, &)
|
261
261
|
end
|
262
262
|
|
263
263
|
def context_class
|
@@ -265,15 +265,15 @@ module Servitium
|
|
265
265
|
end
|
266
266
|
|
267
267
|
def context_class_name
|
268
|
-
name.gsub(
|
268
|
+
name.gsub("Service", "Context")
|
269
269
|
end
|
270
270
|
|
271
271
|
def context_class!
|
272
272
|
return context_class if context_class
|
273
273
|
|
274
|
-
context_class_parts = context_class_name.split(
|
274
|
+
context_class_parts = context_class_name.split("::")
|
275
275
|
context_class_name_part = context_class_parts.pop
|
276
|
-
context_module_name = context_class_parts.join(
|
276
|
+
context_module_name = context_class_parts.join("::")
|
277
277
|
context_module = context_module_name.present? ? context_module_name.constantize : Object
|
278
278
|
|
279
279
|
context_module.const_set(context_class_name_part, Class.new(context_base_class_name.constantize))
|
@@ -283,7 +283,7 @@ module Servitium
|
|
283
283
|
# Get the base class for new contexts defined using context blocks
|
284
284
|
# Defaults to Servitium::Context
|
285
285
|
def context_base_class_name
|
286
|
-
@@_context_base_class_name ||=
|
286
|
+
@@_context_base_class_name ||= "Servitium::Context"
|
287
287
|
end
|
288
288
|
|
289
289
|
# Override the base class for contexts defined using context blocks, you can use this to
|
@@ -292,19 +292,19 @@ module Servitium
|
|
292
292
|
@@_context_base_class_name = base_class
|
293
293
|
end
|
294
294
|
|
295
|
-
def context(
|
296
|
-
return initialized_context(*
|
295
|
+
def context(*, &)
|
296
|
+
return initialized_context(*) unless block_given?
|
297
297
|
|
298
298
|
begin
|
299
299
|
context_class!.new
|
300
|
-
rescue
|
300
|
+
rescue
|
301
301
|
nil
|
302
302
|
end
|
303
|
-
context_class!.class_eval(&
|
303
|
+
context_class!.class_eval(&)
|
304
304
|
end
|
305
305
|
|
306
|
-
def initialized_context(*
|
307
|
-
context_class.new(*
|
306
|
+
def initialized_context(*)
|
307
|
+
context_class.new(*)
|
308
308
|
end
|
309
309
|
end
|
310
310
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Servitium
|
4
4
|
class ServiceActiveJob < ActiveJob::Base
|
5
|
-
def perform(class_name, *
|
6
|
-
service = class_name.constantize.call(*
|
5
|
+
def perform(class_name, *)
|
6
|
+
service = class_name.constantize.call(*)
|
7
7
|
|
8
8
|
if service.context.success?
|
9
9
|
service.send(:async_success)
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Servitium
|
4
4
|
class ServiceSidekiqJob
|
5
5
|
include Sidekiq::Job
|
6
|
-
def perform(class_name, *
|
7
|
-
service = class_name.constantize.call(*
|
6
|
+
def perform(class_name, *)
|
7
|
+
service = class_name.constantize.call(*)
|
8
8
|
|
9
9
|
if service.context.success?
|
10
10
|
service.send(:async_success)
|
@@ -4,7 +4,7 @@ module Servitium
|
|
4
4
|
module SubContexts
|
5
5
|
def sub_context(name)
|
6
6
|
if name.to_s.singularize == name.to_s
|
7
|
-
define_method("#{name}_attributes=") do |attributes|
|
7
|
+
define_method(:"#{name}_attributes=") do |attributes|
|
8
8
|
klass = "#{self.class.name}::#{name.to_s.camelize}".safe_constantize
|
9
9
|
|
10
10
|
writer = "#{name}="
|
@@ -19,17 +19,17 @@ module Servitium
|
|
19
19
|
inst
|
20
20
|
end
|
21
21
|
|
22
|
-
define_method("#{name}=") do |attributes|
|
22
|
+
define_method(:"#{name}=") do |attributes|
|
23
23
|
klass = "#{self.class.name}::#{name.to_s.camelize}".safe_constantize
|
24
24
|
inst = if attributes.is_a? klass
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
attributes
|
26
|
+
else
|
27
|
+
inst = klass.new(attributes)
|
28
|
+
inst.supercontext = self
|
29
|
+
inst
|
30
|
+
end
|
31
31
|
|
32
|
-
instance_variable_set("@#{name}"
|
32
|
+
instance_variable_set(:"@#{name}", inst)
|
33
33
|
|
34
34
|
@subcontexts ||= {}
|
35
35
|
@subcontexts[name] = inst
|
@@ -37,21 +37,21 @@ module Servitium
|
|
37
37
|
inst
|
38
38
|
end
|
39
39
|
else
|
40
|
-
define_method("#{name}_attributes=") do |attributes|
|
40
|
+
define_method(:"#{name}_attributes=") do |attributes|
|
41
41
|
klass = "#{self.class.name}::#{name.to_s.singularize.camelize}".safe_constantize
|
42
42
|
|
43
43
|
if attributes.is_a?(Hash) || attributes.is_a?(ActionController::Parameters)
|
44
44
|
keys = attributes.keys
|
45
|
-
attributes = (if keys.reject { |k| k ==
|
45
|
+
attributes = (if keys.reject { |k| k == "TEMPLATE" }.all? { |k| k.to_i.to_s == k }
|
46
46
|
attributes.reject do |k|
|
47
|
-
k ==
|
47
|
+
k == "TEMPLATE"
|
48
48
|
end.values
|
49
49
|
end)
|
50
50
|
end
|
51
51
|
|
52
52
|
result = []
|
53
53
|
attributes.each do |params|
|
54
|
-
next if params[
|
54
|
+
next if params["_destroy"] == "1" || params[:_destroy] == "1"
|
55
55
|
|
56
56
|
inst = klass.new(params)
|
57
57
|
inst.supercontext = self
|
@@ -66,25 +66,25 @@ module Servitium
|
|
66
66
|
result
|
67
67
|
end
|
68
68
|
|
69
|
-
define_method("#{name}=") do |attributes|
|
69
|
+
define_method(:"#{name}=") do |attributes|
|
70
70
|
klass = "#{self.class.name}::#{name.to_s.singularize.camelize}".safe_constantize
|
71
71
|
result = if attributes.is_a?(Array) && attributes.all? { |a| a.instance_of?(klass) }
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
instance_variable_set("@#{name}"
|
72
|
+
attributes
|
73
|
+
else
|
74
|
+
if attributes.is_a?(Hash) || attributes.is_a?(ActionController::Parameters)
|
75
|
+
attributes = (attributes.values if attributes.keys.all? { |k| k.to_i.to_s == k })
|
76
|
+
end
|
77
|
+
|
78
|
+
result = []
|
79
|
+
attributes.each do |params|
|
80
|
+
inst = klass.new(params)
|
81
|
+
inst.supercontext = self
|
82
|
+
result.push(inst)
|
83
|
+
end
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
instance_variable_set(:"@#{name}", result)
|
88
88
|
|
89
89
|
@subcontexts ||= {}
|
90
90
|
@subcontexts[name] = result
|
@@ -95,11 +95,11 @@ module Servitium
|
|
95
95
|
|
96
96
|
if name.to_s.singularize == name.to_s
|
97
97
|
define_method(name.to_s) do
|
98
|
-
instance_variable_get("@#{name}"
|
98
|
+
instance_variable_get(:"@#{name}") if instance_variable_defined?(:"@#{name}")
|
99
99
|
end
|
100
100
|
else
|
101
101
|
define_method(name.to_s) do
|
102
|
-
value = instance_variable_get("@#{name}"
|
102
|
+
value = instance_variable_get(:"@#{name}") if instance_variable_defined?(:"@#{name}")
|
103
103
|
value ||= []
|
104
104
|
value
|
105
105
|
end
|
@@ -10,14 +10,14 @@ module Servitium
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def transactional(value = nil)
|
13
|
-
@transactional = value
|
13
|
+
@transactional = value unless value.nil?
|
14
14
|
@transactional = nil unless defined?(@transactional)
|
15
15
|
if @transactional.nil?
|
16
16
|
@transactional = if superclass < Servitium::Service
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
superclass.transactional
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
21
|
end
|
22
22
|
@transactional
|
23
23
|
end
|
data/lib/servitium/version.rb
CHANGED
data/lib/servitium.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require "active_model"
|
4
|
+
require "active_attr"
|
5
|
+
require "active_support"
|
6
|
+
require "action_controller"
|
7
|
+
require "active_job"
|
8
|
+
require "sidekiq"
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
|
23
|
-
require 'servitium/rails' if defined?(::Rails)
|
10
|
+
require "servitium/error"
|
11
|
+
require "servitium/context_failure"
|
12
|
+
require "servitium/i18n"
|
13
|
+
require "servitium/sub_contexts"
|
14
|
+
require "servitium/scoped_attributes"
|
15
|
+
require "servitium/context_model"
|
16
|
+
require "servitium/context"
|
17
|
+
require "servitium/service_active_job"
|
18
|
+
require "servitium/service_sidekiq_job"
|
19
|
+
require "servitium/service"
|
20
|
+
require "servitium/version"
|
21
|
+
require "servitium/configuration"
|
24
22
|
|
23
|
+
require "servitium/rails" if defined?(::Rails)
|
25
24
|
|
26
25
|
module Servitium
|
27
26
|
class << self
|
@@ -34,4 +33,4 @@ module Servitium
|
|
34
33
|
@config ||= Configuration.new
|
35
34
|
end
|
36
35
|
end
|
37
|
-
end
|
36
|
+
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "yaml"
|
4
|
+
require "active_support/inflector"
|
5
5
|
|
6
6
|
namespace :servitium do
|
7
|
-
desc
|
7
|
+
desc "Convert localization keys"
|
8
8
|
task :convert_keys do
|
9
|
-
locs = YAML.
|
10
|
-
locs[
|
11
|
-
locs[
|
9
|
+
locs = YAML.load_file("./config/locales/en.yml")
|
10
|
+
locs["en"]["services"].each_key do |service|
|
11
|
+
locs["en"][service[0..-9].pluralize] = {"service" => locs["en"]["services"][service].dup}
|
12
12
|
end
|
13
13
|
|
14
|
-
File.
|
15
|
-
f.write YAML.dump(locs)
|
16
|
-
end
|
14
|
+
File.write("./config/locales/en.yml", YAML.dump(locs))
|
17
15
|
end
|
18
16
|
end
|
data/servitium.gemspec
CHANGED
@@ -1,47 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "lib/servitium/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "servitium"
|
7
|
+
spec.version = Servitium::VERSION
|
8
|
+
spec.authors = ["Tom de Grunt"]
|
9
|
+
spec.email = ["tom@degrunt.nl"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = "Service objects"
|
12
|
+
spec.description = "An implementation of the command pattern for Ruby"
|
13
|
+
spec.homepage = "https://entropydecelerator.com/components/servitium"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.5")
|
16
16
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://code.entropydecelerator.com/components/servitium"
|
19
19
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
22
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
23
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
24
|
end
|
25
|
-
spec.bindir
|
26
|
-
spec.executables
|
27
|
-
spec.require_paths = [
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_dependency
|
30
|
-
spec.add_dependency
|
31
|
-
spec.add_dependency
|
32
|
-
spec.add_dependency
|
33
|
-
spec.add_dependency
|
34
|
-
spec.add_dependency
|
35
|
-
spec.add_dependency
|
29
|
+
spec.add_dependency "active_attr", "~> 0.15"
|
30
|
+
spec.add_dependency "activejob", "> 5.1"
|
31
|
+
spec.add_dependency "activemodel", "> 5.1"
|
32
|
+
spec.add_dependency "activerecord", "> 5.1"
|
33
|
+
spec.add_dependency "activesupport", "> 5.1"
|
34
|
+
spec.add_dependency "actionpack", "> 5.1"
|
35
|
+
spec.add_dependency "i18n", ">= 0.7"
|
36
36
|
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
41
|
-
spec.add_development_dependency
|
42
|
-
spec.add_development_dependency
|
43
|
-
spec.add_development_dependency
|
44
|
-
spec.add_development_dependency
|
45
|
-
spec.add_development_dependency
|
46
|
-
spec.add_development_dependency
|
37
|
+
spec.add_development_dependency "auxilium", ">= 3"
|
38
|
+
spec.add_development_dependency "minitest", "~> 5.11"
|
39
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
40
|
+
spec.add_development_dependency "pry"
|
41
|
+
spec.add_development_dependency "pry-rails", "~> 0.3"
|
42
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
43
|
+
spec.add_development_dependency "rubocop", "~> 1"
|
44
|
+
spec.add_development_dependency "standard", "~> 1"
|
45
|
+
spec.add_development_dependency "sqlite3", "~> 1.4"
|
46
|
+
spec.add_development_dependency "sidekiq", "~> 7"
|
47
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servitium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom de Grunt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|