Skip to content

Commit 2395751

Browse files
Refactor validate_package_gem_compatibility! to fix RuboCop metrics
Extract validation logic into separate private methods to satisfy: - Metrics/AbcSize - Metrics/CyclomaticComplexity - Metrics/MethodLength Changes: - Split validate_package_gem_compatibility! into 4 focused validation methods: - validate_packages_installed! - Ensures at least one package is installed - validate_no_duplicate_packages! - Prevents both packages being installed - validate_pro_gem_uses_pro_package! - Enforces Pro gem uses Pro package - validate_pro_package_has_pro_gem! - Enforces Pro package requires Pro gem - Remove rubocop:disable and rubocop:enable comments - Maintain same functionality and test coverage (54 specs pass) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9a0523d commit 2395751

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

lib/react_on_rails/version_checker.rb

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -57,71 +57,79 @@ def validate_package_json_exists!
5757
MSG
5858
end
5959

60-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
6160
def validate_package_gem_compatibility!
6261
has_base_package = node_package_version.react_on_rails_package?
6362
has_pro_package = node_package_version.react_on_rails_pro_package?
6463
is_pro_gem = ReactOnRails::Utils.react_on_rails_pro?
6564

66-
# Error: No packages installed
67-
if !has_base_package && !has_pro_package
68-
base_install_cmd = ReactOnRails::Utils.package_manager_install_exact_command("react-on-rails", gem_version)
69-
pro_install_cmd = ReactOnRails::Utils.package_manager_install_exact_command("react-on-rails-pro", gem_version)
65+
validate_packages_installed!(has_base_package, has_pro_package)
66+
validate_no_duplicate_packages!(has_base_package, has_pro_package)
67+
validate_pro_gem_uses_pro_package!(is_pro_gem, has_pro_package)
68+
validate_pro_package_has_pro_gem!(is_pro_gem, has_pro_package)
69+
end
7070

71-
raise ReactOnRails::Error, <<~MSG.strip
72-
**ERROR** ReactOnRails: No React on Rails npm package is installed.
71+
def validate_packages_installed!(has_base_package, has_pro_package)
72+
return if has_base_package || has_pro_package
7373

74-
You must install either 'react-on-rails' or 'react-on-rails-pro' package.
74+
base_install_cmd = ReactOnRails::Utils.package_manager_install_exact_command("react-on-rails", gem_version)
75+
pro_install_cmd = ReactOnRails::Utils.package_manager_install_exact_command("react-on-rails-pro", gem_version)
7576

76-
Fix:
77-
If using the standard (free) version:
78-
Run: #{base_install_cmd}
77+
raise ReactOnRails::Error, <<~MSG.strip
78+
**ERROR** ReactOnRails: No React on Rails npm package is installed.
7979
80-
Or if using React on Rails Pro:
81-
Run: #{pro_install_cmd}
80+
You must install either 'react-on-rails' or 'react-on-rails-pro' package.
8281
83-
#{package_json_location}
84-
MSG
85-
end
82+
Fix:
83+
If using the standard (free) version:
84+
Run: #{base_install_cmd}
8685
87-
# Error: Both packages installed
88-
if has_base_package && has_pro_package
89-
remove_cmd = ReactOnRails::Utils.package_manager_remove_command("react-on-rails")
86+
Or if using React on Rails Pro:
87+
Run: #{pro_install_cmd}
9088
91-
raise ReactOnRails::Error, <<~MSG.strip
92-
**ERROR** ReactOnRails: Both 'react-on-rails' and 'react-on-rails-pro' packages are installed.
89+
#{package_json_location}
90+
MSG
91+
end
9392

94-
If you're using React on Rails Pro, only install the 'react-on-rails-pro' package.
95-
The Pro package already includes all functionality from the base package.
93+
def validate_no_duplicate_packages!(has_base_package, has_pro_package)
94+
return unless has_base_package && has_pro_package
9695

97-
Fix:
98-
1. Remove 'react-on-rails' from your package.json dependencies
99-
2. Run: #{remove_cmd}
100-
3. Keep only: react-on-rails-pro
96+
remove_cmd = ReactOnRails::Utils.package_manager_remove_command("react-on-rails")
10197

102-
#{package_json_location}
103-
MSG
104-
end
98+
raise ReactOnRails::Error, <<~MSG.strip
99+
**ERROR** ReactOnRails: Both 'react-on-rails' and 'react-on-rails-pro' packages are installed.
105100
106-
# Error: Pro gem but using base package
107-
if is_pro_gem && !has_pro_package
108-
remove_cmd = ReactOnRails::Utils.package_manager_remove_command("react-on-rails")
109-
install_cmd = ReactOnRails::Utils.package_manager_install_exact_command("react-on-rails-pro", gem_version)
101+
If you're using React on Rails Pro, only install the 'react-on-rails-pro' package.
102+
The Pro package already includes all functionality from the base package.
110103
111-
raise ReactOnRails::Error, <<~MSG.strip
112-
**ERROR** ReactOnRails: You have the Pro gem installed but are using the base 'react-on-rails' package.
104+
Fix:
105+
1. Remove 'react-on-rails' from your package.json dependencies
106+
2. Run: #{remove_cmd}
107+
3. Keep only: react-on-rails-pro
113108
114-
When using React on Rails Pro, you must use the 'react-on-rails-pro' npm package.
109+
#{package_json_location}
110+
MSG
111+
end
115112

116-
Fix:
117-
1. Remove the base package: #{remove_cmd}
118-
2. Install the Pro package: #{install_cmd}
113+
def validate_pro_gem_uses_pro_package!(is_pro_gem, has_pro_package)
114+
return unless is_pro_gem && !has_pro_package
119115

120-
#{package_json_location}
121-
MSG
122-
end
116+
remove_cmd = ReactOnRails::Utils.package_manager_remove_command("react-on-rails")
117+
install_cmd = ReactOnRails::Utils.package_manager_install_exact_command("react-on-rails-pro", gem_version)
118+
119+
raise ReactOnRails::Error, <<~MSG.strip
120+
**ERROR** ReactOnRails: You have the Pro gem installed but are using the base 'react-on-rails' package.
121+
122+
When using React on Rails Pro, you must use the 'react-on-rails-pro' npm package.
123+
124+
Fix:
125+
1. Remove the base package: #{remove_cmd}
126+
2. Install the Pro package: #{install_cmd}
127+
128+
#{package_json_location}
129+
MSG
130+
end
123131

124-
# Error: Pro package but not Pro gem
132+
def validate_pro_package_has_pro_gem!(is_pro_gem, has_pro_package)
125133
return unless !is_pro_gem && has_pro_package
126134

127135
remove_pro_cmd = ReactOnRails::Utils.package_manager_remove_command("react-on-rails-pro")
@@ -144,7 +152,6 @@ def validate_package_gem_compatibility!
144152
#{package_json_location}
145153
MSG
146154
end
147-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
148155

149156
def validate_exact_version!
150157
return if node_package_version.raw.nil? || node_package_version.local_path_or_url?

0 commit comments

Comments
 (0)