roo_on_rails 1.9.0 → 1.10.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
  SHA1:
3
- metadata.gz: 82ad20e84b42ea5464aa1d089f6e54c1476f38bf
4
- data.tar.gz: b707a2fc6d70a093fc7b75c9ab44f61d1678bdd7
3
+ metadata.gz: a75dec85ceb80185f16de9a7750600c6a6284f20
4
+ data.tar.gz: b0c3482407ff65e0cf7a69e9935a4b1b67a54893
5
5
  SHA512:
6
- metadata.gz: d94ba024d087ea2d51405d81bc9b690c072492551384d409bc0d8b34d6b24a11dd46db96e8ef5093ef6e04db731d149af91377470d0da6fc7fc328e81ec09682
7
- data.tar.gz: 0a7839fda65b584af46860dd660a303889cb9a159502053a02ec7875e70fe1ea20c7240f12b9f0ccb2696134fe19b72d8c3b5a2b19a77d95467992feb84cab79
6
+ metadata.gz: 2a0e90668340f68bec18a4fcf1b7aaaf0fe05a1a89649a0fe0383bcbc19bb9aeb1070201d5cadc3b0f8dd3f5c43ae3b036b001c562aac20479a7c042ac4c6492
7
+ data.tar.gz: 3c90104b1133595ddd86729440776ac6a0c08f03aa71f87584afee49353545f4fd7cef91ecedd0d1a2dade237453d2960c43be7110414e29d69c5b47cfc48be4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v1.10.0 (2017-08-11)
2
+
3
+ Features:
4
+
5
+ - Asynchronous publishing of events to Routemaster (#56)
6
+
1
7
  # v1.9.0 (2017-08-08)
2
8
 
3
9
  Features:
@@ -8,39 +8,29 @@ It also assumes that your app has an API for the resources you want to publish l
8
8
 
9
9
  ### Setup lifecycle events for your models
10
10
 
11
- We will most likely want to publish lifecycle events for several models, so to write slightly less code let's create a model concern first:
12
-
13
- ```ruby
14
- # app/models/concerns/routemaster_lifecycle_events.rb
15
- require 'roo_on_rails/routemaster/lifecycle_events'
16
-
17
- module RoutemasterLifecycleEvents
18
- extend ActiveSupport::Concern
19
- include RooOnRails::Routemaster::LifecycleEvents
20
-
21
- included do
22
- publish_lifecycle_events
23
- end
24
- end
25
- ```
26
-
27
- Then let's include this concern to the relevant model(s):
11
+ You can use publish events on create, update, and destroy by including the `PublishLifecycleEvents` module:
28
12
 
29
13
  ```ruby
30
14
  # app/models/order.rb
15
+ require 'roo_on_rails/routemaster/publish_lifecycle_events'
16
+
31
17
  class Order < ApplicationRecord
32
- include RoutemasterLifecycleEvents
18
+ include RooOnRails::Routemaster::PublishLifecycleEvents
33
19
 
34
20
  # ...
35
21
  end
36
22
  ```
37
23
 
38
- And another one for the example:
24
+ If you need more control over which events are published you can use the base module `LifecycleEvents` and specify them explicitly:
39
25
 
40
26
  ```ruby
41
27
  # app/models/rider.rb
28
+ require 'roo_on_rails/routemaster/lifecycle_events'
29
+
42
30
  class Rider < ApplicationRecord
43
- include RoutemasterLifecycleEvents
31
+ include RooOnRails::Routemaster::LifecycleEvents
32
+
33
+ publish_lifecycle_events :create, :destroy
44
34
 
45
35
  # ...
46
36
  end
@@ -48,26 +38,31 @@ end
48
38
 
49
39
  ### Create publishers for lifecycle events
50
40
 
51
- 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 a `BasePublisher` that we can then inherit from:
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.
52
42
 
53
43
  ```ruby
54
- # app/publishers/base_publisher.rb
44
+ # app/publishers/application_publisher.rb
55
45
  require 'roo_on_rails/routemaster/publisher'
56
46
 
57
- class BasePublisher < RooOnRails::Routemaster::Publisher
47
+ class ApplicationPublisher < RooOnRails::Routemaster::Publisher
58
48
  include Rails.application.routes.url_helpers
59
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
+
60
55
  # Add your method overrides here if needed
61
56
  end
62
57
  ```
63
58
 
64
- Then create a publisher for each model with lifecycle events enabled:
59
+ If different behaviour is needed for specific models then you can override the defaults in their publishers:
65
60
 
66
61
  ```ruby
67
62
  # app/publishers/order_publisher.rb
68
- class OrderPublisher < BasePublisher
69
- def url
70
- api_order_url(model, host: ENV.fetch('API_HOST'), protocol: 'https')
63
+ class OrderPublisher < ApplicationPublisher
64
+ def async?
65
+ true
71
66
  end
72
67
  end
73
68
  ```
@@ -76,9 +71,9 @@ and
76
71
 
77
72
  ```ruby
78
73
  # app/publishers/rider_publisher.rb
79
- class RiderPublisher < BasePublisher
80
- def url
81
- api_rider_url(model, host: ENV.fetch('API_HOST'), protocol: 'https')
74
+ class RiderPublisher < ApplicationPublisher
75
+ def topic
76
+ 'a_different_rider_topic'
82
77
  end
83
78
  end
84
79
  ```
@@ -96,10 +91,11 @@ PUBLISHERS = [
96
91
  RiderPublisher
97
92
  ].freeze
98
93
 
94
+ RooOnRails::Routemaster::Publishers.register_default(ApplicationPublisher)
99
95
  PUBLISHERS.each do |publisher|
100
96
  model_class = publisher.to_s.gsub("Publisher", "").constantize
101
97
  RooOnRails::Routemaster::Publishers.register(publisher, model_class: model_class)
102
98
  end
103
99
  ```
104
100
 
105
- We should now be all set for our app to publish lifecycle events for `orders` and `riders` onto the event bus, so that other apps can listen to them.
101
+ 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,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- roo_on_rails (1.9.0)
4
+ roo_on_rails (1.10.0)
5
5
  dogstatsd-ruby
6
6
  dotenv-rails (~> 2.1)
7
7
  faraday
@@ -76,7 +76,7 @@ GEM
76
76
  erubis (2.7.0)
77
77
  ethon (0.10.1)
78
78
  ffi (>= 1.3.0)
79
- excon (0.58.0)
79
+ excon (0.57.1)
80
80
  faraday (0.12.2)
81
81
  multipart-post (>= 1.2, < 3)
82
82
  faraday_middleware (0.12.2)
@@ -141,7 +141,7 @@ GEM
141
141
  omniauth (1.4.2)
142
142
  hashie (>= 1.2, < 4)
143
143
  rack (>= 1.0, < 3)
144
- omniauth-google-oauth2 (0.5.2)
144
+ omniauth-google-oauth2 (0.5.1)
145
145
  jwt (~> 1.5)
146
146
  multi_json (~> 1.3)
147
147
  omniauth (>= 1.1.1)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- roo_on_rails (1.9.0)
4
+ roo_on_rails (1.10.0)
5
5
  dogstatsd-ruby
6
6
  dotenv-rails (~> 2.1)
7
7
  faraday
@@ -83,7 +83,7 @@ GEM
83
83
  erubis (2.7.0)
84
84
  ethon (0.10.1)
85
85
  ffi (>= 1.3.0)
86
- excon (0.58.0)
86
+ excon (0.57.1)
87
87
  faraday (0.12.2)
88
88
  multipart-post (>= 1.2, < 3)
89
89
  faraday_middleware (0.12.2)
@@ -155,7 +155,7 @@ GEM
155
155
  omniauth (1.6.1)
156
156
  hashie (>= 3.4.6, < 3.6.0)
157
157
  rack (>= 1.6.2, < 3)
158
- omniauth-google-oauth2 (0.5.2)
158
+ omniauth-google-oauth2 (0.5.1)
159
159
  jwt (~> 1.5)
160
160
  multi_json (~> 1.3)
161
161
  omniauth (>= 1.1.1)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- roo_on_rails (1.9.0)
4
+ roo_on_rails (1.10.0)
5
5
  dogstatsd-ruby
6
6
  dotenv-rails (~> 2.1)
7
7
  faraday
@@ -86,7 +86,7 @@ GEM
86
86
  erubis (2.7.0)
87
87
  ethon (0.10.1)
88
88
  ffi (>= 1.3.0)
89
- excon (0.58.0)
89
+ excon (0.57.1)
90
90
  faraday (0.12.2)
91
91
  multipart-post (>= 1.2, < 3)
92
92
  faraday_middleware (0.12.2)
@@ -159,7 +159,7 @@ GEM
159
159
  omniauth (1.6.1)
160
160
  hashie (>= 3.4.6, < 3.6.0)
161
161
  rack (>= 1.6.2, < 3)
162
- omniauth-google-oauth2 (0.5.2)
162
+ omniauth-google-oauth2 (0.5.1)
163
163
  jwt (~> 1.5)
164
164
  multi_json (~> 1.3)
165
165
  omniauth (>= 1.1.1)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- roo_on_rails (1.9.0)
4
+ roo_on_rails (1.10.0)
5
5
  dogstatsd-ruby
6
6
  dotenv-rails (~> 2.1)
7
7
  faraday
@@ -87,7 +87,7 @@ GEM
87
87
  erubis (2.7.0)
88
88
  ethon (0.10.1)
89
89
  ffi (>= 1.3.0)
90
- excon (0.58.0)
90
+ excon (0.57.1)
91
91
  faraday (0.12.2)
92
92
  multipart-post (>= 1.2, < 3)
93
93
  faraday_middleware (0.12.2)
@@ -160,7 +160,7 @@ GEM
160
160
  omniauth (1.6.1)
161
161
  hashie (>= 3.4.6, < 3.6.0)
162
162
  rack (>= 1.6.2, < 3)
163
- omniauth-google-oauth2 (0.5.2)
163
+ omniauth-google-oauth2 (0.5.1)
164
164
  jwt (~> 1.5)
165
165
  multi_json (~> 1.3)
166
166
  omniauth (>= 1.1.1)
@@ -0,0 +1,13 @@
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
@@ -22,7 +22,7 @@ module RooOnRails
22
22
 
23
23
  def publish!
24
24
  return unless will_publish?
25
- @client.send(@event, topic, url, data: stringify_keys(data))
25
+ @client.send(@event, topic, url, async: async?, data: stringify_keys(data))
26
26
  end
27
27
 
28
28
  def topic
@@ -33,6 +33,10 @@ module RooOnRails
33
33
  raise NotImplementedError
34
34
  end
35
35
 
36
+ def async?
37
+ false
38
+ end
39
+
36
40
  def data
37
41
  nil
38
42
  end
@@ -1,17 +1,27 @@
1
1
  module RooOnRails
2
2
  module Routemaster
3
3
  module Publishers
4
+ @default_publishers = []
4
5
  @publishers = {}
5
6
 
7
+ def self.register_default(publisher_class)
8
+ @default_publishers << publisher_class
9
+ end
10
+
6
11
  def self.register(publisher_class, model_class:)
7
12
  @publishers[model_class] ||= Set.new
8
13
  @publishers[model_class] << publisher_class
9
14
  end
10
15
 
11
16
  def self.for(model, event)
12
- publisher_classes = @publishers[model.class]
17
+ publisher_classes = @publishers[model.class] || @default_publishers
13
18
  publisher_classes.map { |c| c.new(model, event) }
14
19
  end
20
+
21
+ def self.clear
22
+ @default_publishers = []
23
+ @publishers = {}
24
+ end
15
25
  end
16
26
  end
17
27
  end
@@ -1,3 +1,3 @@
1
1
  module RooOnRails
2
- VERSION = '1.9.0'.freeze
2
+ VERSION = '1.10.0'.freeze
3
3
  end
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: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv-rails
@@ -433,6 +433,7 @@ files:
433
433
  - lib/roo_on_rails/railties/routemaster.rb
434
434
  - lib/roo_on_rails/railties/sidekiq.rb
435
435
  - lib/roo_on_rails/routemaster/lifecycle_events.rb
436
+ - lib/roo_on_rails/routemaster/publish_lifecycle_events.rb
436
437
  - lib/roo_on_rails/routemaster/publisher.rb
437
438
  - lib/roo_on_rails/routemaster/publishers.rb
438
439
  - lib/roo_on_rails/shell.rb