roo_on_rails 2.0.0.pre.pre.1 → 2.0.0.pre.pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.circleci/config.yml.erb +1 -1
- data/Appraisals +9 -4
- data/CHANGELOG.md +6 -0
- data/README.md +0 -11
- data/lib/roo_on_rails.rb +0 -1
- data/lib/roo_on_rails/config.rb +0 -8
- data/lib/roo_on_rails/default.env +0 -4
- data/lib/roo_on_rails/version.rb +1 -1
- data/roo_on_rails.gemspec +2 -2
- metadata +21 -27
- data/README.routemaster_client.md +0 -103
- data/lib/roo_on_rails/railties/routemaster.rb +0 -42
- data/lib/roo_on_rails/routemaster/lifecycle_events.rb +0 -63
- data/lib/roo_on_rails/routemaster/publish_lifecycle_events.rb +0 -13
- data/lib/roo_on_rails/routemaster/publisher.rb +0 -74
- data/lib/roo_on_rails/routemaster/publishers.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd0078f99de5de6df13bb2f3432826fe10ce2a42
|
4
|
+
data.tar.gz: 39dc8387999e301ae72bd79f478abea4ae254425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de9ad52a69426d76ceffaa4441a96b12c5d9ac304f739d8fd96fef6c0ffd3c593544b3424435785e4e327952067616e01b983ddd0e9b71e945a10b3e7a2c535d
|
7
|
+
data.tar.gz: a86864238bffd84afa3c799086c7171498bb2437e8c17cd654dc92a419cf67ee6e8754fe3833da04004fa8f00c10365031bafc6280181083ecf0035b0e266ab2
|
data/.circleci/config.yml.erb
CHANGED
data/Appraisals
CHANGED
@@ -1,24 +1,29 @@
|
|
1
1
|
appraise 'rails-4' do
|
2
2
|
gem 'rails', '~> 4.2'
|
3
|
-
gem 'sqlite3'
|
3
|
+
gem 'sqlite3', '~> 1.3.6'
|
4
4
|
gem 'pg', '~> 0.11'
|
5
|
+
gem 'sprockets', '~>3.0'
|
6
|
+
gem 'rake', '13.0.1'
|
5
7
|
end
|
6
8
|
|
7
9
|
appraise 'rails-5' do
|
8
10
|
gem 'rails', '~> 5.0.0'
|
9
|
-
gem 'sqlite3'
|
11
|
+
gem 'sqlite3', '~> 1.3.6'
|
10
12
|
gem 'pg', '~> 0.18'
|
13
|
+
gem 'rake', '13.0.1'
|
11
14
|
end
|
12
15
|
|
13
16
|
appraise 'rails-5-1' do
|
14
17
|
gem 'rails', '~> 5.1.0'
|
15
|
-
gem 'sqlite3'
|
18
|
+
gem 'sqlite3', '~> 1.3.6'
|
16
19
|
gem 'pg', '~> 0.18'
|
20
|
+
gem 'rake', '13.0.1'
|
17
21
|
end
|
18
22
|
|
19
23
|
appraise 'rails-5-2' do
|
20
24
|
gem 'rails', '~> 5.2.0'
|
21
25
|
gem 'bootsnap', '>= 1.1.0', require: false
|
22
|
-
gem 'sqlite3'
|
26
|
+
gem 'sqlite3', '~> 1.3.6'
|
23
27
|
gem 'pg', '~> 0.18'
|
28
|
+
gem 'rake', '13.0.1'
|
24
29
|
end
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,6 @@
|
|
30
30
|
- [Datadog Integration](#datadog-integration)
|
31
31
|
- [Heroku metrics](#heroku-metrics)
|
32
32
|
- [Custom application metrics](#custom-application-metrics)
|
33
|
-
- [Routemaster Client](#routemaster-client)
|
34
33
|
- [API Authentication](#api-authentication)
|
35
34
|
- [Command features](#command-features)
|
36
35
|
- [Usage](#usage)
|
@@ -302,16 +301,6 @@ The following tags will automatically be added to all your metrics and their val
|
|
302
301
|
* `HOPPER_APP_NAME`+`HOPPER_ECS_CLUSTER_NAME` – automatically set by Hopper (e.g. `notifications-staging`);
|
303
302
|
* Defaults to `unknown`.
|
304
303
|
|
305
|
-
### Routemaster Client
|
306
|
-
|
307
|
-
When `ROUTEMASTER_ENABLED` is set to `true` we attempt to configure [`routemaster-client`](https://github.com/deliveroo/routemaster-client) on your application. In order for this to happen, set the following environment variables:
|
308
|
-
|
309
|
-
* `ROUTEMASTER_URL` – the full URL of your Routemaster application (mandatory)
|
310
|
-
* `ROUTEMASTER_UUID` – the UUID of your application, e.g. `logistics-dashboard` (mandatory)
|
311
|
-
* `ROUTEMASTER_VERIFY_SSL` – set to false if your Routemaster application is not served with a valid cert. (optional)
|
312
|
-
|
313
|
-
If you then want to enable the publishing of events onto the event bus, you need to set `ROUTEMASTER_PUBLISHING_ENABLED` to `true` and implement publishers as needed. An example of how to do this is detailed in [`README.routemaster_client.md`](README.routemaster_client.md).
|
314
|
-
|
315
304
|
### API Authentication
|
316
305
|
|
317
306
|
RooOnRails provides a concern which will make adding rotatable API authentication to your service a breeze:
|
data/lib/roo_on_rails.rb
CHANGED
@@ -12,6 +12,5 @@ if defined?(Rails)
|
|
12
12
|
require 'roo_on_rails/railties/sidekiq_integration'
|
13
13
|
require 'roo_on_rails/railties/rake_tasks'
|
14
14
|
require 'roo_on_rails/railties/google_oauth'
|
15
|
-
require 'roo_on_rails/railties/routemaster'
|
16
15
|
require 'roo_on_rails/railties/roo_identity'
|
17
16
|
end
|
data/lib/roo_on_rails/config.rb
CHANGED
@@ -25,14 +25,6 @@ module RooOnRails
|
|
25
25
|
ENV.fetch('GOOGLE_AUTH_CONTROLLER')
|
26
26
|
end
|
27
27
|
|
28
|
-
def routemaster_enabled?
|
29
|
-
enabled? 'ROUTEMASTER_ENABLED', default: false
|
30
|
-
end
|
31
|
-
|
32
|
-
def routemaster_publishing_enabled?
|
33
|
-
enabled? 'ROUTEMASTER_PUBLISHING_ENABLED', default: false
|
34
|
-
end
|
35
|
-
|
36
28
|
private
|
37
29
|
|
38
30
|
ENABLED_PATTERN = /\A(YES|TRUE|ON|1)\Z/i
|
@@ -6,10 +6,6 @@ GOOGLE_AUTH_PATH_PREFIX=/auth
|
|
6
6
|
GOOGLE_AUTH_CONTROLLER=sessions
|
7
7
|
RACK_SERVICE_TIMEOUT=10
|
8
8
|
RACK_WAIT_TIMEOUT=30
|
9
|
-
ROUTEMASTER_URL=''
|
10
|
-
ROUTEMASTER_UUID=''
|
11
|
-
ROUTEMASTER_ENABLED=false
|
12
|
-
ROUTEMASTER_PUBLISHING_ENABLED=false
|
13
9
|
SIDEKIQ_ENABLED=true
|
14
10
|
SIDEKIQ_THREADS=25
|
15
11
|
SIDEKIQ_DATABASE_REAPING_FREQUENCY=10
|
data/lib/roo_on_rails/version.rb
CHANGED
data/roo_on_rails.gemspec
CHANGED
@@ -23,18 +23,18 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_runtime_dependency 'dotenv-rails', '~> 2.1'
|
25
25
|
spec.add_runtime_dependency 'rails', '>= 3.2.22', '< 5.3'
|
26
|
+
spec.add_runtime_dependency 'sprockets', '~>3.0'
|
26
27
|
spec.add_runtime_dependency 'platform-api', '~> 2.0'
|
27
28
|
spec.add_runtime_dependency 'hashie', '~> 3.4'
|
28
29
|
spec.add_runtime_dependency 'rack-timeout', '>= 0.4.0'
|
29
30
|
spec.add_runtime_dependency 'rack-ssl-enforcer'
|
30
31
|
spec.add_runtime_dependency 'octokit'
|
31
32
|
spec.add_runtime_dependency 'hirefire-resource'
|
32
|
-
spec.add_runtime_dependency 'sidekiq'
|
33
|
+
spec.add_runtime_dependency 'sidekiq', '< 6.0.0'
|
33
34
|
spec.add_runtime_dependency 'dogstatsd-ruby'
|
34
35
|
spec.add_runtime_dependency 'omniauth-google-oauth2'
|
35
36
|
spec.add_runtime_dependency 'faraday'
|
36
37
|
spec.add_runtime_dependency 'faraday_middleware'
|
37
|
-
spec.add_runtime_dependency 'routemaster-client'
|
38
38
|
spec.add_runtime_dependency 'json-jwt', '~> 1.8'
|
39
39
|
|
40
40
|
spec.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roo_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.pre.
|
4
|
+
version: 2.0.0.pre.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Letessier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv-rails
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.3'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sprockets
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: platform-api
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,16 +146,16 @@ dependencies:
|
|
132
146
|
name: sidekiq
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
|
-
- - "
|
149
|
+
- - "<"
|
136
150
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
151
|
+
version: 6.0.0
|
138
152
|
type: :runtime
|
139
153
|
prerelease: false
|
140
154
|
version_requirements: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
|
-
- - "
|
156
|
+
- - "<"
|
143
157
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
158
|
+
version: 6.0.0
|
145
159
|
- !ruby/object:Gem::Dependency
|
146
160
|
name: dogstatsd-ruby
|
147
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,20 +212,6 @@ dependencies:
|
|
198
212
|
- - ">="
|
199
213
|
- !ruby/object:Gem::Version
|
200
214
|
version: '0'
|
201
|
-
- !ruby/object:Gem::Dependency
|
202
|
-
name: routemaster-client
|
203
|
-
requirement: !ruby/object:Gem::Requirement
|
204
|
-
requirements:
|
205
|
-
- - ">="
|
206
|
-
- !ruby/object:Gem::Version
|
207
|
-
version: '0'
|
208
|
-
type: :runtime
|
209
|
-
prerelease: false
|
210
|
-
version_requirements: !ruby/object:Gem::Requirement
|
211
|
-
requirements:
|
212
|
-
- - ">="
|
213
|
-
- !ruby/object:Gem::Version
|
214
|
-
version: '0'
|
215
215
|
- !ruby/object:Gem::Dependency
|
216
216
|
name: json-jwt
|
217
217
|
requirement: !ruby/object:Gem::Requirement
|
@@ -390,7 +390,6 @@ files:
|
|
390
390
|
- LICENSE.txt
|
391
391
|
- README.google_oauth2.md
|
392
392
|
- README.md
|
393
|
-
- README.routemaster_client.md
|
394
393
|
- Rakefile
|
395
394
|
- appraise
|
396
395
|
- bin/console
|
@@ -447,12 +446,7 @@ files:
|
|
447
446
|
- lib/roo_on_rails/railties/logging.rb
|
448
447
|
- lib/roo_on_rails/railties/rake_tasks.rb
|
449
448
|
- lib/roo_on_rails/railties/roo_identity.rb
|
450
|
-
- lib/roo_on_rails/railties/routemaster.rb
|
451
449
|
- lib/roo_on_rails/railties/sidekiq_integration.rb
|
452
|
-
- lib/roo_on_rails/routemaster/lifecycle_events.rb
|
453
|
-
- lib/roo_on_rails/routemaster/publish_lifecycle_events.rb
|
454
|
-
- lib/roo_on_rails/routemaster/publisher.rb
|
455
|
-
- lib/roo_on_rails/routemaster/publishers.rb
|
456
450
|
- lib/roo_on_rails/shell.rb
|
457
451
|
- lib/roo_on_rails/sidekiq/loader.rb
|
458
452
|
- lib/roo_on_rails/sidekiq/metrics_worker.rb
|
@@ -484,7 +478,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
484
478
|
version: 1.3.1
|
485
479
|
requirements: []
|
486
480
|
rubyforge_project:
|
487
|
-
rubygems_version: 2.
|
481
|
+
rubygems_version: 2.6.11
|
488
482
|
signing_key:
|
489
483
|
specification_version: 4
|
490
484
|
summary: Scaffolding for building services
|
@@ -1,103 +0,0 @@
|
|
1
|
-
## Using the Routemaster Client feature
|
2
|
-
|
3
|
-
[`routemaster-client`](https://github.com/deliveroo/routemaster-client) comes as a dependency of `roo_on_rails` with a basic implementation of lifecycle event publishers.
|
4
|
-
|
5
|
-
This code example assumes that you are using the latest version of the [`roo_on_rails`](https://github.com/deliveroo/roo_on_rails) gem and that you have set the correct environment variables for Routemaster Client to work on your app, as explained in the main [`README.md`](https://github.com/deliveroo/roo_on_rails#routemaster-client) file.
|
6
|
-
|
7
|
-
It also assumes that your app has an API for the resources you want to publish lifecycle events for, with matching routes and an `API_HOST` environment variable set.
|
8
|
-
|
9
|
-
### Setup lifecycle events for your models
|
10
|
-
|
11
|
-
You can use publish events on create, update, and destroy by including the `PublishLifecycleEvents` module:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
# app/models/order.rb
|
15
|
-
require 'roo_on_rails/routemaster/publish_lifecycle_events'
|
16
|
-
|
17
|
-
class Order < ApplicationRecord
|
18
|
-
include RooOnRails::Routemaster::PublishLifecycleEvents
|
19
|
-
|
20
|
-
# ...
|
21
|
-
end
|
22
|
-
```
|
23
|
-
|
24
|
-
If you need more control over which events are published you can use the base module `LifecycleEvents` and specify them explicitly:
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
# app/models/rider.rb
|
28
|
-
require 'roo_on_rails/routemaster/lifecycle_events'
|
29
|
-
|
30
|
-
class Rider < ApplicationRecord
|
31
|
-
include RooOnRails::Routemaster::LifecycleEvents
|
32
|
-
|
33
|
-
publish_lifecycle_events :create, :destroy
|
34
|
-
|
35
|
-
# ...
|
36
|
-
end
|
37
|
-
```
|
38
|
-
|
39
|
-
### Create publishers for lifecycle events
|
40
|
-
|
41
|
-
We have now configured our models to publish lifecycle events to Routemaster, but it won't send anything until you have enabled publishing and created matching publishers. Let's start with creating an `ApplicationPublisher` that we can use as our default.
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
# app/publishers/application_publisher.rb
|
45
|
-
require 'roo_on_rails/routemaster/publisher'
|
46
|
-
|
47
|
-
class ApplicationPublisher < RooOnRails::Routemaster::Publisher
|
48
|
-
include Rails.application.routes.url_helpers
|
49
|
-
|
50
|
-
def url
|
51
|
-
url_helper = :"api_#{model.class.name.underscore}_url"
|
52
|
-
public_send(url_helper, model.id, host: ENV.fetch('API_HOST'), protocol: 'https')
|
53
|
-
end
|
54
|
-
|
55
|
-
# Add your method overrides here if needed
|
56
|
-
end
|
57
|
-
```
|
58
|
-
|
59
|
-
If different behaviour is needed for specific models then you can override the defaults in their publishers:
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
# app/publishers/order_publisher.rb
|
63
|
-
class OrderPublisher < ApplicationPublisher
|
64
|
-
def async?
|
65
|
-
true
|
66
|
-
end
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
|
-
and
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
# app/publishers/rider_publisher.rb
|
74
|
-
class RiderPublisher < ApplicationPublisher
|
75
|
-
def topic
|
76
|
-
'a_different_rider_topic'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
```
|
80
|
-
|
81
|
-
`#publish?`, `#topics`, `#async?`, `#data` and `#timestamp` can be overriden; see [the `Publisher` class](lib/roo_on_rails/routemaster/publisher.rb) for the default implementations.
|
82
|
-
|
83
|
-
### Register the publishers with Routemaster
|
84
|
-
|
85
|
-
The final step is to tell Routemaster that these publishers exist, so that it can listen to their events. We're going to do this in an initialiser:
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
# config/initilizers/routemaster.rb
|
89
|
-
require 'roo_on_rails/routemaster/publishers'
|
90
|
-
|
91
|
-
PUBLISHERS = [
|
92
|
-
OrderPublisher,
|
93
|
-
RiderPublisher
|
94
|
-
].freeze
|
95
|
-
|
96
|
-
RooOnRails::Routemaster::Publishers.register_default(ApplicationPublisher)
|
97
|
-
PUBLISHERS.each do |publisher|
|
98
|
-
model_class = publisher.to_s.gsub("Publisher", "").constantize
|
99
|
-
RooOnRails::Routemaster::Publishers.register(publisher, model_class: model_class)
|
100
|
-
end
|
101
|
-
```
|
102
|
-
|
103
|
-
We should now be all set for our app to publish lifecycle events for all our models onto the event bus, with special behaviour for `orders` and `riders`, so that other apps can listen to them.
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'roo_on_rails/config'
|
2
|
-
|
3
|
-
module RooOnRails
|
4
|
-
module Railties
|
5
|
-
class Routemaster < Rails::Railtie
|
6
|
-
initializer 'roo_on_rails.routemaster' do
|
7
|
-
Rails.logger.with initializer: 'roo_on_rails.routemaster' do |log|
|
8
|
-
next unless Config.routemaster_enabled?
|
9
|
-
log.debug 'loading'
|
10
|
-
|
11
|
-
abort 'Aborting: ROUTEMASTER_URL and ROUTEMASTER_UUID are required' if bus_details_missing?
|
12
|
-
|
13
|
-
require 'routemaster/client'
|
14
|
-
|
15
|
-
::Routemaster::Client.configure do |config|
|
16
|
-
config.url = routemaster_url
|
17
|
-
config.uuid = routemaster_uuid
|
18
|
-
config.verify_ssl = routemaster_verify_ssl
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def bus_details_missing?
|
26
|
-
routemaster_url.blank? || routemaster_uuid.blank?
|
27
|
-
end
|
28
|
-
|
29
|
-
def routemaster_url
|
30
|
-
ENV.fetch('ROUTEMASTER_URL')
|
31
|
-
end
|
32
|
-
|
33
|
-
def routemaster_uuid
|
34
|
-
ENV.fetch('ROUTEMASTER_UUID')
|
35
|
-
end
|
36
|
-
|
37
|
-
def routemaster_verify_ssl
|
38
|
-
ENV.fetch('ROUTEMASTER_VERIFY_SSL', 'true') != 'false'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'roo_on_rails/routemaster/publishers'
|
3
|
-
|
4
|
-
module RooOnRails
|
5
|
-
module Routemaster
|
6
|
-
module LifecycleEvents
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
ACTIVE_RECORD_TO_ROUTEMASTER_EVENT_MAP = {
|
10
|
-
create: :created,
|
11
|
-
update: :updated,
|
12
|
-
destroy: :deleted,
|
13
|
-
noop: :noop
|
14
|
-
}.freeze
|
15
|
-
private_constant :ACTIVE_RECORD_TO_ROUTEMASTER_EVENT_MAP
|
16
|
-
|
17
|
-
def publish_lifecycle_event(event)
|
18
|
-
publish_event(event, force_publish: false)
|
19
|
-
end
|
20
|
-
|
21
|
-
def publish_lifecycle_event!(event)
|
22
|
-
publish_event(event, force_publish: true)
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def publish_event(event, force_publish:)
|
28
|
-
publishers = Routemaster::Publishers.for(self, routemaster_event_type(event))
|
29
|
-
publishers.each do |publisher|
|
30
|
-
begin
|
31
|
-
publisher.publish!(force_publish: force_publish)
|
32
|
-
rescue => e
|
33
|
-
Raven.report_exception(e) if defined?(Raven)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def routemaster_event_type(event)
|
39
|
-
ACTIVE_RECORD_TO_ROUTEMASTER_EVENT_MAP[event].tap do |type|
|
40
|
-
raise "invalid lifecycle event '#{event}'" unless type
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
%i(create update destroy noop).each do |event|
|
45
|
-
define_method("publish_lifecycle_event_on_#{event}") do
|
46
|
-
publish_lifecycle_event(event)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
module ClassMethods
|
51
|
-
def publish_lifecycle_events(*events)
|
52
|
-
events = events.any? ? events : %i(create update destroy)
|
53
|
-
events.each do |event|
|
54
|
-
after_commit(
|
55
|
-
:"publish_lifecycle_event_on_#{event}",
|
56
|
-
on: event
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'roo_on_rails/routemaster/lifecycle_events'
|
3
|
-
|
4
|
-
module RooOnRails
|
5
|
-
module Routemaster
|
6
|
-
module PublishLifecycleEvents
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
include LifecycleEvents
|
9
|
-
|
10
|
-
included(&:publish_lifecycle_events)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'roo_on_rails/config'
|
2
|
-
require 'routemaster/client'
|
3
|
-
|
4
|
-
module RooOnRails
|
5
|
-
module Routemaster
|
6
|
-
class Publisher
|
7
|
-
attr_reader :model, :event
|
8
|
-
|
9
|
-
def initialize(model, event, client: ::Routemaster::Client)
|
10
|
-
@model = model
|
11
|
-
@event = event
|
12
|
-
@client = client
|
13
|
-
end
|
14
|
-
|
15
|
-
def publish?
|
16
|
-
noop? || @model.new_record? || @model.previous_changes.any?
|
17
|
-
end
|
18
|
-
|
19
|
-
def will_publish?(force_publish: false)
|
20
|
-
Config.routemaster_publishing_enabled? && (force_publish || publish?)
|
21
|
-
end
|
22
|
-
|
23
|
-
def publish!(force_publish: false)
|
24
|
-
return unless will_publish?(force_publish: force_publish)
|
25
|
-
@client.send(
|
26
|
-
@event,
|
27
|
-
topic,
|
28
|
-
url,
|
29
|
-
async: async?,
|
30
|
-
data: stringify_keys(data),
|
31
|
-
t: timestamp && (timestamp.to_f * 1000).to_i
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
def topic
|
36
|
-
@model.class.name.tableize
|
37
|
-
end
|
38
|
-
|
39
|
-
def url
|
40
|
-
raise NotImplementedError
|
41
|
-
end
|
42
|
-
|
43
|
-
def async?
|
44
|
-
false
|
45
|
-
end
|
46
|
-
|
47
|
-
def data
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
|
51
|
-
def timestamp
|
52
|
-
return @model.created_at if created? && @model.respond_to?(:created_at)
|
53
|
-
return @model.updated_at if (updated? || created?) && @model.respond_to?(:updated_at)
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
|
57
|
-
%i(created updated deleted noop).each do |event_type|
|
58
|
-
define_method :"#{event_type}?" do
|
59
|
-
@event.to_sym == event_type
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def stringify_keys(hash)
|
66
|
-
return hash if hash.nil? || hash.empty?
|
67
|
-
|
68
|
-
hash.each_with_object({}) do |(k, v), h|
|
69
|
-
h[k.to_s] = v.is_a?(Hash) ? stringify_keys(v) : v
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module RooOnRails
|
2
|
-
module Routemaster
|
3
|
-
module Publishers
|
4
|
-
@default_publishers = []
|
5
|
-
@publishers = {}
|
6
|
-
|
7
|
-
def self.register_default(publisher_class)
|
8
|
-
@default_publishers << publisher_class
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.register(publisher_class, model_class:)
|
12
|
-
@publishers[model_class.name] ||= Set.new
|
13
|
-
@publishers[model_class.name] << publisher_class
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.for(model, event)
|
17
|
-
publisher_classes = @publishers[model.class.name] || @default_publishers
|
18
|
-
publisher_classes.map { |c| c.new(model, event) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.clear
|
22
|
-
@default_publishers = []
|
23
|
-
@publishers = {}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|