Class: Pangrid::Plugin
Constant Summary
collapse
- REGISTRY =
{}
- FAILED =
[]
- MISSING_DEPS =
{}
Class Method Summary
collapse
#check
Class Method Details
.class_to_name(str) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/pangrid/plugin.rb', line 97
def self.class_to_name(str)
str.gsub(/.*:/, '').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2').
gsub(/([a-z\d])([A-Z])/,'\1-\2').
downcase
end
|
.get(name) ⇒ Object
92
93
94
|
# File 'lib/pangrid/plugin.rb', line 92
def self.get(name)
REGISTRY[name]
end
|
.inherited(subclass) ⇒ Object
38
39
40
41
42
|
# File 'lib/pangrid/plugin.rb', line 38
def self.inherited(subclass)
name = class_to_name(subclass.name)
REGISTRY[name] = subclass
end
|
.list_all ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/pangrid/plugin.rb', line 63
def self.list_all
puts "-------------------------------------------------------"
puts "Available plugins:"
puts "-------------------------------------------------------"
REGISTRY.keys.sort.each do |name|
plugin = REGISTRY[name]
provides = [:read, :write].select {|m| plugin.method_defined? m}
provides = provides.map {|m| {read: 'from', write: 'to'}[m]}
puts " " + name + " [" + provides.join(", ") + "]"
end
if !MISSING_DEPS.empty?
puts
puts "-------------------------------------------------------"
puts "Missing dependencies for plugins:"
puts "-------------------------------------------------------"
MISSING_DEPS.keys.sort.each do |name|
puts " " + name + ": gem install " + MISSING_DEPS[name].join(" ")
end
end
if !FAILED.empty?
puts
puts "The following plugins could not load due to errors:"
puts "-------------------------------------------------------"
FAILED.each do |error|
puts " " + error
end
end
end
|
.load_all ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/pangrid/plugin.rb', line 44
def self.load_all
REGISTRY.clear
FAILED.clear
plugins = Dir.glob(File.dirname(__FILE__) + "/plugins/*.rb")
plugins.each do |f|
load_plugin f
end
end
|
.load_plugin(filename) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/pangrid/plugin.rb', line 53
def self.load_plugin(filename)
begin
require filename
rescue PluginDependencyError => e
MISSING_DEPS[e.name] = e.gems
rescue StandardError => e
FAILED << "#{File.basename(filename)}: #{e}"
end
end
|