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 +1 -1
- data/lib/nuggets/util/pluggable.rb +42 -31
- data/lib/nuggets/version.rb +1 -1
- metadata +5 -5
data/README
CHANGED
@@ -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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
46
|
+
def loaded_plugins
|
47
|
+
@loaded_plugins ||= Set.new
|
48
|
+
end
|
48
49
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
59
|
-
|
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
|
-
}
|
64
|
+
load_plugin_file(plugin) if ::File.file?(plugin)
|
65
|
+
}
|
63
66
|
end
|
64
67
|
|
65
68
|
def load_gem_plugins(name)
|
66
|
-
|
67
|
-
spec.matches_for_glob(name)
|
68
|
-
}.
|
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
|
data/lib/nuggets/version.rb
CHANGED
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:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
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-
|
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.
|
207
|
+
- ruby-nuggets Application documentation (v0.8.2)
|
208
208
|
- --line-numbers
|
209
209
|
require_paths:
|
210
210
|
- lib
|