ruby-nuggets 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.8.1
5
+ This documentation refers to ruby-nuggets version 0.8.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -25,57 +25,68 @@
25
25
  ###############################################################################
26
26
  #++
27
27
 
28
+ require 'set'
29
+
28
30
  module Util
29
31
 
30
32
  module Pluggable
31
33
 
32
- class << self
33
-
34
- def load_plugins_for(*klasses)
35
- klasses.map { |klass| klass.extend(self).load_plugins }
36
- end
34
+ def self.load_plugins_for(*klasses)
35
+ klasses.map { |klass| klass.extend(self).load_plugins }
36
+ end
37
37
 
38
- def extended(base)
39
- base.plugin_filename ||= "#{base.name.
40
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
41
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
42
- gsub(/::/, '/').tr('-', '_').downcase}_plugin.rb"
43
- end
38
+ def load_plugins(name = plugin_filename)
39
+ load_path_plugins(name)
40
+ load_gem_plugins(name)
41
+ load_env_plugins(name)
44
42
 
43
+ loaded_plugins.to_a
45
44
  end
46
45
 
47
- attr_accessor :plugin_filename
46
+ def loaded_plugins
47
+ @loaded_plugins ||= Set.new
48
+ end
48
49
 
49
- def load_plugins
50
- plugins, name = [], plugin_filename
51
- plugins.concat(load_env_plugins(name))
52
- plugins.concat(load_gem_plugins(name)) if defined?(::Gem)
53
- plugins
50
+ def plugin_filename
51
+ @plugin_filename ||= "#{name.
52
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
53
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
54
+ gsub(/::/, '/').tr('-', '_').downcase}_plugin.rb"
54
55
  end
55
56
 
57
+ attr_writer :plugin_filename
58
+
56
59
  private
57
60
 
58
- def load_env_plugins(name)
59
- load_plugin_files($LOAD_PATH.map { |path|
61
+ def load_path_plugins(name)
62
+ $LOAD_PATH.dup.each { |path|
60
63
  plugin = ::File.expand_path(name, path)
61
- plugin if ::File.file?(plugin)
62
- }.compact)
64
+ load_plugin_file(plugin) if ::File.file?(plugin)
65
+ }
63
66
  end
64
67
 
65
68
  def load_gem_plugins(name)
66
- load_plugin_files(::Gem::Specification.map { |spec|
67
- spec.matches_for_glob(name)
68
- }.flatten)
69
+ ::Gem::Specification.latest_specs.each { |spec|
70
+ load_plugin_files(spec.matches_for_glob(name))
71
+ } if ::Object.const_defined?(:Gem)
72
+ end
73
+
74
+ def load_env_plugins(name)
75
+ path = ::ENV["#{name.chomp(ext = ::File.extname(name)).upcase}_PATH"]
76
+ path.split(::File::PATH_SEPARATOR).each { |dir|
77
+ load_plugin_files(::Dir["#{dir}/*#{ext}"])
78
+ } if path
79
+ end
80
+
81
+ def load_plugin_file(plugin)
82
+ load plugin if loaded_plugins.add?(plugin)
83
+ rescue ::Exception => err
84
+ raise unless loaded_plugins.delete?(plugin)
85
+ warn "Error loading #{name} plugin: #{plugin}: #{err} (#{err.class})"
69
86
  end
70
87
 
71
88
  def load_plugin_files(plugins)
72
- plugins.each { |plugin|
73
- begin
74
- load plugin
75
- rescue ::Exception => err
76
- warn "Error loading #{name} plugin: #{plugin}: #{err} (#{err.class})"
77
- end
78
- }
89
+ plugins.each { |plugin| load_plugin_file(::File.expand_path(plugin)) }
79
90
  end
80
91
 
81
92
  end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 8
7
- TINY = 1
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 1
10
- version: 0.8.1
9
+ - 2
10
+ version: 0.8.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-28 00:00:00 Z
18
+ date: 2011-12-30 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Some extensions to the Ruby programming language.
@@ -204,7 +204,7 @@ rdoc_options:
204
204
  - --charset
205
205
  - UTF-8
206
206
  - --title
207
- - ruby-nuggets Application documentation (v0.8.1)
207
+ - ruby-nuggets Application documentation (v0.8.2)
208
208
  - --line-numbers
209
209
  require_paths:
210
210
  - lib