plugin_manager 1 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,11 +20,11 @@ class PluginManager
20
20
  end
21
21
 
22
22
  def object(value)
23
- @definition.object = value
23
+ @definition.object_string = value
24
24
  end
25
25
 
26
- def file(value)
27
- @definition.file = value
26
+ def file(*values)
27
+ @definition.file = values
28
28
  end
29
29
 
30
30
  def dependencies(*deps)
@@ -3,25 +3,38 @@ class PluginManager
3
3
  class PluginDefinition
4
4
  attr_accessor :name,
5
5
  :version,
6
- :object,
6
+ :object_string,
7
7
  :file,
8
8
  :dependencies,
9
9
  :definition_file
10
10
 
11
- def inspect
11
+ def inspect1
12
12
  "<Plugin #{name} #{version} depends:[#{(dependencies||[]).map{|dep| dep.join("")}.join(", ")}] #{required_files.length} files>"
13
13
  end
14
14
 
15
+ def inspect
16
+ inspect1
17
+ end
18
+
15
19
  def required_files
16
20
  @required_files ||= []
17
21
  end
18
22
 
19
23
  def load
20
24
  required_files.each {|file| $".delete(file) }
25
+ load_file = File.expand_path(File.join(File.dirname(definition_file), file))
26
+ $:.unshift(File.dirname(load_file))
21
27
  new_files = log_requires do
22
- require File.expand_path(File.join(File.dirname(definition_file), file))
28
+ require load_file
23
29
  end
24
30
  required_files.unshift(*new_files)
31
+ if object.respond_to?(:loaded)
32
+ object.loaded
33
+ end
34
+ end
35
+
36
+ def object
37
+ eval(object_string)
25
38
  end
26
39
 
27
40
  private
@@ -6,7 +6,7 @@ require 'plugin_manager/plugin_definition'
6
6
  require 'plugin_manager/definition_builder'
7
7
 
8
8
  class PluginManager
9
- attr_reader :unreadable_definitions, :plugins_with_errors, :loaded_plugins
9
+ attr_reader :unreadable_definitions, :plugins_with_errors, :loaded_plugins, :unloaded_plugins
10
10
 
11
11
  def initialize
12
12
  @unloaded_plugins = []
@@ -28,8 +28,10 @@ class PluginManager
28
28
  definition = instance_eval(File.read(file))
29
29
  definition.definition_file = File.expand_path(file)
30
30
  definition
31
- rescue Object
31
+ rescue Object => e
32
32
  puts "Unreadable plugin definition: #{file}"
33
+ puts " " + e.message
34
+ puts e.backtrace.map {|l| " " + l }
33
35
  @unreadable_definitions << file
34
36
  nil
35
37
  end
@@ -43,14 +45,15 @@ class PluginManager
43
45
  previous_length = @unloaded_plugins.length
44
46
  if plugin = next_to_load
45
47
  begin
48
+ puts "[PluginManager] loading #{plugin.name}" if ENV["PLUGIN_DEBUG"]
46
49
  plugin.load
50
+ @loaded_plugins << plugin
47
51
  rescue Object => e
48
- puts "Error loading plugin: #{plugin}"
52
+ puts "Error loading plugin: #{plugin.inspect}"
49
53
  puts " " + e.message
50
54
  puts e.backtrace.map {|l| " " + l }
51
55
  @plugins_with_errors << plugin
52
56
  end
53
- @loaded_plugins << plugin
54
57
  @unloaded_plugins.delete(plugin)
55
58
  end
56
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plugin_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: "1"
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lucraft
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-16 00:00:00 +00:00
12
+ date: 2010-01-17 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency