plugin 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +18 -16
- data/lib/plugin.rb +72 -19
- data/meta/version +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
= Plugin
|
2
2
|
|
3
3
|
* home: http://rubyworks.github.com/plugin
|
4
|
+
* source: http://github.com/rubyworks/plugin
|
4
5
|
|
5
6
|
|
6
7
|
== DESCRIPTION
|
7
8
|
|
8
|
-
Plugin is a straighforward plugin manager for Ruby.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
== USAGE
|
9
|
+
Plugin is a straighforward plugin manager for Ruby. It can handle
|
10
|
+
RubyGems, Rolls and Ruby's standard site locals. It is both more
|
11
|
+
flexible and more robust the using Gem.find_files or searching the
|
12
|
+
$LOAD_PATH manually.
|
14
13
|
|
15
14
|
The Plugin library does two signifficant things. First it designates
|
16
15
|
a location in the ruby $LOAD_PATH for plugins. Second it provides
|
17
16
|
an easy to use function for finding plugin scripts stored in the
|
18
17
|
designated location.
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
== USAGE
|
20
|
+
|
21
|
+
Place all plugins for you projectt in <tt>lib/plugin/<name>/</tt>.
|
22
|
+
Or if you have altered the load path for your project, you can
|
23
|
+
place it in the alternate location under <tt>plugin/<name></tt>.
|
24
|
+
However, this is not a recommended practice.
|
23
25
|
|
24
|
-
To find plugins, simply provide a
|
25
|
-
|
26
|
-
|
26
|
+
To find plugins, simply provide a glob to the <tt>Plugin.find</tt> function,
|
27
|
+
and it will return all matches found within current and/or most recent versions
|
28
|
+
of libraries.
|
27
29
|
|
28
|
-
For example,
|
29
|
-
the plugins
|
30
|
+
For example, a common use case for a pluggable application is to require all
|
31
|
+
the plugins found:
|
30
32
|
|
31
33
|
require 'plugin'
|
32
34
|
|
@@ -34,8 +36,8 @@ the plugins they find:
|
|
34
36
|
require(file)
|
35
37
|
end
|
36
38
|
|
37
|
-
Alternately you might load plugins only as
|
38
|
-
|
39
|
+
Alternately you might load plugins only as needed. For instance, if a command-line
|
40
|
+
option calls for it.
|
39
41
|
|
40
42
|
|
41
43
|
== COPYRIGHTS
|
data/lib/plugin.rb
CHANGED
@@ -2,6 +2,38 @@
|
|
2
2
|
#
|
3
3
|
# Find plugins across various library managers.
|
4
4
|
#
|
5
|
+
# All plugins are expected to be within a libraries designated
|
6
|
+
# loadpath(s) under a <tt>plugin/</tt> subdirectory. By using
|
7
|
+
# this assigned space, ie. <tt>plugin/<tt>, plugins are kept
|
8
|
+
# isolated from normal libary scripts. This helps prevent
|
9
|
+
# inadvertent name clashes.
|
10
|
+
#
|
11
|
+
# == How To Use
|
12
|
+
#
|
13
|
+
# Usage is very simple. Just supply a glob to the +Plugin.find+
|
14
|
+
# function.
|
15
|
+
#
|
16
|
+
# Plugin.find('syckle/*')
|
17
|
+
#
|
18
|
+
# A shortcut is provided with <tt>[]</tt>.
|
19
|
+
#
|
20
|
+
# Plugin['syckle/*']
|
21
|
+
#
|
22
|
+
# == A Note on RubyGems
|
23
|
+
#
|
24
|
+
# A way has not yet been devised to isolate the actived version
|
25
|
+
# of a gem from the latest inactive version. Therefore some
|
26
|
+
# overlap can occur if an older version of a plugin-containing
|
27
|
+
# gem has been activated prior to calling Plugin.find(). Such an
|
28
|
+
# occurance will be rare (considering the use cases of plugins),
|
29
|
+
# so it is nothing to be overly concerned about. Moreover, it is
|
30
|
+
# a long-way from the offical Gems plugin policy which is to find
|
31
|
+
# all matching files from *all* versions using Gem.find_files().
|
32
|
+
# I quote Eric Hodel, "It's an encouragement to make your plugin
|
33
|
+
# files as light as possible, such as requiring an additional file
|
34
|
+
# or calling some very stable API." While an understandable
|
35
|
+
# encouragment, ultimately it is not a robust solution.
|
36
|
+
|
5
37
|
module Plugin
|
6
38
|
|
7
39
|
extend self
|
@@ -17,20 +49,27 @@ module Plugin
|
|
17
49
|
#
|
18
50
|
def find(match)
|
19
51
|
plugins = []
|
52
|
+
plugins.concat find_roll(match)
|
53
|
+
plugins.concat find_loadpath(match)
|
54
|
+
plugins.concat find_gems(match)
|
55
|
+
plugins.uniq
|
56
|
+
end
|
20
57
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
58
|
+
# Shortcut for #find.
|
59
|
+
#
|
60
|
+
# Plugin['syckle/*']
|
61
|
+
#
|
62
|
+
alias_method :[], :find
|
63
|
+
|
64
|
+
|
65
|
+
# Search roll for current or latest libraries.
|
28
66
|
|
29
|
-
|
67
|
+
def find_roll(match)
|
68
|
+
plugins = []
|
30
69
|
if defined?(::Roll)
|
31
70
|
::Roll::Library.ledger.each do |name, lib|
|
32
71
|
lib = lib.sort.first if Array===lib
|
33
|
-
lib.
|
72
|
+
lib.loadpath.each do |path|
|
34
73
|
find = File.join(lib.location, path, DIRECTORY, match)
|
35
74
|
list = Dir.glob(find)
|
36
75
|
list = list.map{ |d| d.chomp('/') }
|
@@ -38,25 +77,39 @@ module Plugin
|
|
38
77
|
end
|
39
78
|
end
|
40
79
|
end
|
80
|
+
plugins
|
81
|
+
end
|
82
|
+
|
83
|
+
# Search standard $LOAD_PATH.
|
84
|
+
#
|
85
|
+
# Activated gem versions are in here too.
|
86
|
+
|
87
|
+
def find_loadpath(match)
|
88
|
+
plugins = []
|
89
|
+
$LOAD_PATH.uniq.each do |path|
|
90
|
+
list = Dir.glob(File.join(path, DIRECTORY, match))
|
91
|
+
#dirs = dirs.select{ |d| File.directory?(d) }
|
92
|
+
list = list.map{ |d| d.chomp('/') }
|
93
|
+
plugins.concat(list)
|
94
|
+
end
|
95
|
+
plugins
|
96
|
+
end
|
97
|
+
|
98
|
+
# Search latest gem versions.
|
99
|
+
#
|
100
|
+
# TODO: Is there anyway to skip active gems?
|
41
101
|
|
42
|
-
|
43
|
-
|
102
|
+
def find_gems(match)
|
103
|
+
plugins = []
|
44
104
|
if defined?(::Gem)
|
45
|
-
Gem.latest_load_paths do |path|
|
105
|
+
::Gem.latest_load_paths do |path|
|
46
106
|
list = Dir.glob(File.join(path, DIRECTORY, match))
|
47
107
|
list = list.map{ |d| d.chomp('/') }
|
48
108
|
plugins.concat(list)
|
49
109
|
end
|
50
110
|
end
|
51
|
-
|
52
111
|
plugins
|
53
112
|
end
|
54
113
|
|
55
|
-
# Shortcut for #find.
|
56
|
-
#
|
57
|
-
# Plugins['syckle/*']
|
58
|
-
#
|
59
|
-
alias_method :[], :find
|
60
|
-
|
61
114
|
end
|
62
115
|
|
data/meta/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0
|
1
|
+
1.0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0
|
4
|
+
version: "1.0"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Sawyer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|