services 4.1.4 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +8 -4
- data/Appraisals +15 -0
- data/Guardfile +1 -1
- data/README.md +11 -10
- data/gemfiles/rails_4.0.gemfile +7 -0
- data/gemfiles/rails_4.1.gemfile +7 -0
- data/gemfiles/rails_4.2.gemfile +7 -0
- data/gemfiles/rails_5.0.gemfile +7 -0
- data/lib/services/base.rb +1 -1
- data/lib/services/version.rb +1 -1
- data/services.gemspec +2 -1
- metadata +24 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bd1a27e2051a3dfce7845c6d24396c007f17c51
|
4
|
+
data.tar.gz: 55072f152a1356ce1f6be21d3b60ec92ba45ac78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fba150903e4924d507e1f13526578e47f6b0164d170d89d6c6f7f96564d657ab2bc1dc5901d7a2e1bbbd9146ddc4de4d9e8d1a5c3f228ca9ca7aed2e864c1e7
|
7
|
+
data.tar.gz: 4ae154068e6e42f69b79f4b20555f77e73e5499c5e2e072a3e8c77ecb1e6049404b7883486c712351ee534277b68d941de9132f7d5c1e6a001ead12e553dcba6
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.1
|
5
|
-
- 2.2
|
6
|
-
- 2.3.0
|
3
|
+
- 2.2.5
|
4
|
+
- 2.3.1
|
7
5
|
services:
|
8
6
|
- redis-server
|
9
7
|
before_install:
|
10
8
|
- gem update --system
|
11
9
|
- gem update bundler
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/rails_4.0.gemfile
|
12
|
+
- gemfiles/rails_4.1.gemfile
|
13
|
+
- gemfiles/rails_4.2.gemfile
|
14
|
+
- gemfiles/rails_5.0.gemfile
|
15
|
+
sudo: false
|
data/Appraisals
ADDED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -19,9 +19,9 @@ For disambiguation: in this README, when you read "Services" with a uppercase "S
|
|
19
19
|
|
20
20
|
### Requirements
|
21
21
|
|
22
|
-
#### Ruby >= 2.
|
22
|
+
#### Ruby >= 2.2.3
|
23
23
|
|
24
|
-
#### Rails >=
|
24
|
+
#### Rails >= 4.0
|
25
25
|
|
26
26
|
#### Redis >= 2.8
|
27
27
|
|
@@ -57,7 +57,8 @@ Follow these conventions when using Services in your Rails app, and you'll be fi
|
|
57
57
|
* Let your services inherit from `Services::Base`
|
58
58
|
* Let your query objects inherit from `Services::Query`
|
59
59
|
* Put your services in `app/services/`
|
60
|
-
*
|
60
|
+
* Decide if you want to use a `Services` namespace or not. Namespacing your service allows you to use a name for them that some other class or module in your app has (e.g. you can have a `Services::Maintenance` service, yet also a `Maintenance` module in `lib`). Not using a namespace saves you from writing `Services::` everytime you want to reference a service in your app. Both approaches are fine, pick one and stick to it.
|
61
|
+
* Give your services "verby" names, e.g. `app/services/users/delete.rb` defines `Users::Delete` (or `Services::Users::Delete`, see above). If a service operates on multiple models or no models at all, don't namespace them (`Services::DoStuff`) or namespace them by logical groups unrelated to models (`Services::Maintenance::CleanOldStuff`, `Services::Maintenance::SendDailySummary`, etc.)
|
61
62
|
* Some services call other services. Try to not combine multiple calls to other services and business logic in one service. Instead, some services should contain only business logic and other services only a bunch of service calls but no (or little) business logic. This keeps your services nice and modular.
|
62
63
|
|
63
64
|
### Configuration
|
@@ -67,22 +68,22 @@ You can/should configure Services in an initializer:
|
|
67
68
|
```ruby
|
68
69
|
# config/initializers/services.rb
|
69
70
|
Services.configure do |config|
|
70
|
-
config.logger = Services::Logger::Redis.new(Redis.new) # see Logging
|
71
|
-
config.redis = Redis.new # optional, if Redis.current is defined. Otherwise it is recommended to use
|
72
|
-
# a [connection pool](https://github.com/mperham/connection_pool).
|
71
|
+
config.logger = Services::Logger::Redis.new(Redis.new) # see [Logging](#Logging)
|
72
|
+
config.redis = Redis.new # optional, if `Redis.current` is defined. Otherwise it is recommended to use
|
73
|
+
# a [connection pool](https://github.com/mperham/connection_pool) here instead of simply `Redis.new`.
|
73
74
|
end
|
74
75
|
```
|
75
76
|
|
76
|
-
### Rails autoload fix
|
77
|
+
### Rails autoload fix for `Services` namespace
|
77
78
|
|
78
|
-
By default, Rails expects `app/services/users/delete.rb` to define `Users::Delete
|
79
|
+
By default, Rails expects `app/services/users/delete.rb` to define `Users::Delete`. If you want to use the `Services` namespace for your services, we want it to expect `Services::Users::Delete`. To make this work, add the `app` folder to the autoload path:
|
79
80
|
|
80
81
|
```ruby
|
81
82
|
# config/application.rb
|
82
83
|
config.autoload_paths += [config.root.join('app')]
|
83
84
|
```
|
84
85
|
|
85
|
-
This looks as if it might break things, but
|
86
|
+
This looks as if it might break things, but AFAIK it has never cause problems so far.
|
86
87
|
|
87
88
|
### Services::Base
|
88
89
|
|
@@ -227,7 +228,7 @@ to be described...
|
|
227
228
|
|
228
229
|
### Background/asynchronous processing
|
229
230
|
|
230
|
-
to be
|
231
|
+
Each service can run synchronously (i.e. blocking/in the foreground) or asynchronously (i.e. non-blocking/in the background). If you want to run a service in the background, make sure it takes only arguments that can be serialized without problems (i.e. integers, strings, etc.). The background processing is done by Sidekiq, so you must set up Sidekiq in the Services initializer.
|
231
232
|
|
232
233
|
## Installation
|
233
234
|
|
data/lib/services/base.rb
CHANGED
@@ -60,7 +60,7 @@ module Services
|
|
60
60
|
ids, objects = _split_ids_and_objects(ids_or_objects, klass)
|
61
61
|
if ids.any?
|
62
62
|
objects_from_ids = find_service(klass).call(ids)
|
63
|
-
object_ids = if objects_from_ids.
|
63
|
+
object_ids = if objects_from_ids.is_a?(ActiveRecord::Relation)
|
64
64
|
objects_from_ids.pluck(:id)
|
65
65
|
else
|
66
66
|
objects_from_ids.map(&:id)
|
data/lib/services/version.rb
CHANGED
data/services.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.add_development_dependency 'tries', '~> 0.3'
|
30
30
|
gem.add_development_dependency 'timecop', '~> 0.7'
|
31
31
|
gem.add_development_dependency 'sqlite3', '~> 1.3'
|
32
|
-
gem.
|
32
|
+
gem.add_development_dependency 'appraisal', '~> 2.1'
|
33
|
+
gem.add_runtime_dependency 'rails', '>= 4.0.0'
|
33
34
|
gem.add_runtime_dependency 'gem_config', '~> 0.3'
|
34
35
|
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: 4.
|
4
|
+
version: 4.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: 2016-
|
11
|
+
date: 2016-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -122,20 +122,34 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: appraisal
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.1'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.1'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rails
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
145
|
+
version: 4.0.0
|
132
146
|
type: :runtime
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
152
|
+
version: 4.0.0
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: gem_config
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,12 +172,17 @@ extra_rdoc_files: []
|
|
158
172
|
files:
|
159
173
|
- ".gitignore"
|
160
174
|
- ".travis.yml"
|
175
|
+
- Appraisals
|
161
176
|
- CHANGELOG.md
|
162
177
|
- Gemfile
|
163
178
|
- Guardfile
|
164
179
|
- LICENSE.txt
|
165
180
|
- README.md
|
166
181
|
- Rakefile
|
182
|
+
- gemfiles/rails_4.0.gemfile
|
183
|
+
- gemfiles/rails_4.1.gemfile
|
184
|
+
- gemfiles/rails_4.2.gemfile
|
185
|
+
- gemfiles/rails_5.0.gemfile
|
167
186
|
- lib/services.rb
|
168
187
|
- lib/services/asyncable.rb
|
169
188
|
- lib/services/base.rb
|
@@ -214,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
233
|
version: '0'
|
215
234
|
requirements: []
|
216
235
|
rubyforge_project:
|
217
|
-
rubygems_version: 2.
|
236
|
+
rubygems_version: 2.6.6
|
218
237
|
signing_key:
|
219
238
|
specification_version: 4
|
220
239
|
summary: A nifty service layer for your Rails app
|