Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use basename when doing white and black list matching

  • Loading branch information...
commit 6b0f258964ec62047197d1b1852f9bd433b95da0 1 parent b47303d
Kjell-Magne Øierud authored
View
3  lib/plugman.rb
@@ -51,6 +51,7 @@ def initialize(finder_or_name)
@log = StringIO.new("")
@logger = Logger.new(@log)
Plugman::PluginBase.manager = self
+ @policy = Plugman::BlackWhitePolicy.new([], []) { |x| true }
end
def log
@@ -60,7 +61,7 @@ def log
# Looks for plugins, requires them, checks state, initializes, and
# registers the plugins
def load_plugins
- @finder.plugin_files.each do |f|
+ @policy.apply(@finder.plugin_files).each do |f|
require_plugin(f)
end
View
7 lib/plugman/black_white_policy.rb
@@ -10,12 +10,13 @@ def initialize(black_list, white_list, &unknown_handler)
def apply(plugin_files)
approved = []
plugin_files.each do |plugin|
- if @white.include?(plugin)
+ basename = File.basename(plugin)
+ if @white.include?(basename)
approved << plugin
next
end
- next if @black.include?(plugin)
- approved << plugin if @unknown_handler.call(plugin)
+ next if @black.include?(basename)
+ approved << plugin if @unknown_handler.call(basename)
end
approved
end
View
9 spec/plugman/black_white_policy_spec.rb
@@ -8,9 +8,16 @@
x << unknown
false
end
- policy.apply(%w(a b c d)).should == %w(a b)
+ plugin_files = %w(prefix/a prefix/b prefix/c prefix/d)
+ policy.apply(plugin_files).should == %w(prefix/a prefix/b)
x.should == %w(d)
end
+ it do
+ policy = Plugman::BlackWhitePolicy.new(%w(c), %w(a b)) { |x| true }
+ plugin_files = %w(prefix/a prefix/b prefix/c prefix/d)
+ policy.apply(plugin_files).should == %w(prefix/a prefix/b prefix/d)
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.