cloudenvoy 0.3.1 → 0.5.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint_rubocop.yml +20 -0
  3. data/.github/workflows/{test.yml → test_ruby_2.5_2.6.yml} +8 -13
  4. data/.github/workflows/test_ruby_2.7.yml +36 -0
  5. data/.github/workflows/test_ruby_3.x.yml +35 -0
  6. data/.gitignore +3 -0
  7. data/.rubocop.yml +5 -0
  8. data/Appraisals +24 -4
  9. data/CHANGELOG.md +33 -2
  10. data/README.md +4 -4
  11. data/app/controllers/cloudenvoy/subscriber_controller.rb +6 -5
  12. data/cloudenvoy.gemspec +0 -4
  13. data/examples/rails/.ruby-version +1 -1
  14. data/examples/rails/Gemfile +4 -1
  15. data/examples/rails/Gemfile.lock +132 -110
  16. data/examples/rails/README.md +1 -1
  17. data/examples/sinatra/Gemfile +18 -0
  18. data/examples/sinatra/Gemfile.lock +131 -0
  19. data/examples/sinatra/Procfile +1 -0
  20. data/examples/sinatra/README.md +41 -0
  21. data/examples/sinatra/app/publishers/hello_publisher.rb +34 -0
  22. data/examples/sinatra/app/subscribers/hello_subscriber.rb +16 -0
  23. data/examples/sinatra/app.rb +40 -0
  24. data/examples/sinatra/bin/console +8 -0
  25. data/examples/sinatra/config/initializers/cloudenvoy.rb +30 -0
  26. data/gemfiles/.bundle/config +2 -0
  27. data/gemfiles/rails_5.2.gemfile +1 -0
  28. data/gemfiles/rails_5.2.gemfile.lock +111 -88
  29. data/gemfiles/rails_6.0.gemfile +1 -0
  30. data/gemfiles/rails_6.0.gemfile.lock +112 -89
  31. data/gemfiles/rails_6.1.gemfile +8 -0
  32. data/gemfiles/rails_7.0.gemfile +8 -0
  33. data/gemfiles/semantic_logger_3.4.gemfile +1 -0
  34. data/gemfiles/semantic_logger_3.4.gemfile.lock +89 -187
  35. data/gemfiles/semantic_logger_4.6.gemfile +1 -0
  36. data/gemfiles/semantic_logger_4.6.gemfile.lock +89 -187
  37. data/gemfiles/semantic_logger_4.7.0.gemfile +1 -0
  38. data/gemfiles/semantic_logger_4.7.0.gemfile.lock +89 -187
  39. data/gemfiles/semantic_logger_4.7.2.gemfile +1 -0
  40. data/gemfiles/semantic_logger_4.7.2.gemfile.lock +89 -187
  41. data/lib/cloudenvoy/backend/google_pub_sub.rb +18 -3
  42. data/lib/cloudenvoy/message.rb +2 -2
  43. data/lib/cloudenvoy/publisher.rb +1 -0
  44. data/lib/cloudenvoy/subscriber.rb +3 -2
  45. data/lib/cloudenvoy/version.rb +1 -1
  46. data/lib/cloudenvoy.rb +1 -0
  47. data/lib/generators/cloudenvoy/publisher_generator.rb +46 -0
  48. data/lib/generators/cloudenvoy/subscriber_generator.rb +46 -0
  49. data/lib/generators/cloudenvoy/templates/publisher.rb.erb +11 -0
  50. data/lib/generators/cloudenvoy/templates/publisher_spec.rb.erb +6 -0
  51. data/lib/generators/cloudenvoy/templates/subscriber.rb.erb +11 -0
  52. data/lib/generators/cloudenvoy/templates/subscriber_spec.rb.erb +6 -0
  53. data/lib/tasks/cloudenvoy.rake +4 -4
  54. metadata +30 -53
  55. data/Gemfile.lock +0 -267
  56. data/app/controllers/cloudenvoy/application_controller.rb +0 -8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cloudenvoy (0.3.1)
4
+ cloudenvoy (0.4.2)
5
5
  activesupport
6
6
  google-cloud-pubsub (~> 2.0)
7
7
  jwt
@@ -10,200 +10,115 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (6.0.3.3)
14
- actionpack (= 6.0.3.3)
15
- nio4r (~> 2.0)
16
- websocket-driver (>= 0.6.1)
17
- actionmailbox (6.0.3.3)
18
- actionpack (= 6.0.3.3)
19
- activejob (= 6.0.3.3)
20
- activerecord (= 6.0.3.3)
21
- activestorage (= 6.0.3.3)
22
- activesupport (= 6.0.3.3)
23
- mail (>= 2.7.1)
24
- actionmailer (6.0.3.3)
25
- actionpack (= 6.0.3.3)
26
- actionview (= 6.0.3.3)
27
- activejob (= 6.0.3.3)
28
- mail (~> 2.5, >= 2.5.4)
29
- rails-dom-testing (~> 2.0)
30
- actionpack (6.0.3.3)
31
- actionview (= 6.0.3.3)
32
- activesupport (= 6.0.3.3)
33
- rack (~> 2.0, >= 2.0.8)
34
- rack-test (>= 0.6.3)
35
- rails-dom-testing (~> 2.0)
36
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
- actiontext (6.0.3.3)
38
- actionpack (= 6.0.3.3)
39
- activerecord (= 6.0.3.3)
40
- activestorage (= 6.0.3.3)
41
- activesupport (= 6.0.3.3)
42
- nokogiri (>= 1.8.5)
43
- actionview (6.0.3.3)
44
- activesupport (= 6.0.3.3)
45
- builder (~> 3.1)
46
- erubi (~> 1.4)
47
- rails-dom-testing (~> 2.0)
48
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
- activejob (6.0.3.3)
50
- activesupport (= 6.0.3.3)
51
- globalid (>= 0.3.6)
52
- activemodel (6.0.3.3)
53
- activesupport (= 6.0.3.3)
54
- activerecord (6.0.3.3)
55
- activemodel (= 6.0.3.3)
56
- activesupport (= 6.0.3.3)
57
- activestorage (6.0.3.3)
58
- actionpack (= 6.0.3.3)
59
- activejob (= 6.0.3.3)
60
- activerecord (= 6.0.3.3)
61
- marcel (~> 0.3.1)
62
- activesupport (6.0.3.3)
13
+ activesupport (6.1.0)
63
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
64
- i18n (>= 0.7, < 2)
65
- minitest (~> 5.1)
66
- tzinfo (~> 1.1)
67
- zeitwerk (~> 2.2, >= 2.2.2)
68
- addressable (2.7.0)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
+ addressable (2.8.0)
69
20
  public_suffix (>= 2.0.2, < 5.0)
70
- appraisal (2.3.0)
21
+ appraisal (2.4.1)
71
22
  bundler
72
23
  rake
73
24
  thor (>= 0.14.0)
74
- ast (2.4.1)
75
- builder (3.2.4)
76
- concurrent-ruby (1.1.7)
77
- crack (0.4.4)
78
- crass (1.0.6)
79
- diff-lcs (1.4.4)
80
- erubi (1.9.0)
81
- faraday (1.0.1)
25
+ ast (2.4.2)
26
+ concurrent-ruby (1.1.9)
27
+ crack (0.4.5)
28
+ rexml
29
+ diff-lcs (1.5.0)
30
+ faraday (1.8.0)
31
+ faraday-em_http (~> 1.0)
32
+ faraday-em_synchrony (~> 1.0)
33
+ faraday-excon (~> 1.1)
34
+ faraday-httpclient (~> 1.0.1)
35
+ faraday-net_http (~> 1.0)
36
+ faraday-net_http_persistent (~> 1.1)
37
+ faraday-patron (~> 1.0)
38
+ faraday-rack (~> 1.0)
82
39
  multipart-post (>= 1.2, < 3)
83
- gapic-common (0.3.4)
84
- google-protobuf (~> 3.12, >= 3.12.2)
85
- googleapis-common-protos (>= 1.3.9, < 2.0)
86
- googleapis-common-protos-types (>= 1.0.4, < 2.0)
87
- googleauth (~> 0.9)
88
- grpc (~> 1.25)
89
- globalid (0.4.2)
90
- activesupport (>= 4.2.0)
91
- google-cloud-core (1.5.0)
40
+ ruby2_keywords (>= 0.0.4)
41
+ faraday-em_http (1.0.0)
42
+ faraday-em_synchrony (1.0.0)
43
+ faraday-excon (1.1.0)
44
+ faraday-httpclient (1.0.1)
45
+ faraday-net_http (1.0.1)
46
+ faraday-net_http_persistent (1.2.0)
47
+ faraday-patron (1.0.0)
48
+ faraday-rack (1.0.0)
49
+ gapic-common (0.7.0)
50
+ faraday (~> 1.3)
51
+ google-protobuf (~> 3.14)
52
+ googleapis-common-protos (>= 1.3.11, < 2.a)
53
+ googleapis-common-protos-types (>= 1.0.6, < 2.a)
54
+ googleauth (>= 0.17.0, < 2.a)
55
+ grpc (~> 1.36)
56
+ google-cloud-core (1.6.0)
92
57
  google-cloud-env (~> 1.0)
93
58
  google-cloud-errors (~> 1.0)
94
- google-cloud-env (1.3.3)
59
+ google-cloud-env (1.5.0)
95
60
  faraday (>= 0.17.3, < 2.0)
96
- google-cloud-errors (1.0.1)
97
- google-cloud-pubsub (2.0.0)
61
+ google-cloud-errors (1.2.0)
62
+ google-cloud-pubsub (2.9.0)
98
63
  concurrent-ruby (~> 1.1)
99
64
  google-cloud-core (~> 1.5)
100
65
  google-cloud-pubsub-v1 (~> 0.0)
101
- google-cloud-pubsub-v1 (0.1.2)
102
- gapic-common (~> 0.3)
66
+ google-cloud-pubsub-v1 (0.6.1)
67
+ gapic-common (>= 0.7, < 2.a)
103
68
  google-cloud-errors (~> 1.0)
104
- grpc-google-iam-v1 (>= 0.6.10, < 2.0)
105
- google-protobuf (3.13.0-universal-darwin)
106
- googleapis-common-protos (1.3.10)
107
- google-protobuf (~> 3.11)
108
- googleapis-common-protos-types (>= 1.0.5, < 2.0)
69
+ grpc-google-iam-v1 (>= 0.6.10, < 2.a)
70
+ google-protobuf (3.19.1)
71
+ googleapis-common-protos (1.3.12)
72
+ google-protobuf (~> 3.14)
73
+ googleapis-common-protos-types (~> 1.2)
109
74
  grpc (~> 1.27)
110
- googleapis-common-protos-types (1.0.5)
111
- google-protobuf (~> 3.11)
112
- googleauth (0.13.1)
75
+ googleapis-common-protos-types (1.3.0)
76
+ google-protobuf (~> 3.14)
77
+ googleauth (1.1.0)
113
78
  faraday (>= 0.17.3, < 2.0)
114
79
  jwt (>= 1.4, < 3.0)
115
80
  memoist (~> 0.16)
116
81
  multi_json (~> 1.11)
117
82
  os (>= 0.9, < 2.0)
118
- signet (~> 0.14)
119
- grpc (1.32.0-universal-darwin)
120
- google-protobuf (~> 3.13)
83
+ signet (>= 0.16, < 2.a)
84
+ grpc (1.42.0)
85
+ google-protobuf (~> 3.18)
121
86
  googleapis-common-protos-types (~> 1.0)
122
- grpc-google-iam-v1 (0.6.10)
123
- google-protobuf (~> 3.11)
124
- googleapis-common-protos (>= 1.3.10, < 2.0)
87
+ grpc-google-iam-v1 (1.0.0)
88
+ google-protobuf (~> 3.14)
89
+ googleapis-common-protos (>= 1.3.12, < 2.0)
125
90
  grpc (~> 1.27)
126
91
  hashdiff (1.0.1)
127
- i18n (1.8.5)
92
+ i18n (1.8.11)
128
93
  concurrent-ruby (~> 1.0)
129
94
  jaro_winkler (1.5.4)
130
- jwt (2.2.2)
131
- loofah (2.7.0)
132
- crass (~> 1.0.2)
133
- nokogiri (>= 1.5.9)
134
- mail (2.7.1)
135
- mini_mime (>= 0.1.1)
136
- marcel (0.3.3)
137
- mimemagic (~> 0.3.2)
95
+ jwt (2.3.0)
138
96
  memoist (0.16.2)
139
- method_source (1.0.0)
140
- mimemagic (0.3.5)
141
- mini_mime (1.0.2)
142
- mini_portile2 (2.4.0)
143
- minitest (5.14.2)
97
+ minitest (5.15.0)
144
98
  multi_json (1.15.0)
145
99
  multipart-post (2.1.1)
146
- nio4r (2.5.4)
147
- nokogiri (1.10.10)
148
- mini_portile2 (~> 2.4.0)
149
- os (1.1.1)
150
- parallel (1.19.2)
151
- parser (2.7.1.5)
100
+ os (1.1.4)
101
+ parallel (1.21.0)
102
+ parser (3.1.0.0)
152
103
  ast (~> 2.4.1)
153
104
  public_suffix (4.0.6)
154
- rack (2.2.3)
155
- rack-test (1.1.0)
156
- rack (>= 1.0, < 3)
157
- rails (6.0.3.3)
158
- actioncable (= 6.0.3.3)
159
- actionmailbox (= 6.0.3.3)
160
- actionmailer (= 6.0.3.3)
161
- actionpack (= 6.0.3.3)
162
- actiontext (= 6.0.3.3)
163
- actionview (= 6.0.3.3)
164
- activejob (= 6.0.3.3)
165
- activemodel (= 6.0.3.3)
166
- activerecord (= 6.0.3.3)
167
- activestorage (= 6.0.3.3)
168
- activesupport (= 6.0.3.3)
169
- bundler (>= 1.3.0)
170
- railties (= 6.0.3.3)
171
- sprockets-rails (>= 2.0.0)
172
- rails-dom-testing (2.0.3)
173
- activesupport (>= 4.2.0)
174
- nokogiri (>= 1.6)
175
- rails-html-sanitizer (1.3.0)
176
- loofah (~> 2.3)
177
- railties (6.0.3.3)
178
- actionpack (= 6.0.3.3)
179
- activesupport (= 6.0.3.3)
180
- method_source
181
- rake (>= 0.8.7)
182
- thor (>= 0.20.3, < 2.0)
183
105
  rainbow (3.0.0)
184
- rake (13.0.1)
106
+ rake (13.0.6)
185
107
  retriable (3.1.2)
186
- rspec (3.9.0)
187
- rspec-core (~> 3.9.0)
188
- rspec-expectations (~> 3.9.0)
189
- rspec-mocks (~> 3.9.0)
190
- rspec-core (3.9.3)
191
- rspec-support (~> 3.9.3)
192
- rspec-expectations (3.9.2)
108
+ rexml (3.2.5)
109
+ rspec (3.10.0)
110
+ rspec-core (~> 3.10.0)
111
+ rspec-expectations (~> 3.10.0)
112
+ rspec-mocks (~> 3.10.0)
113
+ rspec-core (3.10.1)
114
+ rspec-support (~> 3.10.0)
115
+ rspec-expectations (3.10.1)
193
116
  diff-lcs (>= 1.2.0, < 2.0)
194
- rspec-support (~> 3.9.0)
195
- rspec-mocks (3.9.1)
117
+ rspec-support (~> 3.10.0)
118
+ rspec-mocks (3.10.2)
196
119
  diff-lcs (>= 1.2.0, < 2.0)
197
- rspec-support (~> 3.9.0)
198
- rspec-rails (4.0.1)
199
- actionpack (>= 4.2)
200
- activesupport (>= 4.2)
201
- railties (>= 4.2)
202
- rspec-core (~> 3.9)
203
- rspec-expectations (~> 3.9)
204
- rspec-mocks (~> 3.9)
205
- rspec-support (~> 3.9)
206
- rspec-support (3.9.3)
120
+ rspec-support (~> 3.10.0)
121
+ rspec-support (3.10.3)
207
122
  rubocop (0.76.0)
208
123
  jaro_winkler (~> 1.5.1)
209
124
  parallel (~> 1.10)
@@ -213,53 +128,40 @@ GEM
213
128
  unicode-display_width (>= 1.4.0, < 1.7)
214
129
  rubocop-rspec (1.37.0)
215
130
  rubocop (>= 0.68.1)
216
- ruby-progressbar (1.10.1)
131
+ ruby-progressbar (1.11.0)
132
+ ruby2_keywords (0.0.5)
217
133
  semantic_logger (4.7.2)
218
134
  concurrent-ruby (~> 1.0)
219
- signet (0.14.0)
220
- addressable (~> 2.3)
135
+ signet (0.16.0)
136
+ addressable (~> 2.8)
221
137
  faraday (>= 0.17.3, < 2.0)
222
138
  jwt (>= 1.5, < 3.0)
223
139
  multi_json (~> 1.10)
224
- sprockets (4.0.2)
140
+ thor (1.1.0)
141
+ timecop (0.9.4)
142
+ tzinfo (2.0.4)
225
143
  concurrent-ruby (~> 1.0)
226
- rack (> 1, < 3)
227
- sprockets-rails (3.2.2)
228
- actionpack (>= 4.0)
229
- activesupport (>= 4.0)
230
- sprockets (>= 3.0.0)
231
- sqlite3 (1.4.2)
232
- thor (1.0.1)
233
- thread_safe (0.3.6)
234
- timecop (0.9.1)
235
- tzinfo (1.2.7)
236
- thread_safe (~> 0.1)
237
144
  unicode-display_width (1.6.1)
238
- webmock (3.9.1)
239
- addressable (>= 2.3.6)
145
+ webmock (3.14.0)
146
+ addressable (>= 2.8.0)
240
147
  crack (>= 0.3.2)
241
148
  hashdiff (>= 0.4.0, < 2.0.0)
242
- websocket-driver (0.7.3)
243
- websocket-extensions (>= 0.1.0)
244
- websocket-extensions (0.1.5)
245
- zeitwerk (2.4.0)
149
+ zeitwerk (2.5.3)
246
150
 
247
151
  PLATFORMS
248
152
  ruby
249
153
 
250
154
  DEPENDENCIES
155
+ activesupport (= 6.1)
251
156
  appraisal
252
157
  cloudenvoy!
253
- rails
254
158
  rake (>= 12.3.3)
255
159
  rspec (~> 3.0)
256
- rspec-rails
257
160
  rubocop (= 0.76.0)
258
161
  rubocop-rspec (= 1.37.0)
259
162
  semantic_logger (= 4.7.2)
260
- sqlite3
261
163
  timecop
262
164
  webmock
263
165
 
264
166
  BUNDLED WITH
265
- 2.1.4
167
+ 2.3.4
@@ -17,15 +17,24 @@ module Cloudenvoy
17
17
  Cloudenvoy.config
18
18
  end
19
19
 
20
+ #
21
+ # Return true if the current config mode is development.
22
+ #
23
+ # @return [Boolean] True if Cloudenvoy is run in development mode.
24
+ #
25
+ def development?
26
+ config.mode == :development
27
+ end
28
+
20
29
  #
21
30
  # Return the backend to use for sending messages.
22
31
  #
23
32
  # @return [Google::Cloud::Pub] The low level client instance.
24
33
  #
25
34
  def backend
26
- @backend ||= Google::Cloud::PubSub.new({
35
+ @backend ||= Google::Cloud::PubSub.new(**{
27
36
  project_id: config.gcp_project_id,
28
- emulator_host: config.mode == :development ? Cloudenvoy::Config::EMULATOR_HOST : nil
37
+ emulator_host: development? ? Cloudenvoy::Config::EMULATOR_HOST : nil
29
38
  }.compact)
30
39
  end
31
40
 
@@ -88,13 +97,19 @@ module Cloudenvoy
88
97
  def upsert_subscription(topic, name, opts = {})
89
98
  sub_config = opts.to_h.merge(endpoint: webhook_url)
90
99
 
100
+ # Auto-create topic in development. In non-development environments
101
+ # the create subscription action raises an error if the topic does
102
+ # not exist
103
+ upsert_topic(topic) if development?
104
+
105
+ # Create subscription
91
106
  ps_sub =
92
107
  begin
93
108
  # Retrieve the topic
94
109
  ps_topic = backend.topic(topic, skip_lookup: true)
95
110
 
96
111
  # Attempt to create the subscription
97
- ps_topic.subscribe(name, sub_config)
112
+ ps_topic.subscribe(name, **sub_config)
98
113
  rescue Google::Cloud::AlreadyExistsError
99
114
  # Update endpoint on subscription
100
115
  # Topic is not updated as it is name-dependent
@@ -75,8 +75,8 @@ module Cloudenvoy
75
75
  def to_h
76
76
  {
77
77
  id: id,
78
- payload: payload,
79
- metadata: metadata,
78
+ payload: payload&.dup,
79
+ metadata: metadata&.dup,
80
80
  topic: topic,
81
81
  sub_uri: sub_uri
82
82
  }.compact
@@ -200,6 +200,7 @@ module Cloudenvoy
200
200
  begin
201
201
  publish_message
202
202
  rescue StandardError => e
203
+ logger.error([e, e.backtrace.join("\n")].join("\n"))
203
204
  try(:on_error, e)
204
205
  return raise(e)
205
206
  end
@@ -53,7 +53,7 @@ module Cloudenvoy
53
53
  # @return [Array<String,String>] A tuple [subscriber_name, topic ]
54
54
  #
55
55
  def self.parse_sub_uri(sub_uri)
56
- sub_uri.split('/').last.split('.').last(2)
56
+ sub_uri.split('/').last.split('.', 2).last.split('.', 2)
57
57
  end
58
58
 
59
59
  #
@@ -211,8 +211,9 @@ module Cloudenvoy
211
211
  begin
212
212
  process(message)
213
213
  rescue StandardError => e
214
+ logger.error([e, e.backtrace.join("\n")].join("\n"))
214
215
  try(:on_error, e)
215
- return raise(e)
216
+ raise(e)
216
217
  end
217
218
  end
218
219
  ensure
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudenvoy
4
- VERSION = '0.3.1'
4
+ VERSION = '0.5.rc1'
5
5
  end
data/lib/cloudenvoy.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/core_ext/string/inflections'
4
+ require 'active_support/core_ext/object/try'
4
5
 
5
6
  require 'cloudenvoy/version'
6
7
  require 'cloudenvoy/config'
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/named_base'
4
+
5
+ module Cloudenvoy
6
+ module Generators # :nodoc:
7
+ class PublisherGenerator < ::Rails::Generators::NamedBase # :nodoc:
8
+ desc 'This generator creates a CloudEnvoy in app/publishers and a corresponding test'
9
+
10
+ check_class_collision suffix: 'Publisher'
11
+
12
+ def self.default_generator_root
13
+ File.dirname(__FILE__)
14
+ end
15
+
16
+ def create_publisher_file
17
+ template 'publisher.rb.erb', File.join('app/publishers', class_path, "#{file_name}_publisher.rb")
18
+ end
19
+
20
+ def create_test_file
21
+ return unless test_framework
22
+
23
+ create_publisher_spec if test_framework == :rspec
24
+ end
25
+
26
+ private
27
+
28
+ def create_publisher_spec
29
+ template_file = File.join(
30
+ 'spec/publishers',
31
+ class_path,
32
+ "#{file_name}_publisher_spec.rb"
33
+ )
34
+ template 'publisher_spec.rb.erb', template_file
35
+ end
36
+
37
+ def file_name
38
+ @file_name ||= super.sub(/_?publisher\z/i, '')
39
+ end
40
+
41
+ def test_framework
42
+ ::Rails.application.config.generators.options[:rails][:test_framework]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/named_base'
4
+
5
+ module Cloudenvoy
6
+ module Generators # :nodoc:
7
+ class SubscriberGenerator < ::Rails::Generators::NamedBase # :nodoc:
8
+ desc 'This generator creates a CloudEnvoy in app/subscribers and a corresponding test'
9
+
10
+ check_class_collision suffix: 'Subscriber'
11
+
12
+ def self.default_generator_root
13
+ File.dirname(__FILE__)
14
+ end
15
+
16
+ def create_subscriber_file
17
+ template 'subscriber.rb.erb', File.join('app/subscribers', class_path, "#{file_name}_subscriber.rb")
18
+ end
19
+
20
+ def create_test_file
21
+ return unless test_framework
22
+
23
+ create_subscriber_spec if test_framework == :rspec
24
+ end
25
+
26
+ private
27
+
28
+ def create_subscriber_spec
29
+ template_file = File.join(
30
+ 'spec/subscribers',
31
+ class_path,
32
+ "#{file_name}_subscriber_spec.rb"
33
+ )
34
+ template 'subscriber_spec.rb.erb', template_file
35
+ end
36
+
37
+ def file_name
38
+ @file_name ||= super.sub(/_?subscriber\z/i, '')
39
+ end
40
+
41
+ def test_framework
42
+ ::Rails.application.config.generators.options[:rails][:test_framework]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Publisher
3
+ include Cloudenvoy::Publisher
4
+
5
+ cloudenvoy_options topic: 'test-msgs'
6
+
7
+ def payload(msg)
8
+ # Format the message payload. The payload can be a hash or a string.
9
+ end
10
+ end
11
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+ <% module_namespacing do -%>
3
+ RSpec.describe <%= class_name %>Publisher, type: :publisher do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
6
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Subscriber
3
+ include Cloudenvoy::Subscriber
4
+
5
+ cloudenvoy_options topic: 'test-msgs'
6
+
7
+ def process(msg)
8
+ # Do something
9
+ end
10
+ end
11
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+ <% module_namespacing do -%>
3
+ RSpec.describe <%= class_name %>Subscriber, type: :subscriber do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
6
+ <% end -%>
@@ -23,8 +23,8 @@ namespace :cloudenvoy do
23
23
 
24
24
  # Notify user when no suscribers
25
25
  if list.empty?
26
- puts 'There are no subscribers defined in your application'
27
- return
26
+ puts 'Skipping subscribers (none defined)'
27
+ next
28
28
  end
29
29
 
30
30
  puts 'The following subscribers are configured:'
@@ -47,8 +47,8 @@ namespace :cloudenvoy do
47
47
 
48
48
  # Notify user when no topics
49
49
  if list.empty?
50
- puts 'There are no publishers defined in your application'
51
- return
50
+ puts 'Skipping publishers (none defined)'
51
+ next
52
52
  end
53
53
 
54
54
  puts 'The following topics are configured:'