services 8.0.1 → 9.0.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: a698bd8da6f4a212b731789e0ac3db4fbee0e0a097c89994d2b1ec9d3ec900ea
4
- data.tar.gz: 4689d6d5813efa452141b8cf4e41fcf542e94bbed9b2ad88e8ef7a8f47857fa1
3
+ metadata.gz: 69f65a0f459ea156e6523031658753b0128be29712385cfe4d2fc32f1c39e6b5
4
+ data.tar.gz: 5d0532802156ea0d3e4cbdc3c2a5189a7a16e580efeb989b7b6dec265d566cbc
5
5
  SHA512:
6
- metadata.gz: 3acfbd1a4c1db551629ab7e2ec8154ad6eb11ac19d576989f700c4c7e2e97ccea38016423c614b45840874d62ae6b1d4ff291c3c091676ebdd613b700ec944de
7
- data.tar.gz: f3e29cdc63402370f7f211a3bea262e807468743fa9e6bb4657cdbad5ac0867738c7693ee239f09483ee758c3d74aec0f92b777d183f156363d1c798008e7df5
6
+ metadata.gz: 52cf70d2876bcf2714dceebe3dba990e58fce96d2196e290667eb95513c470895a8819addaf6d7b37dd3b9973877a2251b887696aa6fbdcddda3c41eb046b6aa
7
+ data.tar.gz: 0523c7bb4b44635870a14caa242900ed93605ad5607bd21c93206bf06bfa6e1c911490e319c769425f1ab6d8d928d6477ef6f2dfebadb7f0ed7fa46a28a008e1
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
@@ -0,0 +1,43 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+
6
+ tests:
7
+ name: Tests
8
+ runs-on: ubuntu-latest
9
+
10
+ env:
11
+ RAILS_ENV: test
12
+
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby_version:
17
+ - 3.0
18
+ - 2.7
19
+
20
+ services:
21
+
22
+ redis:
23
+ image: redis
24
+ options: --entrypoint redis-server
25
+ ports:
26
+ - 6379:6379
27
+
28
+ steps:
29
+
30
+ - name: Check out code
31
+ uses: actions/checkout@v2
32
+
33
+ - name: Set up Ruby
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby_version }}
37
+ bundler-cache: true
38
+
39
+ - name: Install gems
40
+ run: bundle exec appraisal install
41
+
42
+ - name: Run tests
43
+ run: bundle exec appraisal rspec
data/Appraisals CHANGED
@@ -1,7 +1,3 @@
1
- appraise 'rails_5.2' do
2
- gem 'rails', '~> 5.2.0'
3
- end
4
-
5
1
  appraise 'rails_6.0' do
6
2
  gem 'rails', '~> 6.0.0'
7
3
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,152 @@
1
+ ## 9.0.0
2
+
3
+ * Drop support for Rails 5.2 and Ruby 2.6
4
+ * Exclude test files from release
5
+ * Add CI via GitHub Actions
6
+ * Make replacing ActiveRecord records in asyncable params more robust
7
+ * When calling a service async, make args and kwargs available as ivars
8
+
9
+ ## 8.0.1
10
+
11
+ * add missing `to_s`
12
+
13
+ ## 8.0.0
14
+
15
+ * handle kwargs correctly
16
+ * test with current rails versions
17
+
18
+ ## 7.3.3
19
+
20
+ * fix typo
21
+ * increase cache time to 30 days
22
+
23
+ ## 7.3.1
24
+
25
+ * fix loading background processor
26
+
27
+ ## 7.3.0
28
+
29
+ * allow using sucker_punch instead of sidekiq
30
+ * allow setting the method arity when allowing class method to be used in queries, since scopes shadow the arity of their procs
31
+
32
+ ## 7.2.0
33
+
34
+ * enable using class methods in queries
35
+
36
+ ## 7.1.2
37
+
38
+ * use select instead of pluck
39
+
40
+ ## 7.1.1
41
+
42
+ * fix typos
43
+
44
+ ## 7.1.0
45
+
46
+ * fix joining order classes
47
+ * refactor, formatting
48
+
49
+ ## 7.0.3
50
+
51
+ * fix identifying call method when calling service async
52
+ * remove gemnasium badge
53
+ * fix "buy me a coffee" link
54
+ * add "buy me a coffee" link to readme
55
+
56
+ ## 7.0.2
57
+
58
+ * symbolize hash keys for arguments to call method when kwargs are used
59
+ * dont modify args
60
+ * fix spec
61
+ * fix specs and readme
62
+
63
+ ## 7.0.1
64
+
65
+ * add table name to condition
66
+
67
+ ## 7.0.0
68
+
69
+ * add created_after and created_before as default conditions, allow overriding default conditions in query object
70
+
71
+ ## 6.0.5
72
+
73
+ * Revert "set default order for query if it was set to nil"
74
+
75
+ ## 6.0.4
76
+
77
+ * automatically add LEFT OUTER JOIN when trying to sort by a field on an association table
78
+ * set default order for query if it was set to nil
79
+
80
+ ## 6.0.3
81
+
82
+ * allow calling query service without params
83
+
84
+ ## 6.0.2
85
+
86
+ * add id_not as special query condition
87
+
88
+ ## 6.0.1
89
+
90
+ * allow calling query object with only arguments
91
+ * update sidekiq dev dependency to 5.x
92
+ * remove encoding comment
93
+ * add missing require
94
+ * syntax
95
+
96
+ ## 6.0.0
97
+
98
+ * dont specify ruby patchlevels in travis config
99
+ * use globalid to make args serializable
100
+ * remove bulk call async method
101
+ * remove async instance methods from services
102
+
103
+ ## 5.1.2
104
+
105
+ * dup passed in scope in query class before using it
106
+ * fix specs for ruby < 2.4
107
+ * update rails 5.1 to released version
108
+ * update travis config
109
+ * stop supporting rails 4.0 and 4.1, add 5.1.rc1
110
+
111
+ ## 5.1.1
112
+
113
+ * replace Fixnum with Integer to silence Ruby 2.4 warnings
114
+ * update ruby versions in travis config
115
+ * update travis config
116
+ * update ruby versions in travis config
117
+ * update travis build matrix, dont test ruby 2.4.0 with rails 4.0 or 4.1, allow ruby 2.4.0 with rails 4.2 to fail for now (until rails 4.2.8 is released with
118
+ out json 1.x dependency)
119
+ * increase sleep and waiting time in specs
120
+ * require active_record explicitly
121
+ * fix specs
122
+
123
+ ## 5.1.0
124
+
125
+ * test with ruby 2.4.0, clarify version requirements for ruby and redis
126
+ * update sidekiq dev dependency to ~> 4.0
127
+ * allow passing scope to query call
128
+
129
+ ## 5.0.0
130
+
131
+ * freeze constants
132
+ * use #public_send instead of #send where possible
133
+ * rename perform_* methods to call_*, closes #6
134
+
135
+ ## 4.3.0
136
+
137
+ * update travis config
138
+ * use pluck only on activerecord relations, from activesupport 5 on all enumerables respond to #pluck, which will call #[] on the contained objects [Manuel M
139
+ eurer]
140
+ * drop support for rails 3.2, add appraisal for testing
141
+ * update readme
142
+ * update ruby dependency in readme
143
+ * update travis config
144
+
145
+ ## 4.1.4
146
+
147
+ * update changelog
148
+ * fix finding find service class
149
+
1
150
  ## 4.1.3
2
151
 
3
152
  * Fix finding the find service class
@@ -29,9 +178,6 @@
29
178
  ## 3.1.1
30
179
 
31
180
  * Query does not have its own error, raise ArgumentError instead
32
-
33
- ## 3.1.0
34
-
35
181
  * Verify that query ids parameter is not nil
36
182
 
37
183
  ## 3.0.1
@@ -91,16 +237,4 @@
91
237
 
92
238
  ## 1.0.0
93
239
 
94
- * Added Redis logger
95
- * Moved file logger to separate class
96
- * Don't initialize file logger automatically for Rails apps anymore
97
- * Changed argument order for Redis and file logger, made `tags` parameter optional
98
-
99
- ## 0.4.0
100
-
101
- * Renamed `service_class` helper to `object_class`
102
-
103
- ## 0.3.4
104
-
105
- * Added `BaseFinder`
106
- * Updated uniqueness key
240
+ * First stable version
data/Guardfile CHANGED
@@ -68,9 +68,7 @@ guard 'rspec', cmd: 'bundle exec appraisal rspec' do
68
68
 
69
69
  # Specs
70
70
  watch(%r(^spec/.+_spec\.rb$))
71
- watch('spec/spec_helper.rb') { 'spec' }
72
- watch(%r(^spec/support/(.+)\.rb$)) { 'spec' }
73
71
 
74
72
  # Files
75
- watch(%r(^lib/(.+)\.rb$)) { |m| "spec/#{m[1]}_spec.rb" }
73
+ watch(%r(^lib/(.+)\.rb$)) { "spec/#{_1[1]}_spec.rb" }
76
74
  end
data/README.md CHANGED
@@ -1,8 +1,7 @@
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/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)
4
+ [![CI](https://github.com/manuelmeurer/services/actions/workflows/ci.yml/badge.svg)](https://github.com/manuelmeurer/services/actions/workflows/ci.yml)
6
5
 
7
6
  Services is a collection of modules and base classes that let you simply add a service layer to your Rails app.
8
7
 
@@ -18,9 +17,9 @@ For disambiguation: in this README, when you read "Services" with a uppercase "S
18
17
 
19
18
  ### Requirements
20
19
 
21
- #### Ruby >= 2.2.5
20
+ #### Ruby >= 2.7
22
21
 
23
- #### Rails >= 5.2
22
+ #### Rails >= 6.0
24
23
 
25
24
  #### Redis >= 3.0
26
25
 
@@ -33,18 +33,14 @@ module Services
33
33
  module ClassMethods
34
34
  ASYNC_METHOD_SUFFIXES.each do |async_method_suffix|
35
35
  define_method "call_#{async_method_suffix}" do |*args|
36
- args = args.map do |arg|
37
- arg.respond_to?(:to_global_id) ? arg.to_global_id.to_s : arg
38
- end
36
+ args = args.map(&Services.method(:replace_records_with_global_ids))
39
37
  self.public_send "perform_#{async_method_suffix}", *args
40
38
  end
41
39
  end
42
40
  end
43
41
 
44
42
  def perform(*args)
45
- args = args.map do |arg|
46
- GlobalID::Locator.locate(arg) || arg
47
- end
43
+ args = args.map(&Services.method(:replace_global_ids_with_records))
48
44
 
49
45
  call_method = method(:call)
50
46
 
@@ -60,6 +56,10 @@ module Services
60
56
  {}
61
57
  end
62
58
 
59
+ # Save args and kwargs in ivars so they can be used
60
+ # in the service, i.e. for rescheduling.
61
+ @_call_args, @_call_kwargs = args, kwargs
62
+
63
63
  call *args, **kwargs
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '8.0.1'.freeze
2
+ VERSION = '9.0.0'.freeze
3
3
  end
data/lib/services.rb CHANGED
@@ -14,12 +14,37 @@ module Services
14
14
  has :allowed_class_methods_in_queries, default: {}
15
15
  end
16
16
 
17
- def self.redis
18
- @redis ||= self.configuration.redis || (defined?(Redis.current) && Redis.current) or fail RedisNotFound, 'Redis not configured.'
19
- end
17
+ class << self
18
+ def redis
19
+ @redis ||= configuration.redis || (defined?(Redis.current) && Redis.current) or fail RedisNotFound, 'Redis not configured.'
20
+ end
21
+
22
+ def allow_class_method_in_queries(klass, method, arity = nil)
23
+ (configuration.allowed_class_methods_in_queries[klass.to_s] ||= {})[method.to_sym] = arity
24
+ end
25
+
26
+ def replace_records_with_global_ids(arg)
27
+ method = method(__method__)
28
+
29
+ case arg
30
+ when Array then arg.map(&method)
31
+ when Hash then arg.transform_keys(&method)
32
+ .transform_values(&method)
33
+ else arg.respond_to?(:to_global_id) ? "_#{arg.to_global_id.to_s}" : arg
34
+ end
35
+ end
36
+
37
+ def replace_global_ids_with_records(arg)
38
+ method = method(__method__)
20
39
 
21
- def self.allow_class_method_in_queries(klass, method, arity = nil)
22
- (configuration.allowed_class_methods_in_queries[klass.to_s] ||= {})[method.to_sym] = arity
40
+ case arg
41
+ when Array then arg.map(&method)
42
+ when Hash then arg.transform_keys(&method)
43
+ .transform_values(&method)
44
+ when String then (arg.starts_with?("_") && GlobalID::Locator.locate(arg[1..-1])) || arg
45
+ else arg
46
+ end
47
+ end
23
48
  end
24
49
  end
25
50
 
data/services.gemspec CHANGED
@@ -1,9 +1,15 @@
1
1
  lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
+
3
+ unless $LOAD_PATH.include?(lib)
4
+ $LOAD_PATH.unshift(lib)
5
+ end
3
6
 
4
7
  require 'services/version'
5
8
 
6
9
  Gem::Specification.new do |gem|
10
+ files = `git ls-files`.split($/)
11
+ test_files = files.grep(%r(^spec/))
12
+
7
13
  gem.name = 'services'
8
14
  gem.version = Services::VERSION
9
15
  gem.platform = Gem::Platform::RUBY
@@ -11,12 +17,12 @@ Gem::Specification.new do |gem|
11
17
  gem.email = 'manuel@krautcomputing.com'
12
18
  gem.summary = 'A nifty service layer for your Rails app'
13
19
  gem.description = 'A nifty service layer for your Rails app'
14
- gem.homepage = 'http://manuelmeurer.github.io/services'
20
+ gem.homepage = 'https://manuelmeurer.com/services/'
15
21
  gem.license = 'MIT'
16
- gem.required_ruby_version = '>= 2.2.5'
17
- gem.files = `git ls-files`.split($/)
18
- gem.executables = gem.files.grep(%r(^bin/)).map { |f| File.basename(f) }
19
- gem.test_files = gem.files.grep(%r(^(test|spec|features)/))
22
+ gem.required_ruby_version = '>= 2.7'
23
+ gem.files = files - test_files
24
+ gem.executables = gem.files.grep(%r(\Abin/)).map(&File.method(:basename))
25
+ gem.test_files = test_files
20
26
  gem.require_paths = ['lib']
21
27
 
22
28
  gem.add_development_dependency 'rake', '>= 0.9.0'
@@ -29,6 +35,6 @@ Gem::Specification.new do |gem|
29
35
  gem.add_development_dependency 'timecop', '~> 0.7'
30
36
  gem.add_development_dependency 'sqlite3', '~> 1.3'
31
37
  gem.add_development_dependency 'appraisal', '~> 2.1'
32
- gem.add_runtime_dependency 'rails', '>= 4.2'
38
+ gem.add_runtime_dependency 'rails', '>= 6.0'
33
39
  gem.add_runtime_dependency 'gem_config', '~> 0.3'
34
40
  end
@@ -9,7 +9,7 @@ describe Services::Base::CallLogger do
9
9
  service.call *args
10
10
  caller_regex = /\A#{Regexp.escape __FILE__}:\d+\z/
11
11
  expect(logs.first).to match(
12
- message: "START with args: #{args}",
12
+ message: "START with args: #{args}, kwargs: {}",
13
13
  meta: {
14
14
  caller: a_string_matching(caller_regex),
15
15
  service: service.class.to_s,
@@ -16,7 +16,7 @@ describe Services::Query do
16
16
  {
17
17
  comment => comment.id,
18
18
  comments => comments.map(&:id),
19
- Comment.all => Comment.all.pluck(:id)
19
+ Comment.all => Comment.all.map { |comment| { id: comment.id } }
20
20
  }.each do |condition_before, condition_after|
21
21
  expect { Services::Posts::FindRaiseConditions.call [], comment: condition_before }.to raise_error({ comment_id: condition_after }.to_json)
22
22
  end
@@ -20,15 +20,15 @@ def wait_for_all_jobs_to_finish
20
20
  end
21
21
  end
22
22
 
23
- def wait_for_job_to_run(job_class, *args, &block)
24
- job_class.call_async(*args).tap do |jid|
23
+ def wait_for_job_to_run(job_class, *args, **kwargs, &block)
24
+ job_class.call_async(*args, **kwargs).tap do |jid|
25
25
  wait_for { worker_with_jid(jid) }
26
26
  block.call if block_given?
27
27
  end
28
28
  end
29
29
 
30
- def wait_for_job_to_run_and_finish(job_class, *args, &block)
31
- wait_for_job_to_run(job_class, *args, &block).tap do |jid|
30
+ def wait_for_job_to_run_and_finish(job_class, *args, **kwargs, &block)
31
+ wait_for_job_to_run(job_class, *args, **kwargs, &block).tap do |jid|
32
32
  wait_for { worker_with_jid(jid).nil? }
33
33
  end
34
34
  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: 8.0.1
4
+ version: 9.0.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: 2021-08-20 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '4.2'
159
+ version: '6.0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '4.2'
166
+ version: '6.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: gem_config
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -184,8 +184,9 @@ executables: []
184
184
  extensions: []
185
185
  extra_rdoc_files: []
186
186
  files:
187
+ - ".github/dependabot.yml"
188
+ - ".github/workflows/ci.yml"
187
189
  - ".gitignore"
188
- - ".travis.yml"
189
190
  - Appraisals
190
191
  - CHANGELOG.md
191
192
  - Gemfile
@@ -193,7 +194,6 @@ files:
193
194
  - LICENSE.txt
194
195
  - README.md
195
196
  - Rakefile
196
- - gemfiles/rails_5.2.gemfile
197
197
  - gemfiles/rails_6.0.gemfile
198
198
  - gemfiles/rails_6.1.gemfile
199
199
  - lib/services.rb
@@ -227,7 +227,7 @@ files:
227
227
  - spec/support/redis-server
228
228
  - spec/support/shared.rb
229
229
  - spec/support/test_services.rb
230
- homepage: http://manuelmeurer.github.io/services
230
+ homepage: https://manuelmeurer.com/services/
231
231
  licenses:
232
232
  - MIT
233
233
  metadata: {}
@@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
239
  requirements:
240
240
  - - ">="
241
241
  - !ruby/object:Gem::Version
242
- version: 2.2.5
242
+ version: '2.7'
243
243
  required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  requirements:
245
245
  - - ">="
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.2
5
- - 2.3
6
- - 2.4
7
- services:
8
- - redis-server
9
- before_install:
10
- - gem update --system
11
- - gem update bundler
12
- gemfile:
13
- - gemfiles/rails_4.2.gemfile
14
- - gemfiles/rails_5.0.gemfile
15
- - gemfiles/rails_5.1.gemfile
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.2.0"
6
-
7
- gemspec path: "../"