services 7.2.1 → 7.3.0

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: 27e5b3e8dcab03964af30636e451cef509b9155fa721e1323dafdf0ece173364
4
- data.tar.gz: 76ad367be766868a392826d2b8600fbe96a97da1a42f4cda2f0a75ef64440f6a
3
+ metadata.gz: 07315b0de78bb20b6131a711ea5159cb98eb5d0750a2e8887acc17f8656d95ff
4
+ data.tar.gz: 93f14893f791086f48ba29c4dcf7b10f7ddb3d741a940769a11a35b3c200aef5
5
5
  SHA512:
6
- metadata.gz: 2302bdb005ff03507cb952a2feb4b9e7171f3e9823d151aacdc39528005c768780d10ad4e35d4fb283ca56d6666b8862ec08df0838a6b39db7a3beda64829a83
7
- data.tar.gz: 6d55fd8fc4e2e1780343ff14ee56cd9ef89052620e187952a563a5aed0a3b82bad7871b170023d2c9f4cfb4929ea6df776e8e9dc2906fc5b1667d1c512b8ca11
6
+ metadata.gz: 776986d66d7941661b8f9d412c745214a05e5a48db97f5a228b8ca8756c6383bb9f5938a504f9d6f5ad3c1396802e64ec63be86788cebdf298b344090d07c521
7
+ data.tar.gz: 795c3049f0867afb22fd8937a6ccf86ed27b91dafe66aafd385b58c1918360b6a8ee14cbd1f2553ecb300392acfbca8c37a2a47d6cd4c5ddbe55dda3c0c1ce96
@@ -5,8 +5,8 @@ require_relative 'services/logger/null'
5
5
  module Services
6
6
  include GemConfig::Base
7
7
 
8
- BackgroundProcessorNotFound = Class.new(StandardError)
9
- RedisNotFound = Class.new(StandardError)
8
+ NoBackgroundProcessorFound = Class.new(StandardError)
9
+ RedisNotFound = Class.new(StandardError)
10
10
 
11
11
  with_configuration do
12
12
  has :logger, default: Services::Logger::Null.new
@@ -26,10 +26,7 @@ end
26
26
  require_relative 'services/version'
27
27
  require_relative 'services/logger/file'
28
28
  require_relative 'services/logger/redis'
29
- begin
30
- require_relative 'services/asyncable'
31
- rescue Services::BackgroundProcessorNotFound
32
- end
29
+ require_relative 'services/asyncable'
33
30
  require_relative 'services/modules/call_logger'
34
31
  require_relative 'services/modules/exception_wrapper'
35
32
  require_relative 'services/modules/object_class'
@@ -1,13 +1,6 @@
1
1
  require 'active_support/concern'
2
2
  require 'global_id'
3
3
 
4
- begin
5
- require 'sidekiq'
6
- require 'sidekiq/api'
7
- rescue LoadError
8
- raise Services::BackgroundProcessorNotFound
9
- end
10
-
11
4
  module Services
12
5
  module Asyncable
13
6
  extend ActiveSupport::Concern
@@ -15,7 +8,22 @@ module Services
15
8
  ASYNC_METHOD_SUFFIXES = %i(async in at).freeze
16
9
 
17
10
  included do
18
- include Sidekiq::Worker
11
+ begin
12
+ require 'sidekiq'
13
+ require 'sidekiq/api'
14
+ rescue LoadError
15
+ else
16
+ include Sidekiq::Worker
17
+ return
18
+ end
19
+
20
+ begin
21
+ require 'sucker_punch'
22
+ rescue LoadError
23
+ raise Services::NoBackgroundProcessorFound
24
+ else
25
+ include SuckerPunch::Job
26
+ end
19
27
  end
20
28
 
21
29
  module ClassMethods
@@ -33,18 +41,22 @@ module Services
33
41
  args = args.map do |arg|
34
42
  GlobalID::Locator.locate(arg) || arg
35
43
  end
44
+
36
45
  # If the `call` method takes any kwargs and the last argument is a hash, symbolize the hash keys,
37
46
  # otherwise they won't be recognized as kwards when splatted.
38
47
  # Since the arguments to `perform` are serialized to the database before Sidekiq picks them up,
39
48
  # symbol keys are converted to strings.
40
49
  call_method = method(:call)
50
+
41
51
  # Find the first class that inherits from `Services::Base`.
42
52
  while !(call_method.owner < Services::Base)
43
53
  call_method = call_method.super_method
44
54
  end
55
+
45
56
  if call_method.parameters.map(&:first).grep(/\Akey/).any? && args.last.is_a?(Hash)
46
57
  args.last.symbolize_keys!
47
58
  end
59
+
48
60
  call *args
49
61
  end
50
62
  end
@@ -11,7 +11,10 @@ module Services
11
11
  def inherited(subclass)
12
12
  subclass.const_set :Error, Class.new(StandardError)
13
13
  subclass.public_send :include, Rails.application.routes.url_helpers if defined?(Rails)
14
- subclass.public_send :include, Asyncable if defined?(Asyncable)
14
+ begin
15
+ subclass.public_send :include, Asyncable
16
+ rescue Services::NoBackgroundProcessorFound
17
+ end
15
18
  subclass.public_send :prepend, CallLogger, ExceptionWrapper, UniquenessChecker
16
19
  end
17
20
 
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '7.2.1'.freeze
2
+ VERSION = '7.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: services
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.1
4
+ version: 7.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 3.0.4
249
+ rubygems_version: 3.1.2
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: A nifty service layer for your Rails app