noexec 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,6 +12,18 @@ Then, in your .profile (or somewhere you can set env variables)
12
12
 
13
13
  And you're done!
14
14
 
15
+ ## Configuration
16
+
17
+ Though you can let noexec do it's own thing and rely on looking up your binary via your Gemfile, you can also specify which binaries you want included or excluded. Create a .noexec.yaml file along side any Gemfiles you want to use. Then, to enable (or disable) the usage of your particular binary into your bundle, add an include or exclude section. For example:
18
+
19
+ ### .noexec.yaml
20
+
21
+ exclude: [rake]
22
+
23
+ Or,
24
+
25
+ include: [irb, ruby]
26
+
15
27
  ## How does this work?
16
28
 
17
29
  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`).
@@ -17,27 +17,46 @@ begin
17
17
 
18
18
  extend self
19
19
 
20
+ def log(msg)
21
+ puts msg if DEBUG
22
+ end
23
+
20
24
  def candidate?(gemfile, bin)
25
+ config_file = File.expand_path('../.noexec.yaml', gemfile)
26
+ log "Considering #{config_file.inspect}"
27
+ if File.exist?(config_file)
28
+ log "Using config file at #{config_file}"
29
+ config = YAML::load_file(config_file)
30
+ raise "You cannot have both an include and exclude section in your #{config_file.inspect}" unless config['include'].nil? ^ config['exclude'].nil?
31
+ if config['include'] && config['include'].include?(bin)
32
+ log "Binary included by config"
33
+ return true
34
+ elsif config['exclude'] && config['exclude'].include?(bin)
35
+ log "Binary excluded by config"
36
+ return false
37
+ end
38
+ log "Config based matching didn't find it, resorting to Gemfile lookup"
39
+ end
21
40
  ENV['BUNDLE_GEMFILE'] = gemfile
22
41
  Bundler.load.specs.each do |spec|
23
42
  next if spec.name == 'bundler'
24
- return spec if %w(ruby irb).include?(bin) || spec.executables.include?(bin)
43
+ return true if %w(ruby irb).include?(bin) || spec.executables.include?(bin)
25
44
  end
26
- nil
45
+ false
27
46
  ensure
28
47
  Bundler.reset!
29
48
  end
30
49
 
31
50
  def setup
32
- puts "Noexec" if DEBUG
51
+ log "Noexec"
33
52
  return if File.basename($0) == 'bundle'
34
53
  return if ENV['BUNDLE_GEMFILE']
35
54
  gemfile = File.join(CURRENT, "Gemfile")
36
55
  while true
37
56
  if File.exist?(gemfile)
38
- puts "Examining #{gemfile}" if DEBUG
57
+ log "Examining #{gemfile}"
39
58
  if Noexec.candidate?(gemfile, File.basename($0))
40
- puts "Using #{gemfile}" if DEBUG
59
+ log "Using #{gemfile}"
41
60
  ENV['BUNDLE_GEMFILE'] = gemfile
42
61
  Bundler.setup
43
62
  return
@@ -47,7 +66,7 @@ begin
47
66
  break if new_gemfile == gemfile
48
67
  gemfile = new_gemfile
49
68
  end
50
- puts "No valid Gemfile found, moving on" if DEBUG
69
+ log "No valid Gemfile found, moving on"
51
70
  end
52
71
  end
53
72
 
@@ -1,3 +1,3 @@
1
1
  module Noexec
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noexec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -41,7 +41,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  segments:
43
43
  - 0
44
- hash: 3029085704595461036
44
+ hash: -2223861668915785317
45
45
  required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  none: false
47
47
  requirements:
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  segments:
52
52
  - 0
53
- hash: 3029085704595461036
53
+ hash: -2223861668915785317
54
54
  requirements: []
55
55
  rubyforge_project: noexec
56
56
  rubygems_version: 1.8.15