diff --git a/.gitignore b/.gitignore index 35acbf9..5982728 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ vendor/ tmp/ # Claude -.claude/Claude.local.md +.claude/Claude.local*.md diff --git a/lib/methodray/binary_locator.rb b/lib/methodray/binary_locator.rb new file mode 100644 index 0000000..b4c3650 --- /dev/null +++ b/lib/methodray/binary_locator.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module MethodRay + class BinaryLocator + LIB_DIR = __dir__ + + def initialize + @binary_name = Gem.win_platform? ? 'methodray-cli.exe' : 'methodray-cli' + @legacy_binary_name = Gem.win_platform? ? 'methodray.exe' : 'methodray' + end + + def find + candidates.find { |path| File.executable?(path) } + end + + private + + def candidates + [ + # CLI binary built during gem install (lib/methodray directory) + File.expand_path(@binary_name, LIB_DIR), + # Development: target/release (project root) + File.expand_path("../../target/release/#{@binary_name}", LIB_DIR), + # Development: rust/target/release (legacy standalone binary) + File.expand_path("../../rust/target/release/#{@legacy_binary_name}", LIB_DIR) + ] + end + end +end diff --git a/lib/methodray/commands.rb b/lib/methodray/commands.rb index 260ed86..5a5cd02 100644 --- a/lib/methodray/commands.rb +++ b/lib/methodray/commands.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true +require_relative 'binary_locator' + module MethodRay module Commands - COMMANDS_DIR = __dir__ - class << self def help puts <<~HELP @@ -41,7 +41,7 @@ def clear_cache(args) private def exec_rust_cli(command, args) - binary_path = find_rust_binary + binary_path = BinaryLocator.new.find unless binary_path warn 'Error: CLI binary not found.' @@ -56,23 +56,6 @@ def exec_rust_cli(command, args) exec(binary_path, command, *args) end - - def find_rust_binary - # Platform-specific binary name - cli_binary = Gem.win_platform? ? 'methodray-cli.exe' : 'methodray-cli' - legacy_binary = Gem.win_platform? ? 'methodray.exe' : 'methodray' - - candidates = [ - # CLI binary built during gem install (lib/methodray directory) - File.expand_path(cli_binary, COMMANDS_DIR), - # Development: target/release (project root) - File.expand_path("../../target/release/#{cli_binary}", COMMANDS_DIR), - # Development: rust/target/release (legacy standalone binary) - File.expand_path("../../rust/target/release/#{legacy_binary}", COMMANDS_DIR) - ] - - candidates.find { |path| File.executable?(path) } - end end end end