Skip to content

Commit 89ac6eb

Browse files
justin808claude
andcommitted
Simplify dynamic Shakapacker constant resolution
Replace legacy Object.const_get pattern with direct Shakapacker references since packer_type only returns "shakapacker" now. Changes: - Replace Object.const_get(ReactOnRails::PackerUtils.packer_type.capitalize) with Shakapacker - Update Manifest::MissingEntryError references - Update DevServer references in tests - Simplify test helper constant assignment This removes unnecessary dynamic constant resolution that was needed when both Webpacker and Shakapacker were supported. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 077a610 commit 89ac6eb

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

lib/react_on_rails/utils.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ def self.bundle_js_file_path(bundle_name)
8181
if ReactOnRails::PackerUtils.using_packer? && bundle_name != "manifest.json"
8282
begin
8383
ReactOnRails::PackerUtils.bundle_js_uri_from_packer(bundle_name)
84-
rescue Object.const_get(
85-
ReactOnRails::PackerUtils.packer_type.capitalize
86-
)::Manifest::MissingEntryError
84+
rescue Shakapacker::Manifest::MissingEntryError
8785
# When manifest lookup fails, try multiple fallback locations:
8886
# 1. Environment-specific path (e.g., public/webpack/test)
8987
# 2. Standard Shakapacker location (public/packs)

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "rails_helper"
44
require "support/script_tag_utils"
55

6-
Packer = Object.const_get(ReactOnRails::PackerUtils.packer_type.capitalize)
6+
Packer = Shakapacker
77

88
class PlainReactOnRailsHelper
99
include ReactOnRailsHelper

spec/react_on_rails/utils_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module ReactOnRails
5050
end
5151

5252
def mock_bundle_in_manifest(bundle_name, hashed_bundle)
53-
mock_manifest = instance_double(Object.const_get(ReactOnRails::PackerUtils.packer_type.capitalize)::Manifest)
53+
mock_manifest = instance_double(Shakapacker::Manifest)
5454
allow(mock_manifest).to receive(:lookup!)
5555
.with(bundle_name)
5656
.and_return(hashed_bundle)
@@ -61,9 +61,7 @@ def mock_bundle_in_manifest(bundle_name, hashed_bundle)
6161
def mock_missing_manifest_entry(bundle_name)
6262
allow(ReactOnRails::PackerUtils.packer).to receive_message_chain("manifest.lookup!")
6363
.with(bundle_name)
64-
.and_raise(Object.const_get(
65-
ReactOnRails::PackerUtils.packer_type.capitalize
66-
)::Manifest::MissingEntryError)
64+
.and_raise(Shakapacker::Manifest::MissingEntryError)
6765
end
6866

6967
def random_bundle_name
@@ -577,7 +575,7 @@ def mock_dev_server_running
577575
before do
578576
allow(ReactOnRails::PackerUtils.packer).to receive(:dev_server).and_return(
579577
instance_double(
580-
Object.const_get(ReactOnRails::PackerUtils.packer_type.capitalize)::DevServer,
578+
Shakapacker::DevServer,
581579
running?: true,
582580
protocol: "http",
583581
host_with_port: "localhost:3035"

0 commit comments

Comments
 (0)