Permalink
Browse files

Using the Gem module to find plugins

  • Loading branch information...
1 parent 73f0515 commit 5a0017aa08d14b8ffa00234eeb9e02961d3f0bf9 @winton committed Nov 16, 2009
Showing with 25 additions and 24 deletions.
  1. +1 −1 gemspec.rb
  2. +22 −21 lib/auto/plugins.rb
  3. +1 −1 spec/auto/plugins_spec.rb
  4. +1 −1 spec/auto/runner_spec.rb
View
@@ -15,5 +15,5 @@
s.name = GEM_NAME
s.platform = Gem::Platform::RUBY
s.require_path = "lib"
- s.version = "0.1.3"
+ s.version = "0.1.4"
end
View
@@ -1,49 +1,52 @@
module Auto
class Plugins
- @@directories = [ "#{Gem.dir}/gems" ]
+ @@plugin_paths = []
@@plugins = nil
cattr_accessor :directories
class <<self
- # Add a plugin base directory
+ # Add a plugin directory
def add(path)
- Runner.require! Plugin.new(path)
+ @@plugin_paths << path
+ @@plugins = nil
end
- # Add a directory to the plugin load paths.
- def add_directory(path)
- @@directories = [] if $testing
- @@directories << path
- @@directories.uniq!
- @@plugins = nil
+ # Add a repository of plugins
+ def add_repository(path)
+ Dir["#{path}/auto-*"].each do |plugin|
+ Plugins.add plugin
+ end
end
# Returns an array of Plugin instances.
def plugins
return @@plugins if @@plugins
- directories = @@directories.collect do |d|
- File.expand_path("#{d}/*auto-*/")
+ unless $testing
+ specs = Gem.source_index.latest_specs.select do |spec|
+ spec.name =~ /^auto-.+/
+ end
+ @@plugin_paths += specs.collect &:full_gem_path
+ # Treat the home directory like a plugin for the .auto directory
+ @@plugin_paths << File.expand_path('~')
+ @@plugin_paths.compact!
end
- # Treat the home directory like a plugin for the .auto directory
- directories << File.expand_path('~') unless $testing
- @@plugins = Dir[*directories].collect do |d|
+ @@plugins = Dir[*@@plugin_paths].collect do |d|
Plugin.new(d)
end
- @@plugins.compact!
- @@plugins
+ @@plugins || []
end
# Returns an array of library file paths.
def libraries
- collector { |plugin| plugin.library }
+ collector &:library
end
# Returns an array of modules.
def modules
- collector { |plugin| plugin.module }
+ collector &:module
end
# Returns a sorted array of hashes that describe tasks.
@@ -52,9 +55,7 @@ def tasks(task=nil)
if task
tasks.select { |t| t[:name] == task.downcase }.first
else
- t = collector { |plugin| plugin.tasks }
- t = t.flatten
- t.sort do |a, b|
+ collector(&:tasks).flatten.sort do |a, b|
a[:name].gsub(':', '0') <=> b[:name].gsub(':', '0')
end
end
@@ -4,7 +4,7 @@ module Auto
describe Auto::Plugins do
before(:all) do
- Plugins.add_directory @fixtures = "#{SPEC}/plugins"
+ Plugins.add_repository @fixtures = "#{SPEC}/plugins"
@libraries = Plugins.libraries
@modules = Plugins.modules
@tasks = Plugins.tasks
View
@@ -4,7 +4,7 @@ module Auto
describe Auto::Runner do
before(:all) do
- Plugins.add_directory @fixtures = "#{SPEC}/plugins"
+ Plugins.add_repository @fixtures = "#{SPEC}/plugins"
@runner = Runner.new
end

0 comments on commit 5a0017a

Please sign in to comment.