gem_plugin 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +15 -9
- data/bin/gpgen +60 -0
- data/doc/rdoc/classes/GemPlugin.html +3 -2
- data/doc/rdoc/classes/GemPlugin.src/M000001.html +5 -5
- data/doc/rdoc/classes/GemPlugin/Base.html +1 -1
- data/doc/rdoc/classes/GemPlugin/Base.src/M000002.html +6 -6
- data/doc/rdoc/classes/GemPlugin/Base.src/M000003.html +4 -4
- data/doc/rdoc/classes/GemPlugin/Base.src/M000004.html +4 -4
- data/doc/rdoc/classes/GemPlugin/Manager.html +107 -8
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000005.html +9 -5
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000006.html +30 -29
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000007.html +5 -5
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000008.html +15 -15
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000009.html +5 -5
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000010.html +28 -0
- data/doc/rdoc/classes/GemPlugin/Manager.src/M000011.html +28 -0
- data/doc/rdoc/classes/GemPlugin/PluginNotLoaded.html +111 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +3 -6
- data/doc/rdoc/files/lib/gem_plugin_rb.html +1 -1
- data/doc/rdoc/fr_class_index.html +1 -0
- data/doc/rdoc/fr_method_index.html +3 -1
- data/lib/gem_plugin.rb +89 -13
- data/resources/COPYING +1 -0
- data/resources/LICENSE +1 -0
- data/resources/README +5 -0
- data/resources/Rakefile +37 -0
- data/resources/lib/project/init.rb +6 -0
- data/resources/resources/defaults.yaml +2 -0
- data/resources/tools/rakehelp.rb +105 -0
- data/test/test_plugins.rb +3 -4
- data/tools/rakehelp.rb +5 -11
- metadata +36 -11
@@ -10,20 +10,20 @@
|
|
10
10
|
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 145</span>
|
14
|
+
145: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
|
15
|
+
146: <span class="ruby-identifier">last_slash</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-value str">"/"</span>)
|
16
|
+
147: <span class="ruby-identifier">category</span> = <span class="ruby-identifier">name</span>[<span class="ruby-value">0</span> <span class="ruby-operator">...</span> <span class="ruby-identifier">last_slash</span>]
|
17
|
+
148: <span class="ruby-identifier">plugin</span> = <span class="ruby-identifier">name</span>[<span class="ruby-identifier">last_slash</span> <span class="ruby-operator">..</span> <span class="ruby-value">-1</span>]
|
18
|
+
149:
|
19
|
+
150: <span class="ruby-identifier">map</span> = <span class="ruby-ivar">@plugins</span>[<span class="ruby-identifier">category</span>]
|
20
|
+
151: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">map</span>
|
21
|
+
152: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Plugin category #{category} does not exist"</span>
|
22
|
+
153: <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">map</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">plugin</span>
|
23
|
+
154: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Plugin #{plugin} does not exist in category #{category}"</span>
|
24
|
+
155: <span class="ruby-keyword kw">else</span>
|
25
|
+
156: <span class="ruby-identifier">map</span>[<span class="ruby-identifier">plugin</span>].<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>)
|
26
|
+
157: <span class="ruby-keyword kw">end</span>
|
27
|
+
158: <span class="ruby-keyword kw">end</span></pre>
|
28
28
|
</body>
|
29
29
|
</html>
|
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
<html>
|
7
7
|
<head>
|
8
|
-
<title>
|
8
|
+
<title>loaded? (GemPlugin::Manager)</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
11
|
</head>
|
12
12
|
<body class="standalone-code">
|
13
|
-
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 162</span>
|
14
|
+
162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">loaded?</span>(<span class="ruby-identifier">gem_name</span>)
|
15
|
+
163: <span class="ruby-ivar">@gems</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">gem_name</span>
|
16
|
+
164: <span class="ruby-keyword kw">end</span></pre>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>resource (GemPlugin::Manager)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 185</span>
|
14
|
+
185: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">resource</span>(<span class="ruby-identifier">gem_name</span>, <span class="ruby-identifier">path</span>)
|
15
|
+
186: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">loaded?</span> <span class="ruby-identifier">gem_name</span>
|
16
|
+
187: <span class="ruby-identifier">raise</span> <span class="ruby-constant">PluginNotLoaded</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"Plugin #{gem_name} not loaded when getting resource #{path}"</span>)
|
17
|
+
188: <span class="ruby-keyword kw">end</span>
|
18
|
+
189:
|
19
|
+
190: <span class="ruby-identifier">file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@gems</span>[<span class="ruby-identifier">gem_name</span>], <span class="ruby-value str">"resources"</span>, <span class="ruby-identifier">path</span>)
|
20
|
+
191:
|
21
|
+
192: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">file</span>
|
22
|
+
193: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">file</span>
|
23
|
+
194: <span class="ruby-keyword kw">else</span>
|
24
|
+
195: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
25
|
+
196: <span class="ruby-keyword kw">end</span>
|
26
|
+
197: <span class="ruby-keyword kw">end</span></pre>
|
27
|
+
</body>
|
28
|
+
</html>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>config (GemPlugin::Manager)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 218</span>
|
14
|
+
218: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>(<span class="ruby-identifier">gem_name</span>, <span class="ruby-identifier">options</span>={})
|
15
|
+
219: <span class="ruby-identifier">config_file</span> = <span class="ruby-constant">Manager</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">resource</span>(<span class="ruby-identifier">gem_name</span>, <span class="ruby-value str">"/defaults.yaml"</span>)
|
16
|
+
220: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">config_file</span>
|
17
|
+
221: <span class="ruby-keyword kw">begin</span>
|
18
|
+
222: <span class="ruby-identifier">defaults</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load_file</span>(<span class="ruby-identifier">config_file</span>)
|
19
|
+
223: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
|
20
|
+
224: <span class="ruby-keyword kw">rescue</span>
|
21
|
+
225: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Error loading config #{config_file} for gem #{gem_name}"</span>
|
22
|
+
226: <span class="ruby-keyword kw">end</span>
|
23
|
+
227: <span class="ruby-keyword kw">else</span>
|
24
|
+
228: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">options</span>
|
25
|
+
229: <span class="ruby-keyword kw">end</span>
|
26
|
+
230: <span class="ruby-keyword kw">end</span></pre>
|
27
|
+
</body>
|
28
|
+
</html>
|
@@ -0,0 +1,111 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: GemPlugin::PluginNotLoaded</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">GemPlugin::PluginNotLoaded</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/gem_plugin_rb.html">
|
59
|
+
lib/gem_plugin.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
StandardError
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
|
89
|
+
<!-- if includes -->
|
90
|
+
|
91
|
+
<div id="section">
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
<!-- if method_list -->
|
101
|
+
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
|
106
|
+
<div id="validator-badges">
|
107
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</body>
|
111
|
+
</html>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Sat Mar 11 22:25:45 EST 2006
|
data/doc/rdoc/files/README.html
CHANGED
@@ -92,9 +92,7 @@ only have to require ‘gem_plugin’ and then use the <a
|
|
92
92
|
href="../classes/GemPlugin/Manager.html#M000008">GemPlugin::Manager.create</a>,
|
93
93
|
<a
|
94
94
|
href="../classes/GemPlugin/Manager.html#M000006">GemPlugin::Manager.load</a>,
|
95
|
-
and
|
96
|
-
href="../classes/GemPlugin/Manager.html#M000009">GemPlugin::Manager.available</a>
|
97
|
-
methods to work with them.
|
95
|
+
and GemPlugin::Manager.available methods to work with them.
|
98
96
|
</p>
|
99
97
|
<ul>
|
100
98
|
<li><a
|
@@ -108,9 +106,8 @@ href="../classes/GemPlugin/Manager.html#M000008">GemPlugin::Manager.create</a>
|
|
108
106
|
— Takes a URI style name and some options then creates one for you.
|
109
107
|
|
110
108
|
</li>
|
111
|
-
<li
|
112
|
-
|
113
|
-
— Lets you inspect and mess with the internal plugin registry.
|
109
|
+
<li>GemPlugin::Manager.available — Lets you inspect and mess with the
|
110
|
+
internal plugin registry.
|
114
111
|
|
115
112
|
</li>
|
116
113
|
</ul>
|
@@ -23,6 +23,7 @@
|
|
23
23
|
<a href="classes/GemPlugin.html">GemPlugin</a><br />
|
24
24
|
<a href="classes/GemPlugin/Base.html">GemPlugin::Base</a><br />
|
25
25
|
<a href="classes/GemPlugin/Manager.html">GemPlugin::Manager</a><br />
|
26
|
+
<a href="classes/GemPlugin/PluginNotLoaded.html">GemPlugin::PluginNotLoaded</a><br />
|
26
27
|
</div>
|
27
28
|
</div>
|
28
29
|
</body>
|
@@ -21,14 +21,16 @@
|
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
23
|
<a href="classes/GemPlugin.html#M000001">Plugin (GemPlugin)</a><br />
|
24
|
-
<a href="classes/GemPlugin/Manager.html#M000009">available (GemPlugin::Manager)</a><br />
|
25
24
|
<a href="classes/GemPlugin/Base.html#M000003">category= (GemPlugin::Base)</a><br />
|
25
|
+
<a href="classes/GemPlugin/Manager.html#M000011">config (GemPlugin::Manager)</a><br />
|
26
26
|
<a href="classes/GemPlugin/Manager.html#M000008">create (GemPlugin::Manager)</a><br />
|
27
27
|
<a href="classes/GemPlugin/Base.html#M000002">inherited (GemPlugin::Base)</a><br />
|
28
28
|
<a href="classes/GemPlugin/Manager.html#M000006">load (GemPlugin::Manager)</a><br />
|
29
|
+
<a href="classes/GemPlugin/Manager.html#M000009">loaded? (GemPlugin::Manager)</a><br />
|
29
30
|
<a href="classes/GemPlugin/Manager.html#M000005">new (GemPlugin::Manager)</a><br />
|
30
31
|
<a href="classes/GemPlugin/Base.html#M000004">new (GemPlugin::Base)</a><br />
|
31
32
|
<a href="classes/GemPlugin/Manager.html#M000007">register (GemPlugin::Manager)</a><br />
|
33
|
+
<a href="classes/GemPlugin/Manager.html#M000010">resource (GemPlugin::Manager)</a><br />
|
32
34
|
</div>
|
33
35
|
</div>
|
34
36
|
</body>
|
data/lib/gem_plugin.rb
CHANGED
@@ -20,9 +20,9 @@ require 'rubygems'
|
|
20
20
|
# gems based on what they also depend on, thus letting you load these gems when appropriate.
|
21
21
|
#
|
22
22
|
# Since this system was written originally for the Mongrel project that'll be the
|
23
|
-
# best
|
23
|
+
# best example of using it.
|
24
24
|
#
|
25
|
-
# Imagine you have a neat plugin for Mongrel called snazzy_command that
|
25
|
+
# Imagine you have a neat plugin for Mongrel called snazzy_command that gives the
|
26
26
|
# mongrel_rails a new command snazzy (like: mongrel_rails snazzy). You'd like
|
27
27
|
# people to be able to grab this plugin if they want and use it, because it's snazzy.
|
28
28
|
#
|
@@ -51,6 +51,9 @@ module GemPlugin
|
|
51
51
|
|
52
52
|
EXCLUDE = true
|
53
53
|
INCLUDE = false
|
54
|
+
|
55
|
+
class PluginNotLoaded < StandardError; end
|
56
|
+
|
54
57
|
|
55
58
|
# This class is used by people who use gem plugins (but don't necessarily make them)
|
56
59
|
# to add plugins to their own systems. It provides a way to load plugins, list them,
|
@@ -59,10 +62,17 @@ module GemPlugin
|
|
59
62
|
# It is a singleton so you use like this: GemPlugins::Manager.instance.load
|
60
63
|
class Manager
|
61
64
|
include Singleton
|
65
|
+
attr_reader :plugins
|
66
|
+
attr_reader :gems
|
67
|
+
|
62
68
|
|
63
69
|
def initialize
|
70
|
+
# plugins that have been loaded
|
64
71
|
@plugins = {}
|
65
|
-
|
72
|
+
|
73
|
+
# keeps track of gems which have been loaded already by the manager *and*
|
74
|
+
# where they came from so that they can be referenced later
|
75
|
+
@gems = {}
|
66
76
|
end
|
67
77
|
|
68
78
|
|
@@ -95,7 +105,7 @@ module GemPlugin
|
|
95
105
|
|
96
106
|
gems.each do |path, gem|
|
97
107
|
# don't load gems more than once
|
98
|
-
next if @
|
108
|
+
next if @gems.has_key? gem.name
|
99
109
|
check = needs.dup
|
100
110
|
|
101
111
|
# rolls through the depends and inverts anything it finds
|
@@ -110,11 +120,12 @@ module GemPlugin
|
|
110
120
|
# makes them false so we'll skip this gem if any excludes are found
|
111
121
|
if (check.select {|name,test| !test}).length == 0
|
112
122
|
# looks like no needs were set to false, so it's good
|
113
|
-
|
114
|
-
@
|
123
|
+
require "#{gem.name}/init"
|
124
|
+
@gems[gem.name] = File.join(Gem.dir, "gems", "#{gem.name}-#{gem.version}")
|
115
125
|
end
|
116
|
-
|
117
126
|
end
|
127
|
+
|
128
|
+
return nil
|
118
129
|
end
|
119
130
|
|
120
131
|
|
@@ -125,7 +136,8 @@ module GemPlugin
|
|
125
136
|
@plugins[category] ||= {}
|
126
137
|
@plugins[category][name.downcase] = klass
|
127
138
|
end
|
128
|
-
|
139
|
+
|
140
|
+
|
129
141
|
# Resolves the given name (should include /category/name) to
|
130
142
|
# find the plugin class and create an instance. You can
|
131
143
|
# pass a second hash option that is then given to the Plugin
|
@@ -146,15 +158,79 @@ module GemPlugin
|
|
146
158
|
end
|
147
159
|
|
148
160
|
|
149
|
-
#
|
150
|
-
|
151
|
-
|
152
|
-
return @plugins
|
161
|
+
# Simply says whether the given gem has been loaded yet or not.
|
162
|
+
def loaded?(gem_name)
|
163
|
+
@gems.has_key? gem_name
|
153
164
|
end
|
165
|
+
|
166
|
+
|
167
|
+
# GemPlugins can have a 'resources' directory which is packaged with them
|
168
|
+
# and can hold any data resources the plugin may need. The main problem
|
169
|
+
# is that it's difficult to figure out where these resources are
|
170
|
+
# actually located on the file system. The resource method tries to
|
171
|
+
# locate the real path for a given resource path.
|
172
|
+
#
|
173
|
+
# Let's say you have a 'resources/stylesheets/default.css' file in your
|
174
|
+
# gem distribution, then finding where this file really is involves:
|
175
|
+
#
|
176
|
+
# Manager.instance.resource("mygem", "/stylesheets/default.css")
|
177
|
+
#
|
178
|
+
# You either get back the full path to the resource or you get a nil
|
179
|
+
# if it doesn't exist.
|
180
|
+
#
|
181
|
+
# If you request a path for a GemPlugin that hasn't been loaded yet
|
182
|
+
# then it will throw an PluginNotLoaded exception. The gem may be
|
183
|
+
# present on your system in this case, but you just haven't loaded
|
184
|
+
# it with Manager.instance.load properly.
|
185
|
+
def resource(gem_name, path)
|
186
|
+
if not loaded? gem_name
|
187
|
+
raise PluginNotLoaded.new("Plugin #{gem_name} not loaded when getting resource #{path}")
|
188
|
+
end
|
189
|
+
|
190
|
+
file = File.join(@gems[gem_name], "resources", path)
|
191
|
+
|
192
|
+
if File.exist? file
|
193
|
+
return file
|
194
|
+
else
|
195
|
+
return nil
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
154
199
|
|
200
|
+
# While Manager.resource will find arbitrary resources, a special
|
201
|
+
# case is when you need to load a set of configuration defaults.
|
202
|
+
# GemPlugin normalizes this to be if you have a file "resources/defaults.yaml"
|
203
|
+
# then you'll be able to load them via Manager.config.
|
204
|
+
#
|
205
|
+
# How you use the method is you get the options the user wants set, pass
|
206
|
+
# them to Manager.instance.config, and what you get back is a new Hash
|
207
|
+
# with the user's settings overriding the defaults.
|
208
|
+
#
|
209
|
+
# opts = Manager.instance.config "mygem", :age => 12, :max_load => .9
|
210
|
+
#
|
211
|
+
# In the above case, if defaults had {:age => 14} then it would be
|
212
|
+
# changed to 12.
|
213
|
+
#
|
214
|
+
# This loads the .yaml file on the fly every time, so doing it a
|
215
|
+
# whole lot is very stupid. If you need to make frequent calls to
|
216
|
+
# this, call it once with no options (Manager.instance.config) then
|
217
|
+
# use the returned defaults directly from then on.
|
218
|
+
def config(gem_name, options={})
|
219
|
+
config_file = Manager.instance.resource(gem_name, "/defaults.yaml")
|
220
|
+
if config_file
|
221
|
+
begin
|
222
|
+
defaults = YAML.load_file(config_file)
|
223
|
+
return defaults.merge(options)
|
224
|
+
rescue
|
225
|
+
raise "Error loading config #{config_file} for gem #{gem_name}"
|
226
|
+
end
|
227
|
+
else
|
228
|
+
return options
|
229
|
+
end
|
230
|
+
end
|
155
231
|
end
|
156
232
|
|
157
|
-
# This base class for plugins
|
233
|
+
# This base class for plugins really does nothing
|
158
234
|
# more than wire up the new class into the right category.
|
159
235
|
# It is not thread-safe yet but will be soon.
|
160
236
|
class Base
|