auto 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/gemspec.rb CHANGED
@@ -15,5 +15,5 @@ GEM_SPEC = Gem::Specification.new do |s|
15
15
  s.name = GEM_NAME
16
16
  s.platform = Gem::Platform::RUBY
17
17
  s.require_path = "lib"
18
- s.version = "0.1.3"
18
+ s.version = "0.1.4"
19
19
  end
@@ -1,53 +1,52 @@
1
- require 'rubygems'
2
-
3
1
  module Auto
4
2
  class Plugins
5
3
 
6
- @@directories = [
7
- Gem.dir + "/gems",
8
- "~/.auto",
9
- "#{File.dirname(__FILE__)}/../../vendor/plugins"
10
- ]
4
+ @@plugin_paths = []
11
5
  @@plugins = nil
12
6
 
13
7
  cattr_accessor :directories
14
8
 
15
9
  class <<self
16
10
 
17
- # Add a plugin base directory
11
+ # Add a plugin directory
18
12
  def add(path)
19
- Runner.require! Plugin.new(path)
13
+ @@plugin_paths << path
14
+ @@plugins = nil
20
15
  end
21
16
 
22
- # Add a directory to the plugin load paths.
23
- def add_directory(path)
24
- @@directories = [] if $testing
25
- @@directories << path
26
- @@directories.uniq!
27
- @@plugins = nil
17
+ # Add a repository of plugins
18
+ def add_repository(path)
19
+ Dir["#{path}/auto-*"].each do |plugin|
20
+ Plugins.add plugin
21
+ end
28
22
  end
29
23
 
30
24
  # Returns an array of Plugin instances.
31
25
  def plugins
32
26
  return @@plugins if @@plugins
33
- directories = @@directories.collect do |d|
34
- File.expand_path("#{d}/*auto-*/")
27
+ unless $testing
28
+ specs = Gem.source_index.latest_specs.select do |spec|
29
+ spec.name =~ /^auto-.+/
30
+ end
31
+ @@plugin_paths += specs.collect &:full_gem_path
32
+ # Treat the home directory like a plugin for the .auto directory
33
+ @@plugin_paths << File.expand_path('~')
34
+ @@plugin_paths.compact!
35
35
  end
36
- @@plugins = Dir[*directories].collect do |d|
36
+ @@plugins = Dir[*@@plugin_paths].collect do |d|
37
37
  Plugin.new(d)
38
38
  end
39
- @@plugins.compact!
40
- @@plugins
39
+ @@plugins || []
41
40
  end
42
41
 
43
42
  # Returns an array of library file paths.
44
43
  def libraries
45
- collector { |plugin| plugin.library }
44
+ collector &:library
46
45
  end
47
46
 
48
47
  # Returns an array of modules.
49
48
  def modules
50
- collector { |plugin| plugin.module }
49
+ collector &:module
51
50
  end
52
51
 
53
52
  # Returns a sorted array of hashes that describe tasks.
@@ -56,9 +55,7 @@ module Auto
56
55
  if task
57
56
  tasks.select { |t| t[:name] == task.downcase }.first
58
57
  else
59
- t = collector { |plugin| plugin.tasks }
60
- t = t.flatten
61
- t.sort do |a, b|
58
+ collector(&:tasks).flatten.sort do |a, b|
62
59
  a[:name].gsub(':', '0') <=> b[:name].gsub(':', '0')
63
60
  end
64
61
  end
@@ -85,8 +82,11 @@ module Auto
85
82
  name = File.basename(directory)
86
83
  name = name.split('-')
87
84
 
88
- return nil unless name.include?('auto')
89
- @name = name[name.index('auto') + 1]
85
+ if name.include?('auto')
86
+ @name = name[name.index('auto') + 1]
87
+ else
88
+ @name = nil
89
+ end
90
90
 
91
91
  # ~/.auto/auto-plugin/lib/plugin.rb
92
92
  @library = "#{directory}/lib/auto/#{@name}.rb"
@@ -99,7 +99,7 @@ module Auto
99
99
  @module = nil
100
100
  end
101
101
 
102
- # ~/.auto/auto-plugin/auto/task.rb
102
+ # ~/.auto/auto-plugin/.auto/task.rb
103
103
  @tasks = Dir["#{directory}/.auto/**/*.rb"].sort.collect do |path|
104
104
  relative = path.gsub("#{directory}/.auto/", '')
105
105
  {
@@ -4,7 +4,7 @@ module Auto
4
4
  describe Auto::Plugins do
5
5
 
6
6
  before(:all) do
7
- Plugins.add_directory @fixtures = "#{SPEC}/plugins"
7
+ Plugins.add_repository @fixtures = "#{SPEC}/plugins"
8
8
  @libraries = Plugins.libraries
9
9
  @modules = Plugins.modules
10
10
  @tasks = Plugins.tasks
@@ -4,7 +4,7 @@ module Auto
4
4
  describe Auto::Runner do
5
5
 
6
6
  before(:all) do
7
- Plugins.add_directory @fixtures = "#{SPEC}/plugins"
7
+ Plugins.add_repository @fixtures = "#{SPEC}/plugins"
8
8
  @runner = Runner.new
9
9
  end
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-15 00:00:00 -08:00
12
+ date: 2009-11-16 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency