Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ vendor/
tmp/

# Claude
.claude/Claude.local.md
.claude/Claude.local*.md
29 changes: 29 additions & 0 deletions lib/methodray/binary_locator.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 3 additions & 20 deletions lib/methodray/commands.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.'
Expand All @@ -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