cloudenvoy 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint_rubocop.yml +20 -0
- data/.github/workflows/{test.yml → test_ruby_2.5_2.6.yml} +8 -13
- data/.github/workflows/test_ruby_2.7.yml +36 -0
- data/.github/workflows/test_ruby_3.x.yml +35 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +5 -0
- data/Appraisals +24 -4
- data/CHANGELOG.md +16 -0
- data/README.md +7 -4
- data/app/controllers/cloudenvoy/subscriber_controller.rb +5 -2
- data/cloudenvoy.gemspec +0 -4
- data/examples/rails/.ruby-version +1 -1
- data/examples/rails/Gemfile +4 -1
- data/examples/rails/Gemfile.lock +139 -113
- data/examples/rails/README.md +1 -1
- data/examples/sinatra/Gemfile +18 -0
- data/examples/sinatra/Gemfile.lock +139 -0
- data/examples/sinatra/Procfile +1 -0
- data/examples/sinatra/README.md +41 -0
- data/examples/sinatra/app/publishers/hello_publisher.rb +34 -0
- data/examples/sinatra/app/subscribers/hello_subscriber.rb +16 -0
- data/examples/sinatra/app.rb +40 -0
- data/examples/sinatra/bin/console +8 -0
- data/examples/sinatra/config/initializers/cloudenvoy.rb +30 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_5.2.gemfile +1 -0
- data/gemfiles/rails_5.2.gemfile.lock +117 -92
- data/gemfiles/rails_6.0.gemfile +1 -0
- data/gemfiles/rails_6.0.gemfile.lock +118 -93
- data/gemfiles/rails_6.1.gemfile +8 -0
- data/gemfiles/rails_7.0.gemfile +8 -0
- data/gemfiles/semantic_logger_3.4.gemfile +1 -0
- data/gemfiles/semantic_logger_3.4.gemfile.lock +95 -189
- data/gemfiles/semantic_logger_4.6.gemfile +1 -0
- data/gemfiles/semantic_logger_4.6.gemfile.lock +95 -189
- data/gemfiles/semantic_logger_4.7.0.gemfile +1 -0
- data/gemfiles/semantic_logger_4.7.0.gemfile.lock +95 -189
- data/gemfiles/semantic_logger_4.7.2.gemfile +1 -0
- data/gemfiles/semantic_logger_4.7.2.gemfile.lock +95 -189
- data/lib/cloudenvoy/backend/google_pub_sub.rb +2 -2
- data/lib/cloudenvoy/message.rb +2 -2
- data/lib/cloudenvoy/subscriber.rb +1 -1
- data/lib/cloudenvoy/version.rb +1 -1
- data/lib/cloudenvoy.rb +1 -0
- data/lib/generators/cloudenvoy/publisher_generator.rb +46 -0
- data/lib/generators/cloudenvoy/subscriber_generator.rb +46 -0
- data/lib/generators/cloudenvoy/templates/publisher.rb.erb +11 -0
- data/lib/generators/cloudenvoy/templates/publisher_spec.rb.erb +6 -0
- data/lib/generators/cloudenvoy/templates/subscriber.rb.erb +11 -0
- data/lib/generators/cloudenvoy/templates/subscriber_spec.rb.erb +6 -0
- metadata +28 -51
- data/Gemfile.lock +0 -267
- 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.
|
4
|
+
cloudenvoy (0.5.0)
|
5
5
|
activesupport
|
6
6
|
google-cloud-pubsub (~> 2.0)
|
7
7
|
jwt
|
@@ -10,200 +10,119 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
|
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 (>=
|
65
|
-
minitest (
|
66
|
-
tzinfo (~>
|
67
|
-
zeitwerk (~> 2.
|
68
|
-
addressable (2.
|
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.
|
21
|
+
appraisal (2.4.1)
|
71
22
|
bundler
|
72
23
|
rake
|
73
24
|
thor (>= 0.14.0)
|
74
|
-
ast (2.4.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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.10.0)
|
31
|
+
faraday-em_http (~> 1.0)
|
32
|
+
faraday-em_synchrony (~> 1.0)
|
33
|
+
faraday-excon (~> 1.1)
|
34
|
+
faraday-httpclient (~> 1.0)
|
35
|
+
faraday-multipart (~> 1.0)
|
36
|
+
faraday-net_http (~> 1.0)
|
37
|
+
faraday-net_http_persistent (~> 1.0)
|
38
|
+
faraday-patron (~> 1.0)
|
39
|
+
faraday-rack (~> 1.0)
|
40
|
+
faraday-retry (~> 1.0)
|
41
|
+
ruby2_keywords (>= 0.0.4)
|
42
|
+
faraday-em_http (1.0.0)
|
43
|
+
faraday-em_synchrony (1.0.0)
|
44
|
+
faraday-excon (1.1.0)
|
45
|
+
faraday-httpclient (1.0.1)
|
46
|
+
faraday-multipart (1.0.3)
|
82
47
|
multipart-post (>= 1.2, < 3)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
48
|
+
faraday-net_http (1.0.1)
|
49
|
+
faraday-net_http_persistent (1.2.0)
|
50
|
+
faraday-patron (1.0.0)
|
51
|
+
faraday-rack (1.0.0)
|
52
|
+
faraday-retry (1.0.3)
|
53
|
+
gapic-common (0.8.0)
|
54
|
+
faraday (~> 1.3)
|
55
|
+
google-protobuf (~> 3.14)
|
56
|
+
googleapis-common-protos (>= 1.3.11, < 2.a)
|
57
|
+
googleapis-common-protos-types (>= 1.0.6, < 2.a)
|
58
|
+
googleauth (>= 0.17.0, < 2.a)
|
59
|
+
grpc (~> 1.36)
|
60
|
+
google-cloud-core (1.6.0)
|
92
61
|
google-cloud-env (~> 1.0)
|
93
62
|
google-cloud-errors (~> 1.0)
|
94
|
-
google-cloud-env (1.
|
63
|
+
google-cloud-env (1.5.0)
|
95
64
|
faraday (>= 0.17.3, < 2.0)
|
96
|
-
google-cloud-errors (1.0
|
97
|
-
google-cloud-pubsub (2.1
|
65
|
+
google-cloud-errors (1.2.0)
|
66
|
+
google-cloud-pubsub (2.9.1)
|
98
67
|
concurrent-ruby (~> 1.1)
|
99
68
|
google-cloud-core (~> 1.5)
|
100
69
|
google-cloud-pubsub-v1 (~> 0.0)
|
101
|
-
google-cloud-pubsub-v1 (0.1
|
102
|
-
gapic-common (
|
70
|
+
google-cloud-pubsub-v1 (0.7.1)
|
71
|
+
gapic-common (>= 0.7, < 2.a)
|
103
72
|
google-cloud-errors (~> 1.0)
|
104
|
-
grpc-google-iam-v1 (>= 0.6.10, < 2.
|
105
|
-
google-protobuf (3.
|
106
|
-
googleapis-common-protos (1.3.
|
107
|
-
google-protobuf (~> 3.
|
108
|
-
googleapis-common-protos-types (
|
73
|
+
grpc-google-iam-v1 (>= 0.6.10, < 2.a)
|
74
|
+
google-protobuf (3.19.4-x86_64-darwin)
|
75
|
+
googleapis-common-protos (1.3.12)
|
76
|
+
google-protobuf (~> 3.14)
|
77
|
+
googleapis-common-protos-types (~> 1.2)
|
109
78
|
grpc (~> 1.27)
|
110
|
-
googleapis-common-protos-types (1.0
|
111
|
-
google-protobuf (~> 3.
|
112
|
-
googleauth (
|
113
|
-
faraday (>= 0.17.3, <
|
79
|
+
googleapis-common-protos-types (1.3.0)
|
80
|
+
google-protobuf (~> 3.14)
|
81
|
+
googleauth (1.1.2)
|
82
|
+
faraday (>= 0.17.3, < 3.a)
|
114
83
|
jwt (>= 1.4, < 3.0)
|
115
84
|
memoist (~> 0.16)
|
116
85
|
multi_json (~> 1.11)
|
117
86
|
os (>= 0.9, < 2.0)
|
118
|
-
signet (
|
119
|
-
grpc (1.
|
120
|
-
google-protobuf (~> 3.
|
87
|
+
signet (>= 0.16, < 2.a)
|
88
|
+
grpc (1.43.1-universal-darwin)
|
89
|
+
google-protobuf (~> 3.18)
|
121
90
|
googleapis-common-protos-types (~> 1.0)
|
122
|
-
grpc-google-iam-v1 (0.
|
123
|
-
google-protobuf (~> 3.
|
124
|
-
googleapis-common-protos (>= 1.3.
|
91
|
+
grpc-google-iam-v1 (1.0.0)
|
92
|
+
google-protobuf (~> 3.14)
|
93
|
+
googleapis-common-protos (>= 1.3.12, < 2.0)
|
125
94
|
grpc (~> 1.27)
|
126
95
|
hashdiff (1.0.1)
|
127
|
-
i18n (1.8.
|
96
|
+
i18n (1.8.11)
|
128
97
|
concurrent-ruby (~> 1.0)
|
129
98
|
jaro_winkler (1.5.4)
|
130
|
-
jwt (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)
|
99
|
+
jwt (2.3.0)
|
138
100
|
memoist (0.16.2)
|
139
|
-
|
140
|
-
mimemagic (0.3.5)
|
141
|
-
mini_mime (1.0.2)
|
142
|
-
mini_portile2 (2.4.0)
|
143
|
-
minitest (5.14.2)
|
101
|
+
minitest (5.15.0)
|
144
102
|
multi_json (1.15.0)
|
145
103
|
multipart-post (2.1.1)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
os (1.1.1)
|
150
|
-
parallel (1.19.2)
|
151
|
-
parser (2.7.1.5)
|
104
|
+
os (1.1.4)
|
105
|
+
parallel (1.21.0)
|
106
|
+
parser (3.1.0.0)
|
152
107
|
ast (~> 2.4.1)
|
153
108
|
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
109
|
rainbow (3.0.0)
|
184
|
-
rake (13.0.
|
110
|
+
rake (13.0.6)
|
185
111
|
retriable (3.1.2)
|
186
|
-
|
187
|
-
|
188
|
-
rspec-
|
189
|
-
rspec-
|
190
|
-
|
191
|
-
|
192
|
-
|
112
|
+
rexml (3.2.5)
|
113
|
+
rspec (3.10.0)
|
114
|
+
rspec-core (~> 3.10.0)
|
115
|
+
rspec-expectations (~> 3.10.0)
|
116
|
+
rspec-mocks (~> 3.10.0)
|
117
|
+
rspec-core (3.10.1)
|
118
|
+
rspec-support (~> 3.10.0)
|
119
|
+
rspec-expectations (3.10.1)
|
193
120
|
diff-lcs (>= 1.2.0, < 2.0)
|
194
|
-
rspec-support (~> 3.
|
195
|
-
rspec-mocks (3.
|
121
|
+
rspec-support (~> 3.10.0)
|
122
|
+
rspec-mocks (3.10.2)
|
196
123
|
diff-lcs (>= 1.2.0, < 2.0)
|
197
|
-
rspec-support (~> 3.
|
198
|
-
rspec-
|
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)
|
124
|
+
rspec-support (~> 3.10.0)
|
125
|
+
rspec-support (3.10.3)
|
207
126
|
rubocop (0.76.0)
|
208
127
|
jaro_winkler (~> 1.5.1)
|
209
128
|
parallel (~> 1.10)
|
@@ -213,53 +132,40 @@ GEM
|
|
213
132
|
unicode-display_width (>= 1.4.0, < 1.7)
|
214
133
|
rubocop-rspec (1.37.0)
|
215
134
|
rubocop (>= 0.68.1)
|
216
|
-
ruby-progressbar (1.
|
135
|
+
ruby-progressbar (1.11.0)
|
136
|
+
ruby2_keywords (0.0.5)
|
217
137
|
semantic_logger (4.7.2)
|
218
138
|
concurrent-ruby (~> 1.0)
|
219
|
-
signet (0.
|
220
|
-
addressable (~> 2.
|
221
|
-
faraday (>= 0.17.
|
139
|
+
signet (0.16.1)
|
140
|
+
addressable (~> 2.8)
|
141
|
+
faraday (>= 0.17.5, < 3.0)
|
222
142
|
jwt (>= 1.5, < 3.0)
|
223
143
|
multi_json (~> 1.10)
|
224
|
-
|
144
|
+
thor (1.1.0)
|
145
|
+
timecop (0.9.4)
|
146
|
+
tzinfo (2.0.4)
|
225
147
|
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
148
|
unicode-display_width (1.6.1)
|
238
|
-
webmock (3.
|
239
|
-
addressable (>= 2.
|
149
|
+
webmock (3.14.0)
|
150
|
+
addressable (>= 2.8.0)
|
240
151
|
crack (>= 0.3.2)
|
241
152
|
hashdiff (>= 0.4.0, < 2.0.0)
|
242
|
-
|
243
|
-
websocket-extensions (>= 0.1.0)
|
244
|
-
websocket-extensions (0.1.5)
|
245
|
-
zeitwerk (2.4.0)
|
153
|
+
zeitwerk (2.5.3)
|
246
154
|
|
247
155
|
PLATFORMS
|
248
156
|
ruby
|
249
157
|
|
250
158
|
DEPENDENCIES
|
159
|
+
activesupport (= 6.1)
|
251
160
|
appraisal
|
252
161
|
cloudenvoy!
|
253
|
-
rails
|
254
162
|
rake (>= 12.3.3)
|
255
163
|
rspec (~> 3.0)
|
256
|
-
rspec-rails
|
257
164
|
rubocop (= 0.76.0)
|
258
165
|
rubocop-rspec (= 1.37.0)
|
259
166
|
semantic_logger (= 4.7.2)
|
260
|
-
sqlite3
|
261
167
|
timecop
|
262
168
|
webmock
|
263
169
|
|
264
170
|
BUNDLED WITH
|
265
|
-
2.
|
171
|
+
2.3.6
|
@@ -32,7 +32,7 @@ module Cloudenvoy
|
|
32
32
|
# @return [Google::Cloud::Pub] The low level client instance.
|
33
33
|
#
|
34
34
|
def backend
|
35
|
-
@backend ||= Google::Cloud::PubSub.new({
|
35
|
+
@backend ||= Google::Cloud::PubSub.new(**{
|
36
36
|
project_id: config.gcp_project_id,
|
37
37
|
emulator_host: development? ? Cloudenvoy::Config::EMULATOR_HOST : nil
|
38
38
|
}.compact)
|
@@ -109,7 +109,7 @@ module Cloudenvoy
|
|
109
109
|
ps_topic = backend.topic(topic, skip_lookup: true)
|
110
110
|
|
111
111
|
# Attempt to create the subscription
|
112
|
-
ps_topic.subscribe(name, sub_config)
|
112
|
+
ps_topic.subscribe(name, **sub_config)
|
113
113
|
rescue Google::Cloud::AlreadyExistsError
|
114
114
|
# Update endpoint on subscription
|
115
115
|
# Topic is not updated as it is name-dependent
|
data/lib/cloudenvoy/message.rb
CHANGED
data/lib/cloudenvoy/version.rb
CHANGED
data/lib/cloudenvoy.rb
CHANGED
@@ -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
|