Class: PluginManager

Inherits:
Object
  • Object
show all
Defined in:
lib/zmb/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePluginManager

Returns a new instance of PluginManager.



4
5
6
7
# File 'lib/zmb/plugin.rb', line 4

def initialize
  @plugins = Array.new
  @plugin_sources = Array.new
end

Instance Attribute Details

#plugin_sourcesObject

Returns the value of attribute plugin_sources.



2
3
4
# File 'lib/zmb/plugin.rb', line 2

def plugin_sources
  @plugin_sources
end

#pluginsObject

Returns the value of attribute plugins.



2
3
4
# File 'lib/zmb/plugin.rb', line 2

def plugins
  @plugins
end

Instance Method Details

#add_plugin_source(directory) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zmb/plugin.rb', line 29

def add_plugin_source(directory)
  @plugin_sources << directory
  
  definition_files = Dir[
    File.join(File.expand_path(directory), "*.rb"),
    File.join(File.expand_path(directory), "*", "plugin.rb")
  ]
  
  definition_files.map do |file|
    begin
      load_plugin_source(file)
    end
  end
end

#load_plugin_source(file) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/zmb/plugin.rb', line 19

def load_plugin_source(file)
  begin
    definition = instance_eval(File.read(file))
    definition.definitition_file = File.expand_path(file)
    @plugins << definition
  rescue Exception
    nil
  end
end

#plugin(name) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/zmb/plugin.rb', line 9

def plugin(name)
  plugin = @plugins.find{|plugin| plugin.name == name}
  
  if plugin then
    plugin.object
  else
    nil
  end
end

#refresh_plugin_sourcesObject



44
45
46
47
48
49
50
51
# File 'lib/zmb/plugin.rb', line 44

def refresh_plugin_sources
  sources = @plugin_sources
  
  @plugins = Array.new
  @plugin_sources = Array.new
  
  sources.each{|directory| add_plugin_source directory}
end

#reload_plugin(name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/zmb/plugin.rb', line 53

def reload_plugin(name)
  plugin = @plugins.find{|plugin| plugin.name == name}
  
  if plugin then
    @plugins.delete(plugin)
    reloaded = load_plugin_source plugin.definitition_file
    @plugins << plugin if not reloaded
    reloaded
  end
end