Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbuddy committed Mar 28, 2012
0 parents commit 9674eaf
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "http://rubygems.org"

# Specify your gem's dependencies in noexec.gemspec
gemspec

gem 'rake'
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Noexec

Let's stop using bundle exec, kthx.

## Installation

gem install noexec

Then, in your .profile (or somewhere you can set env variables)

RUBYOPT="-r`noexec`"

And you're done!

## How does this work?

It adds a script to every execution of ruby via the RUBYOPT environment variable. Then, when you run ruby, it takes a look at your working directory, and every directory above it until it can find a `Gemfile`. If the executable you're running is present in your Gemfile, it switches to using that `Gemfile` instead (via `Bundle.setup`).
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
3 changes: 3 additions & 0 deletions bin/noexec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby

print File.expand_path(File.expand_path("../../lib/noexec/auto.rb", __FILE__))
54 changes: 54 additions & 0 deletions lib/noexec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
begin
require "bundler"

module Bundler
class << self
def reset!
@load = nil
end
end
end

module Noexec
CURRENT = Dir.pwd
DEBUG = ENV.key?('NOEXEC_DEBUG')

extend self

def candidate?(gemfile, bin)
ENV['BUNDLE_GEMFILE'] = gemfile
Bundler.load.specs.each do |spec|
next if spec.name == 'bundler'
return spec if spec.executables.include?(bin)
end
nil
ensure
Bundler.reset!
end

def setup
puts "Noexec" if DEBUG
catch(:done) do
throw :done, false if File.basename($0) == 'bundle'
gemfile = File.join(CURRENT, "Gemfile")
while true
if File.exist?(gemfile)
puts "Examining #{gemfile}" if DEBUG
if Noexec.candidate?(gemfile, File.basename($0))
puts "Using #{gemfile}" if DEBUG
Bundler.setup
throw :done, true
end
end
new_gemfile = File.expand_path("../../Gemfile", gemfile)
throw :done, false if new_gemfile == gemfile
gemfile = new_gemfile
end
puts "No valid Gemfile found, moving on" if DEBUG
false
end
end
end
rescue LoadError
warn "bundler not being used, unable to load"
end
3 changes: 3 additions & 0 deletions lib/noexec/auto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require File.expand_path('../../noexec', __FILE__)

Noexec.setup
3 changes: 3 additions & 0 deletions lib/noexec/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Noexec
VERSION = "0.0.1"
end
20 changes: 20 additions & 0 deletions noexec.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "noexec/version"

Gem::Specification.new do |s|
s.name = "noexec"
s.version = Noexec::VERSION
s.authors = ["Josh Hull"]
s.email = ["joshbuddy@gmail.com"]
s.homepage = "https://github.com/joshbuddy/noexec"
s.summary = %q{Stop using bundle exec}
s.description = %q{Stop using bundle exec.}

s.rubyforge_project = "noexec"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end

0 comments on commit 9674eaf

Please sign in to comment.