Class: Auto::Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/auto/plugins.rb

Defined Under Namespace

Classes: Plugin

Constant Summary collapse

@@plugin_paths =
[]
@@plugins =
nil

Class Method Summary collapse

Class Method Details

.add(path) ⇒ Object

Add a plugin directory



12
13
14
15
# File 'lib/auto/plugins.rb', line 12

def add(path)
  @@plugin_paths << path
  @@plugins = nil
end

.add_repository(path) ⇒ Object

Add a repository of plugins



18
19
20
21
22
# File 'lib/auto/plugins.rb', line 18

def add_repository(path)
  Dir["#{path}/auto-*"].each do |plugin|
    Plugins.add plugin
  end
end

.librariesObject

Returns an array of library file paths.



43
44
45
# File 'lib/auto/plugins.rb', line 43

def libraries
  collector &:library
end

.modulesObject

Returns an array of modules.



48
49
50
# File 'lib/auto/plugins.rb', line 48

def modules
  collector &:module
end

.pluginsObject

Returns an array of Plugin instances.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/auto/plugins.rb', line 25

def plugins
  return @@plugins if @@plugins
  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
  @@plugins = Dir[*@@plugin_paths].collect do |d|
    Plugin.new(d)
  end
  @@plugins || []
end

.tasks(task = nil) ⇒ Object

Returns a sorted array of hashes that describe tasks. Returns a specific task with an optional task parameter (string, ‘task:name’).



54
55
56
57
58
59
60
61
62
# File 'lib/auto/plugins.rb', line 54

def tasks(task=nil)
  if task
    tasks.select { |t| t[:name] == task.downcase }.first
  else
    collector(&:tasks).flatten.sort do |a, b|
      a[:name].gsub(':', '0') <=> b[:name].gsub(':', '0')
    end
  end
end