Skip to content

Commit a43f052

Browse files
justin808claude
andcommitted
refactor: Extract bin/dev comparison into separate method
Improve code organization by extracting the bin/dev default comparison logic into a dedicated method. This makes the code more maintainable and adds clearer documentation about why we use a hardcoded default (Rails doesn't provide a bin/dev template). The shakapacker.yml comparison already correctly fetches and compares against the actual installer template from the Shakapacker gem. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5e31d06 commit a43f052

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/generators/react_on_rails/install_generator.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ def remove_default_bin_dev
7777
return unless File.exist?(bin_dev_path)
7878
return unless File.writable?(bin_dev_path)
7979

80-
# Rails 7+ default bin/dev content
81-
# If Rails changes this default, this comparison will safely fail and preserve the file
82-
default_bin_dev = <<~RUBY.strip
83-
#!/usr/bin/env ruby
84-
exec "./bin/rails", "server", *ARGV
85-
RUBY
86-
8780
current_content = File.read(bin_dev_path).strip
88-
return unless current_content == default_bin_dev
81+
return unless bin_dev_matches_rails_default?(current_content)
8982

9083
puts Rainbow("🗑️ Removing default bin/dev file to avoid conflicts...").yellow
9184
FileUtils.rm_f(bin_dev_path)
9285
end
9386

87+
def bin_dev_matches_rails_default?(content)
88+
# Rails 7+ simple bin/dev content
89+
# Note: Rails doesn't have a bin/dev template in its generators, but this is the
90+
# common simple default that many Rails apps use. We check against this known
91+
# default to avoid conflicts during installation.
92+
rails_simple_default = <<~RUBY.strip
93+
#!/usr/bin/env ruby
94+
exec "./bin/rails", "server", *ARGV
95+
RUBY
96+
97+
content == rails_simple_default
98+
end
99+
94100
def remove_default_shakapacker_yml
95101
config_path = File.join(destination_root, "config/shakapacker.yml")
96102
return unless File.exist?(config_path)

0 commit comments

Comments
 (0)