services 7.3.0 → 8.0.1

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: 07315b0de78bb20b6131a711ea5159cb98eb5d0750a2e8887acc17f8656d95ff
4
- data.tar.gz: 93f14893f791086f48ba29c4dcf7b10f7ddb3d741a940769a11a35b3c200aef5
3
+ metadata.gz: a698bd8da6f4a212b731789e0ac3db4fbee0e0a097c89994d2b1ec9d3ec900ea
4
+ data.tar.gz: 4689d6d5813efa452141b8cf4e41fcf542e94bbed9b2ad88e8ef7a8f47857fa1
5
5
  SHA512:
6
- metadata.gz: 776986d66d7941661b8f9d412c745214a05e5a48db97f5a228b8ca8756c6383bb9f5938a504f9d6f5ad3c1396802e64ec63be86788cebdf298b344090d07c521
7
- data.tar.gz: 795c3049f0867afb22fd8937a6ccf86ed27b91dafe66aafd385b58c1918360b6a8ee14cbd1f2553ecb300392acfbca8c37a2a47d6cd4c5ddbe55dda3c0c1ce96
6
+ metadata.gz: 3acfbd1a4c1db551629ab7e2ec8154ad6eb11ac19d576989f700c4c7e2e97ccea38016423c614b45840874d62ae6b1d4ff291c3c091676ebdd613b700ec944de
7
+ data.tar.gz: f3e29cdc63402370f7f211a3bea262e807468743fa9e6bb4657cdbad5ac0867738c7693ee239f09483ee758c3d74aec0f92b777d183f156363d1c798008e7df5
data/Appraisals CHANGED
@@ -1,11 +1,11 @@
1
- appraise 'rails_4.2' do
2
- gem 'rails', '~> 4.2.0'
1
+ appraise 'rails_5.2' do
2
+ gem 'rails', '~> 5.2.0'
3
3
  end
4
4
 
5
- appraise 'rails_5.0' do
6
- gem 'rails', '~> 5.0.0'
5
+ appraise 'rails_6.0' do
6
+ gem 'rails', '~> 6.0.0'
7
7
  end
8
8
 
9
- appraise 'rails_5.1' do
10
- gem 'rails', '~> 5.1.0'
9
+ appraise 'rails_6.1' do
10
+ gem 'rails', '~> 6.1.0'
11
11
  end
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Services
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/services.png)](http://badge.fury.io/rb/services)
4
- [![Build Status](https://secure.travis-ci.org/krautcomputing/services.png)](http://travis-ci.org/krautcomputing/services)
5
- [![Code Climate](https://codeclimate.com/github/krautcomputing/services.png)](https://codeclimate.com/github/krautcomputing/services)
4
+ [![Build Status](https://secure.travis-ci.org/manuelmeurer/services.png)](http://travis-ci.org/manuelmeurer/services)
5
+ [![Code Climate](https://codeclimate.com/github/manuelmeurer/services.png)](https://codeclimate.com/github/manuelmeurer/services)
6
6
 
7
7
  Services is a collection of modules and base classes that let you simply add a service layer to your Rails app.
8
8
 
@@ -20,7 +20,7 @@ For disambiguation: in this README, when you read "Services" with a uppercase "S
20
20
 
21
21
  #### Ruby >= 2.2.5
22
22
 
23
- #### Rails >= 4.2
23
+ #### Rails >= 5.2
24
24
 
25
25
  #### Redis >= 3.0
26
26
 
@@ -28,7 +28,7 @@ Redis is used at several points, e.g. to store information about the currently r
28
28
 
29
29
  #### Postgres (optional)
30
30
 
31
- The SQL that `Services::Query` (discussed further down) generates is optimized for Postgres. It might work with other databases but it's not guaranteed. If you're not using Postgres, you can still use all other parts of Services, just don't use `Services::Query` or, even better, submit a [pull request](https://github.com/krautcomputing/services/issues) that fixes it to work with your database!
31
+ The SQL that `Services::Query` (discussed further down) generates is optimized for Postgres. It might work with other databases but it's not guaranteed. If you're not using Postgres, you can still use all other parts of Services, just don't use `Services::Query` or, even better, submit a [pull request](https://github.com/manuelmeurer/services/issues) that fixes it to work with your database!
32
32
 
33
33
  #### Sidekiq (optional)
34
34
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.2.0"
5
+ gem "rails", "~> 5.2.0"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0"
5
+ gem "rails", "~> 6.0.0"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.1.0"
5
+ gem "rails", "~> 6.1.0"
6
6
 
7
7
  gemspec path: "../"
@@ -8,21 +8,25 @@ module Services
8
8
  ASYNC_METHOD_SUFFIXES = %i(async in at).freeze
9
9
 
10
10
  included do
11
+ sidekiq_loaded = false
12
+
11
13
  begin
12
14
  require 'sidekiq'
13
15
  require 'sidekiq/api'
14
16
  rescue LoadError
15
17
  else
16
18
  include Sidekiq::Worker
17
- return
19
+ sidekiq_loaded = true
18
20
  end
19
21
 
20
- begin
21
- require 'sucker_punch'
22
- rescue LoadError
23
- raise Services::NoBackgroundProcessorFound
24
- else
25
- include SuckerPunch::Job
22
+ unless sidekiq_loaded
23
+ begin
24
+ require 'sucker_punch'
25
+ rescue LoadError
26
+ raise Services::NoBackgroundProcessorFound
27
+ else
28
+ include SuckerPunch::Job
29
+ end
26
30
  end
27
31
  end
28
32
 
@@ -30,7 +34,7 @@ module Services
30
34
  ASYNC_METHOD_SUFFIXES.each do |async_method_suffix|
31
35
  define_method "call_#{async_method_suffix}" do |*args|
32
36
  args = args.map do |arg|
33
- arg.respond_to?(:to_global_id) ? arg.to_global_id : arg
37
+ arg.respond_to?(:to_global_id) ? arg.to_global_id.to_s : arg
34
38
  end
35
39
  self.public_send "perform_#{async_method_suffix}", *args
36
40
  end
@@ -42,10 +46,6 @@ module Services
42
46
  GlobalID::Locator.locate(arg) || arg
43
47
  end
44
48
 
45
- # If the `call` method takes any kwargs and the last argument is a hash, symbolize the hash keys,
46
- # otherwise they won't be recognized as kwards when splatted.
47
- # Since the arguments to `perform` are serialized to the database before Sidekiq picks them up,
48
- # symbol keys are converted to strings.
49
49
  call_method = method(:call)
50
50
 
51
51
  # Find the first class that inherits from `Services::Base`.
@@ -53,11 +53,14 @@ module Services
53
53
  call_method = call_method.super_method
54
54
  end
55
55
 
56
- if call_method.parameters.map(&:first).grep(/\Akey/).any? && args.last.is_a?(Hash)
57
- args.last.symbolize_keys!
56
+ # If the `call` method takes any kwargs and the last argument is a hash, pass them to the method as kwargs.
57
+ kwargs = if call_method.parameters.map(&:first).grep(/\Akey/).any? && args.last.is_a?(Hash)
58
+ args.pop.symbolize_keys
59
+ else
60
+ {}
58
61
  end
59
62
 
60
- call *args
63
+ call *args, **kwargs
61
64
  end
62
65
  end
63
66
  end
data/lib/services/base.rb CHANGED
@@ -25,7 +25,7 @@ module Services
25
25
  @id = SecureRandom.hex(6)
26
26
  end
27
27
 
28
- def call(*args)
28
+ def call(*args, **kwargs)
29
29
  raise NotImplementedError
30
30
  end
31
31
 
@@ -27,9 +27,9 @@ module Services
27
27
  end
28
28
  end
29
29
 
30
- def call(*args)
30
+ def call(*args, **kwargs)
31
31
  unless self.class.call_logging_disabled
32
- log "START with args: #{args}", caller: caller
32
+ log "START with args: #{args}, kwargs: #{kwargs}", caller: caller
33
33
  start = Time.now
34
34
  end
35
35
  begin
@@ -1,7 +1,7 @@
1
1
  module Services
2
2
  class Base
3
3
  module ExceptionWrapper
4
- def call(*args)
4
+ def call(*args, **kwargs)
5
5
  super
6
6
  rescue StandardError => e
7
7
  if e.class <= self.class::Error
@@ -14,7 +14,7 @@ module Services
14
14
  ).freeze
15
15
 
16
16
  MAX_RETRIES = 10.freeze
17
- ONE_DAY = (60 * 60 * 24).freeze
17
+ THIRTY_DAYS = (60 * 60 * 24 * 30).freeze
18
18
 
19
19
  def self.prepended(mod)
20
20
  mod.const_set :NotUniqueError, Class.new(mod::Error)
@@ -37,12 +37,12 @@ module Services
37
37
  else
38
38
  @_uniqueness_keys ||= []
39
39
  @_uniqueness_keys << new_uniqueness_key
40
- Services.redis.setex new_uniqueness_key, ONE_DAY, @id
40
+ Services.redis.setex new_uniqueness_key, THIRTY_DAYS, @id
41
41
  true
42
42
  end
43
43
  end
44
44
 
45
- def call(*args)
45
+ def call(*args, **kwargs)
46
46
  @_service_args = args
47
47
  super
48
48
  rescue self.class::NotUniqueError => e
@@ -103,7 +103,7 @@ module Services
103
103
  end
104
104
 
105
105
  def increase_error_count
106
- Services.redis.setex error_count_key, retry_delay + ONE_DAY, error_count + 1
106
+ Services.redis.setex error_count_key, retry_delay + THIRTY_DAYS, error_count + 1
107
107
  end
108
108
 
109
109
  def uniqueness_key(args)
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '7.3.0'.freeze
2
+ VERSION = '8.0.1'.freeze
3
3
  end
data/services.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.email = 'manuel@krautcomputing.com'
12
12
  gem.summary = 'A nifty service layer for your Rails app'
13
13
  gem.description = 'A nifty service layer for your Rails app'
14
- gem.homepage = 'http://krautcomputing.github.io/services'
14
+ gem.homepage = 'http://manuelmeurer.github.io/services'
15
15
  gem.license = 'MIT'
16
16
  gem.required_ruby_version = '>= 2.2.5'
17
17
  gem.files = `git ls-files`.split($/)
@@ -81,14 +81,14 @@ module Services
81
81
  end
82
82
 
83
83
  class EmptyService < Services::Base
84
- def call(*args)
84
+ def call(*args, **kwargs)
85
85
  end
86
86
  end
87
87
 
88
88
  class EmptyServiceWithoutCallLogging < Services::Base
89
89
  disable_call_logging
90
90
 
91
- def call(*args)
91
+ def call(*args, **kwargs)
92
92
  end
93
93
  end
94
94
 
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.3.0
4
+ version: 8.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-27 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -193,9 +193,9 @@ files:
193
193
  - LICENSE.txt
194
194
  - README.md
195
195
  - Rakefile
196
- - gemfiles/rails_4.2.gemfile
197
- - gemfiles/rails_5.0.gemfile
198
- - gemfiles/rails_5.1.gemfile
196
+ - gemfiles/rails_5.2.gemfile
197
+ - gemfiles/rails_6.0.gemfile
198
+ - gemfiles/rails_6.1.gemfile
199
199
  - lib/services.rb
200
200
  - lib/services/asyncable.rb
201
201
  - lib/services/base.rb
@@ -227,11 +227,11 @@ files:
227
227
  - spec/support/redis-server
228
228
  - spec/support/shared.rb
229
229
  - spec/support/test_services.rb
230
- homepage: http://krautcomputing.github.io/services
230
+ homepage: http://manuelmeurer.github.io/services
231
231
  licenses:
232
232
  - MIT
233
233
  metadata: {}
234
- post_install_message:
234
+ post_install_message:
235
235
  rdoc_options: []
236
236
  require_paths:
237
237
  - lib
@@ -246,8 +246,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 3.1.2
250
- signing_key:
249
+ rubygems_version: 3.2.23
250
+ signing_key:
251
251
  specification_version: 4
252
252
  summary: A nifty service layer for your Rails app
253
253
  test_files: