stimulus_reflex 3.5.0.rc3 → 3.5.3

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