method
replace_bin_path
v2_6_3 -
Show latest stable
- Class:
Bundler::RubygemsIntegration
replace_bin_path(specs, specs_by_name)public
Used to make bin stubs that are not created by bundler work under bundler. The new Gem.bin_path only considers gems in specs
# File lib/bundler/rubygems_integration.rb, line 439
def replace_bin_path(specs, specs_by_name)
gem_class = (class << Gem; self; end)
redefine_method(gem_class, :find_spec_for_exe) do |gem_name, *args|
exec_name = args.first
spec_with_name = specs_by_name[gem_name]
spec = if exec_name
if spec_with_name && spec_with_name.executables.include?(exec_name)
spec_with_name
else
specs.find {|s| s.executables.include?(exec_name) }
end
else
spec_with_name
end
unless spec
message = "can't find executable #{exec_name} for gem #{gem_name}"
if !exec_name || spec_with_name.nil?
message += ". #{gem_name} is not currently included in the bundle, " "perhaps you meant to add it to your #{Bundler.default_gemfile.basename}?"
end
raise Gem::Exception, message
end
raise Gem::Exception, "no default executable for #{spec.full_name}" unless exec_name ||= spec.default_executable
unless spec.name == gem_name
Bundler::SharedHelpers.major_deprecation 2,
"Bundler is using a binstub that was created for a different gem (#{spec.name}).\n" "You should run `bundle binstub #{gem_name}` " "to work around a system/bundle conflict."
end
spec
end
redefine_method(gem_class, :activate_bin_path) do |name, *args|
exec_name = args.first
return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"
# Copy of Rubygems activate_bin_path impl
requirement = args.last
spec = find_spec_for_exe name, exec_name, [requirement]
gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
end
redefine_method(gem_class, :bin_path) do |name, *args|
exec_name = args.first
return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"
spec = find_spec_for_exe(name, *args)
exec_name ||= spec.default_executable
gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
end
end Related methods
- Instance methods
- backport_base_dir
- backport_cache_file
- backport_segment_generation
- backport_spec_file
- backport_yaml_initialize
- bin_path
- binstubs_call_gem?
- build
- build_args
- build_args=
- build_gem
- clear_paths
- config_map
- configuration
- download_gem
- ext_lock
- fetch_all_remote_specs
- fetch_prerelease_specs
- fetch_specs
- gem_bindir
- gem_cache
- gem_dir
- gem_from_path
- gem_path
- inflate
- install_with_build_args
- load_path_insert_index
- load_plugin_files
- load_plugins
- loaded_gem_paths
- loaded_specs
- mark_loaded
- marshal_spec_dir
- method_visibility
- path
- path_separator
- platforms
- post_reset_hooks
- preserve_paths
- provides?
- read_binary
- redefine_method
- replace_bin_path
- replace_entrypoints
- replace_gem
- replace_refresh
- repository_subdirectories
- reset
- reverse_rubygems_kernel_mixin
- ruby_engine
- security_policies
- security_policy_keys
- set_installed_by_version
- sources
- sources=
- spec_cache_dirs
- spec_default_gem?
- spec_extension_dir
- spec_from_gem
- spec_matches_for_glob
- spec_missing_extensions?
- stub_set_spec
- stub_source_index
- stubs_provide_full_functionality?
- suffix_pattern
- ui=
- undo_replacements
- user_home
- validate
- version
- with_build_args
- Class methods
- new
- provides?
- version