Class: RubynCode::CLI::Setup
- Inherits:
-
Object
- Object
- RubynCode::CLI::Setup
- Defined in:
- lib/rubyn_code/cli/setup.rb
Overview
Installs a pinned launcher that bypasses rbenv/rvm version switching.
When rubyn-code is installed as a gem, RubyGems generates a wrapper in the Ruby version’s bin dir (e.g. ~/.rbenv/versions/3.4.5/bin/rubyn-code) with a shebang pointing to the correct Ruby. However, rbenv’s shim at ~/.rbenv/shims/rubyn-code intercepts the command and re-resolves Ruby based on .ruby-version in the current directory — which breaks rubyn-code when you cd into a project using a different Ruby.
This setup creates a launcher in ~/.local/bin (which typically appears before ~/.rbenv/shims in PATH) that calls the gem wrapper directly, bypassing the shim entirely.
Constant Summary collapse
- INSTALL_DIR =
File.('~/.local/bin')
- LAUNCHER_NAME =
'rubyn-code'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.run ⇒ Object
23 24 25 |
# File 'lib/rubyn_code/cli/setup.rb', line 23 def self.run new.run end |
Instance Method Details
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubyn_code/cli/setup.rb', line 27 def run gem_wrapper = find_gem_wrapper unless gem_wrapper warn 'Error: Could not find the rubyn-code gem wrapper.' warn 'Make sure rubyn-code is installed: gem install rubyn-code' exit 1 end pinned_ruby = extract_ruby_from_wrapper(gem_wrapper) unless pinned_ruby warn "Error: Could not determine Ruby path from #{gem_wrapper}" exit 1 end launcher_path = File.join(INSTALL_DIR, LAUNCHER_NAME) FileUtils.mkdir_p(INSTALL_DIR) write_launcher(launcher_path, gem_wrapper, pinned_ruby) File.chmod(0o755, launcher_path) puts "Installed pinned launcher to #{launcher_path}" puts " Ruby: #{pinned_ruby}" puts " Wrapper: #{gem_wrapper}" puts verify_path(launcher_path) end |