gem-ban 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/README.md +23 -0
- data/lib/rubygems/ban.rb +55 -0
- data/lib/rubygems/commands/ban_command.rb +58 -0
- data/lib/rubygems/install_ban_plugin.rb +17 -0
- data/lib/rubygems_plugin.rb +5 -0
- metadata +54 -0
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Barry Allard <barry@barryallard.name>
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# gem-ban : rubygems plugin
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
gem install gem-ban
|
6
|
+
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
gem ban nokogiri
|
11
|
+
|
12
|
+
gem unban nokogiri
|
13
|
+
|
14
|
+
gem listban
|
15
|
+
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
GPL v3
|
20
|
+
|
21
|
+
## Copyright
|
22
|
+
|
23
|
+
Copyright 2012 Barry Allard <barry@barryallard.name>
|
data/lib/rubygems/ban.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems/exceptions'
|
2
|
+
|
3
|
+
module Gem::Ban
|
4
|
+
VERSION = Version = '1.5.2'
|
5
|
+
|
6
|
+
def self.ban(gem)
|
7
|
+
raise Gem::Exception, "The gem #{gem} is already banned." if banned?(gem)
|
8
|
+
|
9
|
+
_contents[:banned] = if _contents[:banned].is_a?(String)
|
10
|
+
[_contents[:banned], gem.to_s].join(' ')
|
11
|
+
else
|
12
|
+
gem.to_s
|
13
|
+
end
|
14
|
+
write
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.unban(gem)
|
18
|
+
raise Gem::Exception, "There are no currently banned gems." unless banned
|
19
|
+
raise Gem::Exception, "The gem #{gem} is not currently banned." unless banned?(gem)
|
20
|
+
|
21
|
+
_contents[:banned].slice!(gem).strip!
|
22
|
+
_contents.delete(:banned) if _contents[:banned].empty?
|
23
|
+
write
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.banned?(gem)
|
27
|
+
banned.include?(gem)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.banned
|
31
|
+
_contents[:banned].is_a?(String) ? _contents[:banned].split(' ') : []
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def self._contents
|
36
|
+
if ! defined? @@contents
|
37
|
+
read
|
38
|
+
@@contents ||= {}
|
39
|
+
end
|
40
|
+
@@contents
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.filename
|
44
|
+
File.join(ENV['HOME'],'.gemrc')
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.read
|
48
|
+
require 'yaml'
|
49
|
+
@@contents=YAML.load(File.read(filename))
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.write
|
53
|
+
File.open(filename, 'w') { |f| f.write @@contents.to_yaml }
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems/ban'
|
2
|
+
|
3
|
+
class Gem::Commands::BanCommand < Gem::Command
|
4
|
+
def initialize
|
5
|
+
super 'ban', 'Specific gem installation prevention utility'
|
6
|
+
end
|
7
|
+
|
8
|
+
def arguments # :nodoc:
|
9
|
+
['SUBCOMMAND list, add or remove',
|
10
|
+
'GEMNAME(s) name of a gem to ban or unban'].join "\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def usage # :nodoc:
|
14
|
+
"#{program_name} SUBCOMMAND GEMNAME(S)"
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
cmd = options[:args].shift
|
19
|
+
|
20
|
+
if %w|list add remove|.include? cmd
|
21
|
+
return eval("#{cmd}")
|
22
|
+
end
|
23
|
+
|
24
|
+
if %w|help h usage --usage --help -h -?|.include? cmd
|
25
|
+
show_help
|
26
|
+
abort
|
27
|
+
end
|
28
|
+
|
29
|
+
alert_error "Unknown ban subcommand: #{cmd}"
|
30
|
+
show_help
|
31
|
+
abort
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def list
|
36
|
+
unless (_banned = Gem::Ban::banned.join(' ')).empty?
|
37
|
+
puts "Banned gems: #{_banned}"
|
38
|
+
else
|
39
|
+
puts 'Banned gems: (none)'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def add
|
44
|
+
until (gem = options[:args].shift).nil?
|
45
|
+
raise Gem::CommandLineError, "Please specify a gem name to ban on the command line" unless gem
|
46
|
+
Gem::Ban::ban(gem)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove
|
51
|
+
until (gem = options[:args].shift).nil?
|
52
|
+
raise Gem::CommandLineError, "Please specify a gem name to unban on the command line" unless gem
|
53
|
+
Gem::Ban::unban(gem)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems/exceptions'
|
2
|
+
require 'rubygems/installer'
|
3
|
+
require 'rubygems/ban'
|
4
|
+
|
5
|
+
# hack
|
6
|
+
class Gem::Installer
|
7
|
+
alias :old_ensure_dependency :ensure_dependency
|
8
|
+
|
9
|
+
# can be overridden using --force
|
10
|
+
def ensure_dependency(spec, dependency)
|
11
|
+
unless @force
|
12
|
+
gem_name = dependency.name.split('gem')[1]
|
13
|
+
raise Gem::InstallError, "#{spec.name} attempted installation of banned gem #{gem_name}" if Gem::Ban.banned?(gem_name)
|
14
|
+
end
|
15
|
+
old_ensure_dependency(spec, dependency)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-ban
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Barry Allard
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Different places have different requirements, this aims to help ease
|
15
|
+
concerns
|
16
|
+
email: barry@barryallard.name
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- AUTHORS
|
22
|
+
files:
|
23
|
+
- lib/rubygems/ban.rb
|
24
|
+
- lib/rubygems/commands/ban_command.rb
|
25
|
+
- lib/rubygems/install_ban_plugin.rb
|
26
|
+
- lib/rubygems_plugin.rb
|
27
|
+
- README.md
|
28
|
+
- AUTHORS
|
29
|
+
homepage: http://github.com/steakknife/gem-ban
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.17
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: gem-ban, prevent certain gems from installation
|
53
|
+
test_files: []
|
54
|
+
has_rdoc: false
|