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
data/Rakefile
CHANGED
@@ -15,19 +15,25 @@ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
|
|
15
15
|
desc "Does a full compile, test run"
|
16
16
|
task :default => [:test, :package]
|
17
17
|
|
18
|
-
version="0.
|
19
|
-
summary = "A plugin system based only on rubygems"
|
20
|
-
test_file = "test/test_plugins.rb"
|
21
|
-
author="Zed A. Shaw"
|
18
|
+
version = "0.2"
|
22
19
|
name="gem_plugin"
|
23
|
-
scripts=[]
|
24
20
|
|
25
|
-
setup_gem(name, version
|
26
|
-
spec.
|
21
|
+
setup_gem(name, version) do |spec|
|
22
|
+
spec.author="Zed A. Shaw"
|
23
|
+
spec.summary = "A plugin system based only on rubygems that uses dependencies only"
|
24
|
+
spec.description = spec.summary
|
25
|
+
spec.test_file = "test/test_plugins.rb"
|
26
|
+
spec.files += Dir.glob("resources/**/*")
|
27
|
+
spec.executables=["gpgen"]
|
28
|
+
spec.add_dependency("rake", ">= 0.7")
|
27
29
|
end
|
28
30
|
|
29
|
-
task :
|
30
|
-
sh %{sudo gem install pkg
|
31
|
+
task :install => [:test, :package] do
|
32
|
+
sh %{sudo gem install pkg/#{name}-#{version}}
|
33
|
+
end
|
34
|
+
|
35
|
+
task :uninstall => [:clean] do
|
36
|
+
sh %{sudo gem uninstall #{name}}
|
31
37
|
end
|
32
38
|
|
33
39
|
task :site => [:rerdoc] do
|
data/bin/gpgen
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'fileutils'
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
if ARGV.length != 1
|
6
|
+
STDERR.puts "ERROR: You must give a name for your plugin and directory."
|
7
|
+
STDERR.puts "usage: gpgen name"
|
8
|
+
STDERR.puts "example: gpgen mygemplugin"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
# setup the required binding variables for erb processing later
|
13
|
+
project = ARGV.shift
|
14
|
+
gem_plugin_base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
15
|
+
resources = File.join(gem_plugin_base, "resources")
|
16
|
+
gem_plugin_version = gem_plugin_base[gem_plugin_base.rindex("-")+1 .. -1]
|
17
|
+
|
18
|
+
|
19
|
+
# make the dir if it don't exist
|
20
|
+
if not File.exist? project
|
21
|
+
puts "Creating directory #{project}"
|
22
|
+
mkdir project
|
23
|
+
else
|
24
|
+
puts "Directory #{project} exists, skipping."
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# go through all the resource files, erb them, and write them verbatim to output
|
29
|
+
# do not overwrite if exists already
|
30
|
+
|
31
|
+
Dir.glob("#{resources}/**/*") do |infile|
|
32
|
+
outfile = File.join(project, infile[resources.length .. -1])
|
33
|
+
if File.exist? outfile
|
34
|
+
puts "File #{outfile} exists, skipping."
|
35
|
+
else
|
36
|
+
if File.directory? infile
|
37
|
+
puts "Creating directory #{outfile}"
|
38
|
+
mkdir_p outfile
|
39
|
+
elsif File.file? infile
|
40
|
+
puts "Creating file #{outfile}"
|
41
|
+
open(infile) do |content|
|
42
|
+
template = ERB.new(content.read)
|
43
|
+
open(outfile,"w") {|f| f.write(template.result(binding)) }
|
44
|
+
end
|
45
|
+
else
|
46
|
+
puts "!!! Resources contains something not a file or directory."
|
47
|
+
puts "Skipping #{infile}."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Finally, move the base init.rb to the right dir
|
53
|
+
init_file = File.join(project,"lib",project)
|
54
|
+
if File.exist? init_file
|
55
|
+
puts "File init.rb already exists, skipping."
|
56
|
+
puts "WARNING: There might be a junk '#{project}/lib/project/init.rb' file you can delete."
|
57
|
+
else
|
58
|
+
puts "Creating proper '#{project}/lib/#{project}/init.rb' file"
|
59
|
+
mv File.join(project,"lib","project"), init_file
|
60
|
+
end
|
@@ -102,10 +102,10 @@ when appropriate.
|
|
102
102
|
</p>
|
103
103
|
<p>
|
104
104
|
Since this system was written originally for the Mongrel project
|
105
|
-
that’ll be the best
|
105
|
+
that’ll be the best example of using it.
|
106
106
|
</p>
|
107
107
|
<p>
|
108
|
-
Imagine you have a neat plugin for Mongrel called snazzy_command that
|
108
|
+
Imagine you have a neat plugin for Mongrel called snazzy_command that gives
|
109
109
|
the mongrel_rails a new command snazzy (like: mongrel_rails snazzy).
|
110
110
|
You‘d like people to be able to grab this plugin if they want and use
|
111
111
|
it, because it’s snazzy.
|
@@ -168,6 +168,7 @@ Read that to see how it is really done.
|
|
168
168
|
|
169
169
|
Class <a href="GemPlugin/Base.html" class="link">GemPlugin::Base</a><br />
|
170
170
|
Class <a href="GemPlugin/Manager.html" class="link">GemPlugin::Manager</a><br />
|
171
|
+
Class <a href="GemPlugin/PluginNotLoaded.html" class="link">GemPlugin::PluginNotLoaded</a><br />
|
171
172
|
|
172
173
|
</div>
|
173
174
|
|
@@ -10,10 +10,10 @@
|
|
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
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 271</span>
|
14
|
+
271: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">GemPlugin</span><span class="ruby-operator">::</span><span class="ruby-constant">Plugin</span>(<span class="ruby-identifier">c</span>)
|
15
|
+
272: <span class="ruby-constant">Base</span>.<span class="ruby-identifier">category</span> = <span class="ruby-identifier">c</span>
|
16
|
+
273: <span class="ruby-constant">Base</span>
|
17
|
+
274: <span class="ruby-keyword kw">end</span></pre>
|
18
18
|
</body>
|
19
19
|
</html>
|
@@ -80,7 +80,7 @@
|
|
80
80
|
|
81
81
|
<div id="description">
|
82
82
|
<p>
|
83
|
-
This base class for plugins
|
83
|
+
This base class for plugins really does nothing more than wire up the new
|
84
84
|
class into the right category. It is not thread-safe yet but will be soon.
|
85
85
|
</p>
|
86
86
|
|
@@ -10,11 +10,11 @@
|
|
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
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 242</span>
|
14
|
+
242: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Base</span>.<span class="ruby-identifier">inherited</span>(<span class="ruby-identifier">klass</span>)
|
15
|
+
243: <span class="ruby-identifier">name</span> = <span class="ruby-value str">"/"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>
|
16
|
+
244: <span class="ruby-constant">Manager</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">register</span>(<span class="ruby-ivar">@@category</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">klass</span>)
|
17
|
+
245: <span class="ruby-ivar">@@category</span> = <span class="ruby-keyword kw">nil</span>
|
18
|
+
246: <span class="ruby-keyword kw">end</span></pre>
|
19
19
|
</body>
|
20
20
|
</html>
|
@@ -10,9 +10,9 @@
|
|
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 249</span>
|
14
|
+
249: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Base</span>.<span class="ruby-identifier">category=</span>(<span class="ruby-identifier">category</span>)
|
15
|
+
250: <span class="ruby-ivar">@@category</span> = <span class="ruby-identifier">category</span>
|
16
|
+
251: <span class="ruby-keyword kw">end</span></pre>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -10,9 +10,9 @@
|
|
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 253</span>
|
14
|
+
253: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
|
15
|
+
254: <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>
|
16
|
+
255: <span class="ruby-keyword kw">end</span></pre>
|
17
17
|
</body>
|
18
18
|
</html>
|
@@ -97,11 +97,13 @@ It is a singleton so you use like this: GemPlugins::Manager.instance.load
|
|
97
97
|
<h3 class="section-bar">Methods</h3>
|
98
98
|
|
99
99
|
<div class="name-list">
|
100
|
-
<a href="#
|
100
|
+
<a href="#M000011">config</a>
|
101
101
|
<a href="#M000008">create</a>
|
102
102
|
<a href="#M000006">load</a>
|
103
|
+
<a href="#M000009">loaded?</a>
|
103
104
|
<a href="#M000005">new</a>
|
104
105
|
<a href="#M000007">register</a>
|
106
|
+
<a href="#M000010">resource</a>
|
105
107
|
</div>
|
106
108
|
</div>
|
107
109
|
|
@@ -123,6 +125,24 @@ It is a singleton so you use like this: GemPlugins::Manager.instance.load
|
|
123
125
|
|
124
126
|
|
125
127
|
|
128
|
+
<div id="attribute-list">
|
129
|
+
<h3 class="section-bar">Attributes</h3>
|
130
|
+
|
131
|
+
<div class="name-list">
|
132
|
+
<table>
|
133
|
+
<tr class="top-aligned-row context-row">
|
134
|
+
<td class="context-item-name">gems</td>
|
135
|
+
<td class="context-item-value"> [R] </td>
|
136
|
+
<td class="context-item-desc"></td>
|
137
|
+
</tr>
|
138
|
+
<tr class="top-aligned-row context-row">
|
139
|
+
<td class="context-item-name">plugins</td>
|
140
|
+
<td class="context-item-value"> [R] </td>
|
141
|
+
<td class="context-item-desc"></td>
|
142
|
+
</tr>
|
143
|
+
</table>
|
144
|
+
</div>
|
145
|
+
</div>
|
126
146
|
|
127
147
|
|
128
148
|
|
@@ -146,20 +166,42 @@ It is a singleton so you use like this: GemPlugins::Manager.instance.load
|
|
146
166
|
|
147
167
|
<h3 class="section-bar">Public Instance methods</h3>
|
148
168
|
|
149
|
-
<div id="method-
|
150
|
-
<a name="
|
169
|
+
<div id="method-M000011" class="method-detail">
|
170
|
+
<a name="M000011"></a>
|
151
171
|
|
152
172
|
<div class="method-heading">
|
153
|
-
<a href="Manager.src/
|
154
|
-
onclick="popupCode('Manager.src/
|
155
|
-
<span class="method-name">
|
173
|
+
<a href="Manager.src/M000011.html" target="Code" class="method-signature"
|
174
|
+
onclick="popupCode('Manager.src/M000011.html');return false;">
|
175
|
+
<span class="method-name">config</span><span class="method-args">(gem_name, options={})</span>
|
156
176
|
</a>
|
157
177
|
</div>
|
158
178
|
|
159
179
|
<div class="method-description">
|
160
180
|
<p>
|
161
|
-
|
162
|
-
to
|
181
|
+
While <a href="Manager.html#M000010">Manager.resource</a> will find
|
182
|
+
arbitrary resources, a special case is when you need to load a set of
|
183
|
+
configuration defaults. <a href="../GemPlugin.html">GemPlugin</a>
|
184
|
+
normalizes this to be if you have a file
|
185
|
+
"resources/defaults.yaml" then you’ll be able to load them
|
186
|
+
via <a href="Manager.html#M000011">Manager.config</a>.
|
187
|
+
</p>
|
188
|
+
<p>
|
189
|
+
How you use the method is you get the options the user wants set, pass them
|
190
|
+
to Manager.instance.config, and what you get back is a new Hash with the
|
191
|
+
user’s settings overriding the defaults.
|
192
|
+
</p>
|
193
|
+
<pre>
|
194
|
+
opts = Manager.instance.config "mygem", :age => 12, :max_load => .9
|
195
|
+
</pre>
|
196
|
+
<p>
|
197
|
+
In the above case, if defaults had {:age => 14} then it would be changed
|
198
|
+
to 12.
|
199
|
+
</p>
|
200
|
+
<p>
|
201
|
+
This loads the .yaml file on the fly every time, so doing it a whole lot is
|
202
|
+
very stupid. If you need to make frequent calls to this, call it once with
|
203
|
+
no options (Manager.instance.config) then use the returned defaults
|
204
|
+
directly from then on.
|
163
205
|
</p>
|
164
206
|
</div>
|
165
207
|
</div>
|
@@ -228,6 +270,23 @@ mongrel, and rails are ever used to determine if it should be included.
|
|
228
270
|
</div>
|
229
271
|
</div>
|
230
272
|
|
273
|
+
<div id="method-M000009" class="method-detail">
|
274
|
+
<a name="M000009"></a>
|
275
|
+
|
276
|
+
<div class="method-heading">
|
277
|
+
<a href="Manager.src/M000009.html" target="Code" class="method-signature"
|
278
|
+
onclick="popupCode('Manager.src/M000009.html');return false;">
|
279
|
+
<span class="method-name">loaded?</span><span class="method-args">(gem_name)</span>
|
280
|
+
</a>
|
281
|
+
</div>
|
282
|
+
|
283
|
+
<div class="method-description">
|
284
|
+
<p>
|
285
|
+
Simply says whether the given gem has been loaded yet or not.
|
286
|
+
</p>
|
287
|
+
</div>
|
288
|
+
</div>
|
289
|
+
|
231
290
|
<div id="method-M000007" class="method-detail">
|
232
291
|
<a name="M000007"></a>
|
233
292
|
|
@@ -247,6 +306,46 @@ plugin to a category.
|
|
247
306
|
</div>
|
248
307
|
</div>
|
249
308
|
|
309
|
+
<div id="method-M000010" class="method-detail">
|
310
|
+
<a name="M000010"></a>
|
311
|
+
|
312
|
+
<div class="method-heading">
|
313
|
+
<a href="Manager.src/M000010.html" target="Code" class="method-signature"
|
314
|
+
onclick="popupCode('Manager.src/M000010.html');return false;">
|
315
|
+
<span class="method-name">resource</span><span class="method-args">(gem_name, path)</span>
|
316
|
+
</a>
|
317
|
+
</div>
|
318
|
+
|
319
|
+
<div class="method-description">
|
320
|
+
<p>
|
321
|
+
GemPlugins can have a ‘resources’ directory which is packaged
|
322
|
+
with them and can hold any data resources the plugin may need. The main
|
323
|
+
problem is that it’s difficult to figure out where these resources
|
324
|
+
are actually located on the file system. The resource method tries to
|
325
|
+
locate the real path for a given resource path.
|
326
|
+
</p>
|
327
|
+
<p>
|
328
|
+
Let’s say you have a ‘resources/stylesheets/default.css’
|
329
|
+
file in your gem distribution, then finding where this file really is
|
330
|
+
involves:
|
331
|
+
</p>
|
332
|
+
<pre>
|
333
|
+
Manager.instance.resource("mygem", "/stylesheets/default.css")
|
334
|
+
</pre>
|
335
|
+
<p>
|
336
|
+
You either get back the full path to the resource or you get a nil if it
|
337
|
+
doesn’t exist.
|
338
|
+
</p>
|
339
|
+
<p>
|
340
|
+
If you request a path for a <a href="../GemPlugin.html">GemPlugin</a> that
|
341
|
+
hasn’t been loaded yet then it will throw an <a
|
342
|
+
href="PluginNotLoaded.html">PluginNotLoaded</a> exception. The gem may be
|
343
|
+
present on your system in this case, but you just haven’t loaded it
|
344
|
+
with Manager.instance.load properly.
|
345
|
+
</p>
|
346
|
+
</div>
|
347
|
+
</div>
|
348
|
+
|
250
349
|
|
251
350
|
</div>
|
252
351
|
|
@@ -10,10 +10,14 @@
|
|
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
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 69</span>
|
14
|
+
69: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
|
15
|
+
70: <span class="ruby-comment cmt"># plugins that have been loaded</span>
|
16
|
+
71: <span class="ruby-ivar">@plugins</span> = {}
|
17
|
+
72:
|
18
|
+
73: <span class="ruby-comment cmt"># keeps track of gems which have been loaded already by the manager *and*</span>
|
19
|
+
74: <span class="ruby-comment cmt"># where they came from so that they can be referenced later</span>
|
20
|
+
75: <span class="ruby-ivar">@gems</span> = {}
|
21
|
+
76: <span class="ruby-keyword kw">end</span></pre>
|
18
22
|
</body>
|
19
23
|
</html>
|
@@ -10,34 +10,35 @@
|
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 101</span>
|
14
|
+
101: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load</span>(<span class="ruby-identifier">needs</span> = {})
|
15
|
+
102: <span class="ruby-identifier">sdir</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">Gem</span>.<span class="ruby-identifier">dir</span>, <span class="ruby-value str">"specifications"</span>)
|
16
|
+
103: <span class="ruby-identifier">gems</span> = <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">SourceIndex</span>.<span class="ruby-identifier">from_installed_gems</span>(<span class="ruby-identifier">sdir</span>)
|
17
|
+
104: <span class="ruby-identifier">needs</span> = <span class="ruby-identifier">needs</span>.<span class="ruby-identifier">merge</span>({<span class="ruby-value str">"gem_plugin"</span> =<span class="ruby-operator">></span> <span class="ruby-constant">INCLUDE</span>})
|
18
|
+
105:
|
19
|
+
106: <span class="ruby-identifier">gems</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span>, <span class="ruby-identifier">gem</span><span class="ruby-operator">|</span>
|
20
|
+
107: <span class="ruby-comment cmt"># don't load gems more than once</span>
|
21
|
+
108: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@gems</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">gem</span>.<span class="ruby-identifier">name</span>
|
22
|
+
109: <span class="ruby-identifier">check</span> = <span class="ruby-identifier">needs</span>.<span class="ruby-identifier">dup</span>
|
23
|
+
110:
|
24
|
+
111: <span class="ruby-comment cmt"># rolls through the depends and inverts anything it finds</span>
|
25
|
+
112: <span class="ruby-identifier">gem</span>.<span class="ruby-identifier">dependencies</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">dep</span><span class="ruby-operator">|</span>
|
26
|
+
113: <span class="ruby-comment cmt"># this will fail if a gem is depended more than once</span>
|
27
|
+
114: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">check</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">dep</span>.<span class="ruby-identifier">name</span>
|
28
|
+
115: <span class="ruby-identifier">check</span>[<span class="ruby-identifier">dep</span>.<span class="ruby-identifier">name</span>] = <span class="ruby-operator">!</span><span class="ruby-identifier">check</span>[<span class="ruby-identifier">dep</span>.<span class="ruby-identifier">name</span>]
|
29
|
+
116: <span class="ruby-keyword kw">end</span>
|
30
|
+
117: <span class="ruby-keyword kw">end</span>
|
31
|
+
118:
|
32
|
+
119: <span class="ruby-comment cmt"># now since excluded gems start as true, inverting them</span>
|
33
|
+
120: <span class="ruby-comment cmt"># makes them false so we'll skip this gem if any excludes are found</span>
|
34
|
+
121: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">check</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">name</span>,<span class="ruby-identifier">test</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">test</span>}).<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
35
|
+
122: <span class="ruby-comment cmt"># looks like no needs were set to false, so it's good</span>
|
36
|
+
123: <span class="ruby-identifier">require</span> <span class="ruby-node">"#{gem.name}/init"</span>
|
37
|
+
124: <span class="ruby-ivar">@gems</span>[<span class="ruby-identifier">gem</span>.<span class="ruby-identifier">name</span>] = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">Gem</span>.<span class="ruby-identifier">dir</span>, <span class="ruby-value str">"gems"</span>, <span class="ruby-node">"#{gem.name}-#{gem.version}"</span>)
|
38
|
+
125: <span class="ruby-keyword kw">end</span>
|
39
|
+
126: <span class="ruby-keyword kw">end</span>
|
40
|
+
127:
|
41
|
+
128: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
42
|
+
129: <span class="ruby-keyword kw">end</span></pre>
|
42
43
|
</body>
|
43
44
|
</html>
|
@@ -10,10 +10,10 @@
|
|
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
|
-
|
13
|
+
<pre> <span class="ruby-comment cmt"># File lib/gem_plugin.rb, line 135</span>
|
14
|
+
135: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">register</span>(<span class="ruby-identifier">category</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">klass</span>)
|
15
|
+
136: <span class="ruby-ivar">@plugins</span>[<span class="ruby-identifier">category</span>] <span class="ruby-operator">||=</span> {}
|
16
|
+
137: <span class="ruby-ivar">@plugins</span>[<span class="ruby-identifier">category</span>][<span class="ruby-identifier">name</span>.<span class="ruby-identifier">downcase</span>] = <span class="ruby-identifier">klass</span>
|
17
|
+
138: <span class="ruby-keyword kw">end</span></pre>
|
18
18
|
</body>
|
19
19
|
</html>
|