plugman 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/plugman.rb CHANGED
@@ -2,22 +2,32 @@
2
2
 
3
3
  require 'plugman/finder'
4
4
  require 'plugman/plugin_base'
5
+ require 'logger'
6
+ require 'stringio'
5
7
 
6
8
  class Plugman
7
9
 
8
- def initialize(finder)
9
- @finder = finder
10
+ def initialize(finder_or_name)
11
+ if finder_or_name.is_a?(String)
12
+ @finder = Finder::Standard.new(finder_or_name)
13
+ else
14
+ @finder = finder
15
+ end
10
16
  @plugins = []
17
+ @log = StringIO.new("")
18
+ @logger = Logger.new(@log)
11
19
  Plugman::PluginBase.manager = self
12
20
  end
13
21
 
22
+ def log
23
+ @log.string
24
+ end
25
+
14
26
  def load_plugins
15
- begin
16
- @finder.plugin_files.each {|f| require f }
17
- rescue => e
18
- warn e
27
+ @finder.plugin_files.each do |f|
28
+ require_plugin(f)
19
29
  end
20
-
30
+
21
31
  # All plugins are now registered. Requiering the plugins will
22
32
  # magically call Plugman::Plugin::inherited for each
23
33
  # plugin. inherited() will in turn call register_plugin()
@@ -42,4 +52,15 @@ class Plugman
42
52
 
43
53
  # FIX implement respond_to? to match method_missing?
44
54
 
55
+ private
56
+
57
+
58
+ def require_plugin(f)
59
+ @logger.debug "Requiering #{f}"
60
+ require f
61
+ rescue => e
62
+ @logger.error(e.class.to_s + ": " + e.message)
63
+ end
64
+
65
+
45
66
  end
@@ -1,23 +1,23 @@
1
-
2
1
  require 'rubygems'
3
2
 
4
3
  class Plugman
5
4
  module Finder
6
5
  class Standard
7
6
 
8
- def initialize(glob)
9
- @glob = glob
7
+ def initialize(name)
8
+ @glob = "#{name}/plugin/*"
10
9
  end
11
10
 
12
11
  def plugin_files
13
12
  # FIX assuming here that array is sorted correctly. Assumption correct?
14
13
  seen = {}
15
- Gem.find_files(@plugin_glob, true).each do |p|
14
+ files = []
15
+ Gem.find_files(@glob, true).each do |p|
16
16
  name = File.basename(p)
17
- require p unless seen[name]
17
+ files << p unless seen[name]
18
18
  seen[name] = true
19
19
  end
20
-
20
+ files
21
21
  end
22
22
 
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plugman
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-30 00:00:00.000000000 +02:00
12
+ date: 2011-06-01 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: FIX