stimulus_reflex 3.5.0.rc4 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +19 -13
  3. data/app/assets/javascripts/stimulus_reflex.js +1 -1
  4. data/app/assets/javascripts/stimulus_reflex.umd.js +1 -1
  5. data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +2 -2
  6. data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +1 -1
  7. data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +1 -1
  8. data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +1 -1
  9. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +1 -1
  10. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +1 -1
  11. data/lib/install/action_cable.rb +30 -30
  12. data/lib/install/broadcaster.rb +11 -11
  13. data/lib/install/bundle.rb +9 -9
  14. data/lib/install/compression.rb +5 -5
  15. data/lib/install/config.rb +22 -22
  16. data/lib/install/development.rb +19 -19
  17. data/lib/install/esbuild.rb +28 -28
  18. data/lib/install/example.rb +3 -3
  19. data/lib/install/importmap.rb +29 -29
  20. data/lib/install/initializers.rb +3 -3
  21. data/lib/install/mrujs.rb +25 -25
  22. data/lib/install/npm_packages.rb +7 -7
  23. data/lib/install/reflexes.rb +2 -2
  24. data/lib/install/shakapacker.rb +23 -23
  25. data/lib/install/spring.rb +7 -7
  26. data/lib/install/updatable.rb +7 -7
  27. data/lib/install/vite.rb +22 -22
  28. data/lib/install/webpacker.rb +27 -27
  29. data/lib/install/yarn.rb +9 -9
  30. data/lib/stimulus_reflex/html/document_fragment.rb +5 -3
  31. data/lib/stimulus_reflex/installer.rb +303 -277
  32. data/lib/stimulus_reflex/version.rb +1 -1
  33. data/lib/stimulus_reflex.rb +2 -0
  34. data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +8 -8
  35. data/package.json +1 -1
  36. data/stimulus_reflex.gemspec +2 -0
  37. data/yarn.lock +7 -7
  38. metadata +30 -2
@@ -1,355 +1,381 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ### general utilities
3
+ module StimulusReflex
4
+ class Installer
5
+ include Thor::Base
6
+ include Thor::Actions
4
7
 
5
- def fetch(step_path, file)
6
- relative_path = step_path + file
7
- location = template_src + relative_path
8
+ source_root Dir.pwd
8
9
 
9
- Pathname.new(location)
10
- end
10
+ ## Thor wrapper
11
11
 
12
- def complete_step(step)
13
- create_file "tmp/stimulus_reflex_installer/#{step}", verbose: false
14
- end
12
+ def self.create_file(...)
13
+ new.create_file(...)
14
+ end
15
15
 
16
- def create_or_append(path, *args, &block)
17
- FileUtils.touch(path)
18
- append_file(path, *args, &block)
19
- end
16
+ def self.append_file(...)
17
+ new.append_file(...)
18
+ end
20
19
 
21
- def current_template
22
- ENV["LOCATION"].split("/").last.gsub(".rb", "")
23
- end
20
+ def self.copy_file(...)
21
+ new.copy_file(...)
22
+ end
24
23
 
25
- def pack_path_missing?
26
- return false unless pack_path.nil?
27
- halt "#{friendly_pack_path} is missing. You need a valid application pack file to proceed."
28
- end
24
+ def self.say(...)
25
+ new.say(...)
26
+ end
29
27
 
30
- def halt(message)
31
- say "❌ #{message}", :red
32
- create_file "tmp/stimulus_reflex_installer/halt", verbose: false
33
- end
28
+ ### general utilities
34
29
 
35
- def backup(path, delete: false)
36
- if !path.exist?
37
- yield
38
- return
39
- end
30
+ def self.fetch(step_path, file)
31
+ relative_path = step_path + file
32
+ location = template_src + relative_path
40
33
 
41
- backup_path = Pathname.new("#{path}.bak")
42
- old_path = path.relative_path_from(Rails.root).to_s
43
- filename = path.to_path.split("/").last
34
+ Pathname.new(location)
35
+ end
44
36
 
45
- if backup_path.exist?
46
- if backup_path.read == path.read
47
- path.delete if delete
48
- yield
49
- return
37
+ def self.complete_step(step)
38
+ create_file "tmp/stimulus_reflex_installer/#{step}", verbose: false
50
39
  end
51
- backup_path.delete
52
- end
53
40
 
54
- copy_file(path, backup_path, verbose: false)
55
- path.delete if delete
41
+ def self.create_or_append(path, *args, &block)
42
+ FileUtils.touch(path)
43
+ append_file(path, *args, &block)
44
+ end
56
45
 
57
- yield
46
+ def self.current_template
47
+ ENV["LOCATION"].split("/").last.gsub(".rb", "")
48
+ end
58
49
 
59
- if path.read != backup_path.read
60
- create_or_append(backups_path, "#{old_path}\n", verbose: false)
61
- end
62
- say "📦 #{old_path} backed up as #{filename}.bak"
63
- end
50
+ def self.pack_path_missing?
51
+ return false unless pack_path.nil?
52
+ halt "#{friendly_pack_path} is missing. You need a valid application pack file to proceed."
53
+ end
64
54
 
65
- def add_gem(name)
66
- create_or_append(add_gem_list, "#{name}\n", verbose: false)
67
- say "☑️ Added #{name} to the Gemfile"
68
- end
55
+ def self.halt(message)
56
+ say "#{message}", :red
57
+ create_file "tmp/stimulus_reflex_installer/halt", verbose: false
58
+ end
69
59
 
70
- def remove_gem(name)
71
- create_or_append(remove_gem_list, "#{name}\n", verbose: false)
72
- say "❎ Removed #{name} from Gemfile"
73
- end
60
+ def self.backup(path, delete: false)
61
+ if !path.exist?
62
+ yield
63
+ return
64
+ end
74
65
 
75
- def add_package(name)
76
- create_or_append(package_list, "#{name}\n", verbose: false)
77
- say "☑️ Enqueued #{name} to be added to dependencies"
78
- end
66
+ backup_path = Pathname.new("#{path}.bak")
67
+ old_path = path.relative_path_from(Rails.root).to_s
68
+ filename = path.to_path.split("/").last
69
+
70
+ if backup_path.exist?
71
+ if backup_path.read == path.read
72
+ path.delete if delete
73
+ yield
74
+ return
75
+ end
76
+ backup_path.delete
77
+ end
79
78
 
80
- def add_dev_package(name)
81
- create_or_append(dev_package_list, "#{name}\n", verbose: false)
82
- say "☑️ Enqueued #{name} to be added to dev dependencies"
83
- end
79
+ copy_file(path, backup_path, verbose: false)
80
+ path.delete if delete
84
81
 
85
- def drop_package(name)
86
- create_or_append(drop_package_list, "#{name}\n", verbose: false)
87
- say "❎ Enqueued #{name} to be removed from dependencies"
88
- end
82
+ yield
89
83
 
90
- def gemfile_hash
91
- Digest::MD5.hexdigest(gemfile_path.read)
92
- end
84
+ if path.read != backup_path.read
85
+ create_or_append(backups_path, "#{old_path}\n", verbose: false)
86
+ end
87
+ say "📦 #{old_path} backed up as #{filename}.bak"
88
+ end
93
89
 
94
- ### memoized values
90
+ def self.add_gem(name)
91
+ create_or_append(add_gem_list, "#{name}\n", verbose: false)
92
+ say "☑️ Added #{name} to the Gemfile"
93
+ end
95
94
 
96
- def sr_npm_version
97
- @sr_npm_version ||= StimulusReflex::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
98
- end
95
+ def self.remove_gem(name)
96
+ create_or_append(remove_gem_list, "#{name}\n", verbose: false)
97
+ say "❎ Removed #{name} from Gemfile"
98
+ end
99
99
 
100
- def cr_npm_version
101
- @cr_npm_version ||= CableReady::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
102
- end
100
+ def self.add_package(name)
101
+ create_or_append(package_list, "#{name}\n", verbose: false)
102
+ say "☑️ Enqueued #{name} to be added to dependencies"
103
+ end
103
104
 
104
- def package_json_path
105
- @package_json_path ||= Rails.root.join("package.json")
106
- end
105
+ def self.add_dev_package(name)
106
+ create_or_append(dev_package_list, "#{name}\n", verbose: false)
107
+ say "☑️ Enqueued #{name} to be added to dev dependencies"
108
+ end
107
109
 
108
- def installer_entrypoint_path
109
- create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/entrypoint")
110
- end
110
+ def self.drop_package(name)
111
+ create_or_append(drop_package_list, "#{name}\n", verbose: false)
112
+ say "❎ Enqueued #{name} to be removed from dependencies"
113
+ end
111
114
 
112
- def entrypoint
113
- path = installer_entrypoint_path
114
- @entrypoint ||= File.exist?(path) ? File.read(path) : auto_detect_entrypoint
115
- end
115
+ def self.gemfile_hash
116
+ Digest::MD5.hexdigest(gemfile_path.read)
117
+ end
116
118
 
117
- def auto_detect_entrypoint
118
- entrypoint = [
119
- "app/javascript",
120
- "app/frontend",
121
- "app/client",
122
- "app/webpack"
123
- ].find { |path| File.exist?(Rails.root.join(path)) } || "app/javascript"
119
+ ### memoized values
124
120
 
125
- puts
126
- puts "Where do JavaScript files live in your app? Our best guess is: \e[1m#{entrypoint}\e[22m 🤔"
127
- puts "Press enter to accept this, or type a different path."
128
- print "> "
121
+ def self.sr_npm_version
122
+ @sr_npm_version ||= StimulusReflex::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
123
+ end
129
124
 
130
- input = Rails.env.test? ? "tmp/app/javascript" : $stdin.gets.chomp
131
- entrypoint = input unless input.blank?
125
+ def self.cr_npm_version
126
+ @cr_npm_version ||= CableReady::VERSION.gsub(".pre", "-pre").gsub(".rc", "-rc")
127
+ end
132
128
 
133
- File.write(installer_entrypoint_path, entrypoint)
129
+ def self.package_json_path
130
+ @package_json_path ||= Rails.root.join("package.json")
131
+ end
134
132
 
135
- entrypoint
136
- end
133
+ def self.installer_entrypoint_path
134
+ create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/entrypoint")
135
+ end
137
136
 
138
- def installer_bundler_path
139
- create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/bundler")
140
- end
137
+ def self.entrypoint
138
+ path = installer_entrypoint_path
139
+ @entrypoint ||= File.exist?(path) ? File.read(path) : auto_detect_entrypoint
140
+ end
141
141
 
142
- def bundler
143
- path = installer_bundler_path
144
- @bundler ||= File.exist?(path) ? File.read(path) : auto_detect_bundler
142
+ def self.auto_detect_entrypoint
143
+ entrypoint = [
144
+ "app/javascript",
145
+ "app/frontend",
146
+ "app/client",
147
+ "app/webpack"
148
+ ].find { |path| File.exist?(Rails.root.join(path)) } || "app/javascript"
145
149
 
146
- @bundler.inquiry
147
- end
150
+ puts
151
+ puts "Where do JavaScript files live in your app? Our best guess is: \e[1m#{entrypoint}\e[22m 🤔"
152
+ puts "Press enter to accept this, or type a different path."
153
+ print "> "
148
154
 
149
- def auto_detect_bundler
150
- # auto-detect build tool based on existing packages and configuration
151
- if importmap_path.exist?
152
- bundler = "importmap"
153
- elsif package_json_path.exist?
154
- package_json = package_json_path.read
155
-
156
- bundler = "webpacker" if package_json.include?('"@rails/webpacker":')
157
- bundler = "esbuild" if package_json.include?('"esbuild":')
158
- bundler = "vite" if package_json.include?('"vite":')
159
- bundler = "shakapacker" if package_json.include?('"shakapacker":')
160
-
161
- if !bundler
162
- puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
163
- exit
164
- end
165
- else
166
- puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
167
- exit
168
- end
155
+ input = Rails.env.test? ? "tmp/app/javascript" : $stdin.gets.chomp
156
+ entrypoint = input unless input.blank?
169
157
 
170
- puts
171
- puts "It looks like you're using \e[1m#{bundler}\e[22m as your bundler. Is that correct? (Y/n)"
172
- print "> "
158
+ File.write(installer_entrypoint_path, entrypoint)
173
159
 
174
- input = $stdin.gets.chomp
160
+ entrypoint
161
+ end
175
162
 
176
- if input.downcase == "n"
177
- puts
178
- puts "StimulusReflex installation supports: esbuild, webpacker, vite, shakapacker and importmap."
179
- puts "Please run \e[1;94mrails stimulus_reflex:install [bundler]\e[0m to install StimulusReflex and CableReady."
180
- exit
181
- end
163
+ def self.installer_bundler_path
164
+ create_dir_for_file_if_not_exists("tmp/stimulus_reflex_installer/bundler")
165
+ end
182
166
 
183
- File.write(installer_bundler_path, bundler)
167
+ def self.bundler
168
+ path = installer_bundler_path
169
+ @bundler ||= File.exist?(path) ? File.read(path) : auto_detect_bundler
184
170
 
185
- bundler
186
- end
171
+ @bundler.inquiry
172
+ end
187
173
 
188
- def create_dir_if_not_exists(dir_path)
189
- FileUtils.mkdir_p(dir_path)
174
+ def self.auto_detect_bundler
175
+ # auto-detect build tool based on existing packages and configuration
176
+ if importmap_path.exist?
177
+ bundler = "importmap"
178
+ elsif package_json_path.exist?
179
+ package_json = package_json_path.read
180
+
181
+ bundler = "webpacker" if package_json.include?('"@rails/webpacker":')
182
+ bundler = "esbuild" if package_json.include?('"esbuild":')
183
+ bundler = "vite" if package_json.include?('"vite":')
184
+ bundler = "shakapacker" if package_json.include?('"shakapacker":')
185
+
186
+ if !bundler
187
+ puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
188
+ exit
189
+ end
190
+ else
191
+ puts "❌ You must be using a node-based bundler such as esbuild, webpacker, vite or shakapacker (package.json) or importmap (config/importmap.rb) to use StimulusReflex."
192
+ exit
193
+ end
190
194
 
191
- Pathname.new(dir_path)
192
- end
195
+ puts
196
+ puts "It looks like you're using \e[1m#{bundler}\e[22m as your bundler. Is that correct? (Y/n)"
197
+ print "> "
193
198
 
194
- def create_dir_for_file_if_not_exists(file_path)
195
- dir_path = File.dirname(file_path)
196
- create_dir_if_not_exists(dir_path)
199
+ input = $stdin.gets.chomp
197
200
 
198
- Pathname.new(file_path)
199
- end
201
+ if input.downcase == "n"
202
+ puts
203
+ puts "StimulusReflex installation supports: esbuild, webpacker, vite, shakapacker and importmap."
204
+ puts "Please run \e[1;94mrails stimulus_reflex:install[bundler]\e[0m to install StimulusReflex and CableReady."
205
+ exit
206
+ end
200
207
 
201
- def config_path
202
- @config_path ||= create_dir_if_not_exists(Rails.root.join(entrypoint, "config"))
203
- end
208
+ File.write(installer_bundler_path, bundler)
204
209
 
205
- def importmap_path
206
- @importmap_path ||= Rails.root.join("config/importmap.rb")
207
- end
210
+ bundler
211
+ end
208
212
 
209
- def friendly_importmap_path
210
- @friendly_importmap_path ||= importmap_path.relative_path_from(Rails.root).to_s
211
- end
213
+ def self.create_dir_if_not_exists(dir_path)
214
+ FileUtils.mkdir_p(dir_path)
212
215
 
213
- def pack
214
- @pack ||= pack_path.read
215
- end
216
+ Pathname.new(dir_path)
217
+ end
216
218
 
217
- def friendly_pack_path
218
- @friendly_pack_path ||= pack_path.relative_path_from(Rails.root).to_s
219
- end
219
+ def self.create_dir_for_file_if_not_exists(file_path)
220
+ dir_path = File.dirname(file_path)
221
+ create_dir_if_not_exists(dir_path)
220
222
 
221
- def pack_path
222
- @pack_path ||= [
223
- Rails.root.join(entrypoint, "application.js"),
224
- Rails.root.join(entrypoint, "packs/application.js"),
225
- Rails.root.join(entrypoint, "entrypoints/application.js")
226
- ].find(&:exist?)
227
- end
223
+ Pathname.new(file_path)
224
+ end
228
225
 
229
- def package_list
230
- @package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/npm_package_list")
231
- end
226
+ def self.config_path
227
+ @config_path ||= create_dir_if_not_exists(Rails.root.join(entrypoint, "config"))
228
+ end
232
229
 
233
- def dev_package_list
234
- @dev_package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/npm_dev_package_list")
235
- end
230
+ def self.importmap_path
231
+ @importmap_path ||= Rails.root.join("config/importmap.rb")
232
+ end
236
233
 
237
- def drop_package_list
238
- @drop_package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/drop_npm_package_list")
239
- end
234
+ def self.friendly_importmap_path
235
+ @friendly_importmap_path ||= importmap_path.relative_path_from(Rails.root).to_s
236
+ end
240
237
 
241
- def template_src
242
- @template_src ||= File.read("tmp/stimulus_reflex_installer/template_src")
243
- end
238
+ def self.pack
239
+ @pack ||= pack_path.read
240
+ end
244
241
 
245
- def controllers_path
246
- @controllers_path ||= Rails.root.join(entrypoint, "controllers")
247
- end
242
+ def self.friendly_pack_path
243
+ @friendly_pack_path ||= pack_path.relative_path_from(Rails.root).to_s
244
+ end
248
245
 
249
- def gemfile_path
250
- @gemfile_path ||= Rails.root.join("Gemfile")
251
- end
246
+ def self.pack_path
247
+ @pack_path ||= [
248
+ Rails.root.join(entrypoint, "application.js"),
249
+ Rails.root.join(entrypoint, "packs/application.js"),
250
+ Rails.root.join(entrypoint, "entrypoints/application.js")
251
+ ].find(&:exist?)
252
+ end
252
253
 
253
- def gemfile
254
- @gemfile ||= gemfile_path.read
255
- end
254
+ def self.package_list
255
+ @package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/npm_package_list")
256
+ end
256
257
 
257
- def prefix
258
- # standard:disable Style/RedundantStringEscape
259
- @prefix ||= {
260
- "vite" => "..\/",
261
- "webpacker" => "",
262
- "shakapacker" => "",
263
- "importmap" => "",
264
- "esbuild" => ".\/"
265
- }[bundler]
266
- # standard:enable Style/RedundantStringEscape
267
- end
258
+ def self.dev_package_list
259
+ @dev_package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/npm_dev_package_list")
260
+ end
268
261
 
269
- def application_record_path
270
- @application_record_path ||= Rails.root.join("app/models/application_record.rb")
271
- end
262
+ def self.drop_package_list
263
+ @drop_package_list ||= Rails.root.join("tmp/stimulus_reflex_installer/drop_npm_package_list")
264
+ end
272
265
 
273
- def action_cable_initializer_path
274
- @action_cable_initializer_path ||= Rails.root.join("config/initializers/action_cable.rb")
275
- end
266
+ def self.template_src
267
+ @template_src ||= File.read("tmp/stimulus_reflex_installer/template_src")
268
+ end
276
269
 
277
- def action_cable_initializer_working_path
278
- @action_cable_initializer_working_path ||= Rails.root.join(working, "action_cable.rb")
279
- end
270
+ def self.controllers_path
271
+ @controllers_path ||= Rails.root.join(entrypoint, "controllers")
272
+ end
280
273
 
281
- def development_path
282
- @development_path ||= Rails.root.join("config/environments/development.rb")
283
- end
274
+ def self.gemfile_path
275
+ @gemfile_path ||= Rails.root.join("Gemfile")
276
+ end
284
277
 
285
- def development_working_path
286
- @development_working_path ||= Rails.root.join(working, "development.rb")
287
- end
278
+ def self.gemfile
279
+ @gemfile ||= gemfile_path.read
280
+ end
288
281
 
289
- def backups_path
290
- @backups_path ||= Rails.root.join("tmp/stimulus_reflex_installer/backups")
291
- end
282
+ def self.prefix
283
+ # standard:disable Style/RedundantStringEscape
284
+ @prefix ||= {
285
+ "vite" => "..\/",
286
+ "webpacker" => "",
287
+ "shakapacker" => "",
288
+ "importmap" => "",
289
+ "esbuild" => ".\/"
290
+ }[bundler]
291
+ # standard:enable Style/RedundantStringEscape
292
+ end
292
293
 
293
- def add_gem_list
294
- @add_gem_list ||= Rails.root.join("tmp/stimulus_reflex_installer/add_gem_list")
295
- end
294
+ def self.application_record_path
295
+ @application_record_path ||= Rails.root.join("app/models/application_record.rb")
296
+ end
296
297
 
297
- def remove_gem_list
298
- @remove_gem_list ||= Rails.root.join("tmp/stimulus_reflex_installer/remove_gem_list")
299
- end
298
+ def self.action_cable_initializer_path
299
+ @action_cable_initializer_path ||= Rails.root.join("config/initializers/action_cable.rb")
300
+ end
300
301
 
301
- def options_path
302
- @options_path ||= Rails.root.join("tmp/stimulus_reflex_installer/options")
303
- end
302
+ def self.action_cable_initializer_working_path
303
+ @action_cable_initializer_working_path ||= Rails.root.join(working, "action_cable.rb")
304
+ end
304
305
 
305
- def options
306
- @options ||= YAML.safe_load(File.read(options_path))
307
- end
306
+ def self.development_path
307
+ @development_path ||= Rails.root.join("config/environments/development.rb")
308
+ end
308
309
 
309
- def working
310
- @working ||= Rails.root.join("tmp/stimulus_reflex_installer/working")
311
- end
310
+ def self.development_working_path
311
+ @development_working_path ||= Rails.root.join(working, "development.rb")
312
+ end
313
+
314
+ def self.backups_path
315
+ @backups_path ||= Rails.root.join("tmp/stimulus_reflex_installer/backups")
316
+ end
312
317
 
313
- ### support for development step
314
-
315
- def write_redis_recommendation(development_working, lines, index, gemfile)
316
- # provide a recommendation for using redis-session-store, including commented source code
317
- if !lines.index { |line| line.include?("StimulusReflex does not support :cookie_store") }
318
- lines.insert index + 1, <<RUBY
319
-
320
- # StimulusReflex does not support :cookie_store, and we recommend switching to Redis.
321
- # To use `redis-session-store`, make sure to add it to your Gemfile and run `bundle install`.
322
-
323
- # config.session_store :redis_session_store,
324
- # serializer: :json,
325
- # on_redis_down: ->(*a) { Rails.logger.error("Redis down! \#{a.inspect}") },
326
- # redis: {
327
- # expire_after: 120.minutes,
328
- # key_prefix: "session:",
329
- # url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }
330
- # }
331
- RUBY
332
- development_working.write lines.join
333
- # add redis-session-store to Gemfile, but comment it out
334
- if !gemfile.match?(/gem ['"]redis-session-store['"]/)
335
- append_file(gemfile_path, verbose: false) do
336
- <<~RUBY
337
-
338
- # StimulusReflex recommends using Redis for session storage
339
- # gem "redis-session-store", "0.11.5"
318
+ def self.add_gem_list
319
+ @add_gem_list ||= Rails.root.join("tmp/stimulus_reflex_installer/add_gem_list")
320
+ end
321
+
322
+ def self.remove_gem_list
323
+ @remove_gem_list ||= Rails.root.join("tmp/stimulus_reflex_installer/remove_gem_list")
324
+ end
325
+
326
+ def self.options_path
327
+ @options_path ||= Rails.root.join("tmp/stimulus_reflex_installer/options")
328
+ end
329
+
330
+ def self.options
331
+ @options ||= YAML.safe_load(File.read(options_path))
332
+ end
333
+
334
+ def self.working
335
+ @working ||= Rails.root.join("tmp/stimulus_reflex_installer/working")
336
+ end
337
+
338
+ ### support for development step
339
+
340
+ def self.write_redis_recommendation(development_working, lines, index, gemfile)
341
+ # provide a recommendation for using redis-session-store, including commented source code
342
+ if !lines.index { |line| line.include?("StimulusReflex does not support :cookie_store") }
343
+ lines.insert index + 1, <<~RUBY
344
+ # StimulusReflex does not support :cookie_store, and we recommend switching to Redis.
345
+ # To use `redis-session-store`, make sure to add it to your Gemfile and run `bundle install
346
+ # config.session_store :redis_session_store,
347
+ # serializer: :json,
348
+ # on_redis_down: ->(*a) { Rails.logger.error("Redis down! \#{a.inspect}") },
349
+ # redis: {
350
+ # expire_after: 120.minutes,
351
+ # key_prefix: "session:",
352
+ # url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }
353
+ # }
340
354
  RUBY
355
+
356
+ development_working.write lines.join
357
+ # add redis-session-store to Gemfile, but comment it out
358
+ if !gemfile.match?(/gem ['"]redis-session-store['"]/)
359
+ append_file(gemfile_path, verbose: false) do
360
+ <<~RUBY
361
+
362
+ # StimulusReflex recommends using Redis for session storage
363
+ # gem "redis-session-store", "0.11.5"
364
+ RUBY
365
+ end
366
+ say "💡 Added redis-session-store 0.11.5 to the Gemfile, commented out"
367
+ end
341
368
  end
342
- say "💡 Added redis-session-store 0.11.5 to the Gemfile, commented out"
343
369
  end
344
- end
345
- end
346
370
 
347
- def find_index(lines)
348
- # accomodate devs who modify their development.rb file structure
349
- if (index = lines.index { |line| line =~ /caching-dev/ })
350
- index += 3
351
- else
352
- index = lines.index { |line| line =~ /^Rails.application.configure do/ } + 1
371
+ def self.find_index(lines)
372
+ # accomodate devs who modify their development.rb file structure
373
+ if (index = lines.index { |line| line =~ /caching-dev/ })
374
+ index += 3
375
+ else
376
+ index = lines.index { |line| line =~ /^Rails.application.configure do/ } + 1
377
+ end
378
+ index
379
+ end
353
380
  end
354
- index
355
381
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusReflex
4
- VERSION = "3.5.0.rc4"
4
+ VERSION = "3.5.0"
5
5
  end