def candidate?
log "Examining #{gemfile}"
config_file = File.expand_path('../.noexec.yaml', gemfile)
if File.exist?(config_file)
log "Using config file at #{config_file}"
require "yaml"
config = YAML::load_file(config_file)
unless config['include'].nil? ^ config['exclude'].nil?
raise "You cannot have both an include and exclude section in your #{config_file.inspect}"
end
if config['include'] && config['include'].include?(bin)
log "Binary included by config"
return true
elsif config['exclude'] && config['exclude'].include?(bin)
log "Binary excluded by config"
return false
end
log "Config based matching didn't find it, resorting to Gemfile lookup"
end
runtime = Bundler.load
log2(){ "runtime specs: #{runtime.specs.map{|g| "#{g.name}-#{g.version}"}*" "}" }
if rubygems_spec
missing_spec = runtime.
instance_variable_get(:@definition).
missing_specs.
detect{|spec| spec.name == rubygems_spec.name}
if missing_spec
puts "\e[31mCould not find proper version of #{missing_spec.to_s} in any of the sources\e[0m"
puts "\e[33mRun `bundle install` to install missing gems.\e[0m"
exit Bundler::GemNotFound.new.status_code
end
end
if runtime.specs.detect{ |spec| spec.executables.include?(bin) }
return true
end
Bundler.unload!(rubygems_specs)
false
rescue Bundler::BundlerError, Bundler::GemfileError => e
warn "Ignoring candidate #{gemfile}:\n#{e}" if Noexec::DEBUG
false
end