genosaurus 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/classes/Genosaurus.html +130 -123
- data/doc/created.rid +1 -1
- data/doc/files/lib/genosaurus_rb.html +1 -1
- data/lib/genosaurus.rb +7 -0
- data/test/genosaurus_spec.rb +95 -0
- data/test/lib/many_requires_generator/many_requires_generator.rb +4 -0
- data/test/spec.opts +2 -0
- data/test/{test_helper.rb → spec_helper.rb} +4 -6
- metadata +7 -4
- data/test/genosaurus_test.rb +0 -94
data/doc/classes/Genosaurus.html
CHANGED
@@ -153,22 +153,29 @@ initialization.
|
|
153
153
|
<pre>
|
154
154
|
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 35</span>
|
155
155
|
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
|
156
|
-
36: <span class="ruby-
|
157
|
-
37:
|
158
|
-
38: <span class="ruby-identifier">
|
159
|
-
39:
|
160
|
-
40:
|
161
|
-
41:
|
162
|
-
42: <span class="ruby-
|
163
|
-
43: <span class="ruby-ivar">@
|
164
|
-
44: <span class="ruby-identifier"
|
165
|
-
45: <span class="ruby-
|
166
|
-
46:
|
167
|
-
47:
|
168
|
-
48:
|
169
|
-
49: <span class="ruby-keyword kw">
|
170
|
-
50: <span class="ruby-
|
171
|
-
51:
|
156
|
+
36: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
157
|
+
37: <span class="ruby-identifier">opts</span> = [<span class="ruby-identifier">options</span>].<span class="ruby-identifier">flatten</span>
|
158
|
+
38: <span class="ruby-identifier">options</span> = {}
|
159
|
+
39: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">required_params</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
160
|
+
40: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">p</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">i</span>]
|
161
|
+
41: <span class="ruby-keyword kw">end</span>
|
162
|
+
42: <span class="ruby-keyword kw">end</span>
|
163
|
+
43: <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>
|
164
|
+
44: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">required_params</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
165
|
+
45: <span class="ruby-identifier">raise</span> <span class="ruby-operator">::</span><span class="ruby-constant">ArgumentError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"The required parameter '#{p.to_s.upcase}' is missing for this generator!"</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">param</span>(<span class="ruby-identifier">p</span>)
|
166
|
+
46: <span class="ruby-keyword kw">end</span>
|
167
|
+
47: <span class="ruby-ivar">@generator_name</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>
|
168
|
+
48: <span class="ruby-ivar">@generator_name_underscore</span> = <span class="ruby-ivar">@generator_name</span>.<span class="ruby-identifier">underscore</span> <span class="ruby-comment cmt">#String::Style.underscore(@generator_name)#.underscore</span>
|
169
|
+
49: <span class="ruby-ivar">@templates_directory_path</span> = <span class="ruby-keyword kw">nil</span>
|
170
|
+
50: <span class="ruby-ivar">@manifest_path</span> = <span class="ruby-keyword kw">nil</span>
|
171
|
+
51: <span class="ruby-identifier">$"</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
|
172
|
+
52: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/#{@generator_name_underscore}\.rb$/</span>)
|
173
|
+
53: <span class="ruby-ivar">@templates_directory_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">f</span>), <span class="ruby-value str">"templates"</span>)
|
174
|
+
54: <span class="ruby-ivar">@manifest_path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">f</span>), <span class="ruby-value str">"manifest.yml"</span>)
|
175
|
+
55: <span class="ruby-keyword kw">end</span>
|
176
|
+
56: <span class="ruby-keyword kw">end</span>
|
177
|
+
57: <span class="ruby-identifier">setup</span>
|
178
|
+
58: <span class="ruby-keyword kw">end</span>
|
172
179
|
</pre>
|
173
180
|
</div>
|
174
181
|
</div>
|
@@ -191,11 +198,11 @@ Used to define arguments that are required by the generator.
|
|
191
198
|
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
192
199
|
<div class="method-source-code" id="M000009-source">
|
193
200
|
<pre>
|
194
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
201
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 121</span>
|
202
|
+
121: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">require_param</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
203
|
+
122: <span class="ruby-identifier">required_params</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">args</span>
|
204
|
+
123: <span class="ruby-identifier">required_params</span>.<span class="ruby-identifier">flatten!</span>
|
205
|
+
124: <span class="ruby-keyword kw">end</span>
|
199
206
|
</pre>
|
200
207
|
</div>
|
201
208
|
</div>
|
@@ -218,10 +225,10 @@ Returns the <a href="Genosaurus.html#M000010">required_params</a> array.
|
|
218
225
|
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
219
226
|
<div class="method-source-code" id="M000010-source">
|
220
227
|
<pre>
|
221
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
222
|
-
|
223
|
-
|
224
|
-
|
228
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 127</span>
|
229
|
+
127: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">required_params</span>
|
230
|
+
128: <span class="ruby-ivar">@required_params</span> <span class="ruby-operator">||=</span> []
|
231
|
+
129: <span class="ruby-keyword kw">end</span>
|
225
232
|
</pre>
|
226
233
|
</div>
|
227
234
|
</div>
|
@@ -280,9 +287,9 @@ generators.
|
|
280
287
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
281
288
|
<div class="method-source-code" id="M000007-source">
|
282
289
|
<pre>
|
283
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
284
|
-
|
285
|
-
|
290
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 87</span>
|
291
|
+
87: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_generate</span>
|
292
|
+
88: <span class="ruby-keyword kw">end</span>
|
286
293
|
</pre>
|
287
294
|
</div>
|
288
295
|
</div>
|
@@ -307,9 +314,9 @@ href="Genosaurus.html#M000001">run</a>.
|
|
307
314
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
308
315
|
<div class="method-source-code" id="M000006-source">
|
309
316
|
<pre>
|
310
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
311
|
-
|
312
|
-
|
317
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 82</span>
|
318
|
+
82: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before_generate</span>
|
319
|
+
83: <span class="ruby-keyword kw">end</span>
|
313
320
|
</pre>
|
314
321
|
</div>
|
315
322
|
</div>
|
@@ -329,12 +336,12 @@ href="Genosaurus.html#M000001">run</a>.
|
|
329
336
|
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
330
337
|
<div class="method-source-code" id="M000014-source">
|
331
338
|
<pre>
|
332
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
339
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 162</span>
|
340
|
+
162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">copy</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-identifier">output_file</span>, <span class="ruby-identifier">options</span> = <span class="ruby-ivar">@options</span>)
|
341
|
+
163: <span class="ruby-identifier">output_file</span> = <span class="ruby-identifier">template_copy_common</span>(<span class="ruby-identifier">output_file</span>, <span class="ruby-identifier">options</span>)
|
342
|
+
164: <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">cp</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-identifier">output_file</span>)
|
343
|
+
165: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Copied: #{output_file}"</span>
|
344
|
+
166: <span class="ruby-keyword kw">end</span>
|
338
345
|
</pre>
|
339
346
|
</div>
|
340
347
|
</div>
|
@@ -357,18 +364,18 @@ Creates the specified <a href="Genosaurus.html#M000013">directory</a>.
|
|
357
364
|
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
358
365
|
<div class="method-source-code" id="M000013-source">
|
359
366
|
<pre>
|
360
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
367
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 150</span>
|
368
|
+
150: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">directory</span>(<span class="ruby-identifier">output_dir</span>, <span class="ruby-identifier">options</span> = <span class="ruby-ivar">@options</span>)
|
369
|
+
151: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$genosaurus_output_directory</span>
|
370
|
+
152: <span class="ruby-identifier">output_dir</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">$genosaurus_output_directory</span>, <span class="ruby-identifier">output_dir</span>)
|
371
|
+
153: <span class="ruby-keyword kw">end</span>
|
372
|
+
154: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">output_dir</span>)
|
373
|
+
155: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Exists: #{output_dir}"</span>
|
374
|
+
156: <span class="ruby-keyword kw">return</span>
|
375
|
+
157: <span class="ruby-keyword kw">end</span>
|
376
|
+
158: <span class="ruby-identifier">mkdir_p</span>(<span class="ruby-identifier">output_dir</span>)
|
377
|
+
159: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Created: #{output_dir}"</span>
|
378
|
+
160: <span class="ruby-keyword kw">end</span>
|
372
379
|
</pre>
|
373
380
|
</div>
|
374
381
|
</div>
|
@@ -391,23 +398,23 @@ This does the dirty work of generation.
|
|
391
398
|
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
392
399
|
<div class="method-source-code" id="M000015-source">
|
393
400
|
<pre>
|
394
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
401
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 169</span>
|
402
|
+
169: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate</span>
|
403
|
+
170: <span class="ruby-identifier">generate_callbacks</span> <span class="ruby-keyword kw">do</span>
|
404
|
+
171: <span class="ruby-identifier">manifest</span>.<span class="ruby-identifier">each_value</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">info</span><span class="ruby-operator">|</span>
|
405
|
+
172: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">info</span>[<span class="ruby-value str">"type"</span>]
|
406
|
+
173: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"file"</span>
|
407
|
+
174: <span class="ruby-identifier">template</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">"template_path"</span>]).<span class="ruby-identifier">read</span>, <span class="ruby-identifier">info</span>[<span class="ruby-value str">"output_path"</span>])
|
408
|
+
175: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"directory"</span>
|
409
|
+
176: <span class="ruby-identifier">directory</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">"output_path"</span>])
|
410
|
+
177: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">"copy"</span>
|
411
|
+
178: <span class="ruby-identifier">copy</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">"template_path"</span>], <span class="ruby-identifier">info</span>[<span class="ruby-value str">"output_path"</span>])
|
412
|
+
179: <span class="ruby-keyword kw">else</span>
|
413
|
+
180: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown 'type': #{info["type"]}!"</span>
|
414
|
+
181: <span class="ruby-keyword kw">end</span>
|
415
|
+
182: <span class="ruby-keyword kw">end</span>
|
416
|
+
183: <span class="ruby-keyword kw">end</span>
|
417
|
+
184: <span class="ruby-keyword kw">end</span>
|
411
418
|
</pre>
|
412
419
|
</div>
|
413
420
|
</div>
|
@@ -438,32 +445,32 @@ href="Genosaurus.html#M000003">templates_directory_path</a>.
|
|
438
445
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
439
446
|
<div class="method-source-code" id="M000008-source">
|
440
447
|
<pre>
|
441
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
448
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 94</span>
|
449
|
+
94: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">manifest</span>
|
450
|
+
95: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">templates_directory_path</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">manifest_path</span>.<span class="ruby-identifier">nil?</span>
|
451
|
+
96: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Unable to dynamically figure out your templates_directory_path and manifest_path!\nPlease implement these methods and let Genosaurus know where to find these things. Thanks."</span>
|
452
|
+
97: <span class="ruby-keyword kw">end</span>
|
453
|
+
98: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">manifest_path</span>)
|
454
|
+
99: <span class="ruby-comment cmt"># run using the yml file</span>
|
455
|
+
100: <span class="ruby-identifier">template</span> = <span class="ruby-constant">ERB</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">manifest_path</span>).<span class="ruby-identifier">read</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-value str">"->"</span>)
|
456
|
+
101: <span class="ruby-identifier">man</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">template</span>.<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>))
|
457
|
+
102: <span class="ruby-keyword kw">else</span>
|
458
|
+
103: <span class="ruby-identifier">files</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">templates_directory_path</span>, <span class="ruby-value str">"**/*.template"</span>))
|
459
|
+
104: <span class="ruby-identifier">man</span> = {}
|
460
|
+
105: <span class="ruby-identifier">files</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
461
|
+
106: <span class="ruby-identifier">output_path</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-identifier">templates_directory_path</span>, <span class="ruby-value str">""</span>)
|
462
|
+
107: <span class="ruby-identifier">output_path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">".template"</span>, <span class="ruby-value str">""</span>)
|
463
|
+
108: <span class="ruby-identifier">output_path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">""</span>)
|
464
|
+
109: <span class="ruby-identifier">man</span>[<span class="ruby-node">"template_#{i+1}"</span>] = {
|
465
|
+
110: <span class="ruby-value str">"type"</span> =<span class="ruby-operator">></span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">f</span>) <span class="ruby-operator">?</span> <span class="ruby-value str">"directory"</span> <span class="ruby-operator">:</span> <span class="ruby-value str">"file"</span>,
|
466
|
+
111: <span class="ruby-value str">"template_path"</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">f</span>,
|
467
|
+
112: <span class="ruby-value str">"output_path"</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">Eruby</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">output_path</span>, <span class="ruby-identifier">:pattern</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'% %'</span>).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>)
|
468
|
+
113: }
|
469
|
+
114: <span class="ruby-keyword kw">end</span>
|
470
|
+
115: <span class="ruby-keyword kw">end</span>
|
471
|
+
116: <span class="ruby-comment cmt"># puts man.inspect</span>
|
472
|
+
117: <span class="ruby-identifier">man</span>
|
473
|
+
118: <span class="ruby-keyword kw">end</span>
|
467
474
|
</pre>
|
468
475
|
</div>
|
469
476
|
</div>
|
@@ -493,10 +500,10 @@ return the correct path.
|
|
493
500
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
494
501
|
<div class="method-source-code" id="M000004-source">
|
495
502
|
<pre>
|
496
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
497
|
-
|
498
|
-
|
499
|
-
|
503
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 72</span>
|
504
|
+
72: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">manifest_path</span>
|
505
|
+
73: <span class="ruby-ivar">@manifest_path</span>
|
506
|
+
74: <span class="ruby-keyword kw">end</span>
|
500
507
|
</pre>
|
501
508
|
</div>
|
502
509
|
</div>
|
@@ -516,12 +523,12 @@ return the correct path.
|
|
516
523
|
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
517
524
|
<div class="method-source-code" id="M000016-source">
|
518
525
|
<pre>
|
519
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
526
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 186</span>
|
527
|
+
186: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
528
|
+
187: <span class="ruby-identifier">p</span> = <span class="ruby-identifier">param</span>(<span class="ruby-identifier">sym</span>)
|
529
|
+
188: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">p</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">p</span>
|
530
|
+
189: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">sym</span>)
|
531
|
+
190: <span class="ruby-keyword kw">end</span>
|
525
532
|
</pre>
|
526
533
|
</div>
|
527
534
|
</div>
|
@@ -544,10 +551,10 @@ Returns a parameter from the initial Hash of parameters.
|
|
544
551
|
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
545
552
|
<div class="method-source-code" id="M000011-source">
|
546
553
|
<pre>
|
547
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
548
|
-
|
549
|
-
|
550
|
-
|
554
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 132</span>
|
555
|
+
132: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">param</span>(<span class="ruby-identifier">key</span>)
|
556
|
+
133: (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>] <span class="ruby-operator">||=</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">upcase</span>])
|
557
|
+
134: <span class="ruby-keyword kw">end</span>
|
551
558
|
</pre>
|
552
559
|
</div>
|
553
560
|
</div>
|
@@ -571,10 +578,10 @@ href="Genosaurus.html#M000005">setup</a> work needed by the generator.
|
|
571
578
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
572
579
|
<div class="method-source-code" id="M000005-source">
|
573
580
|
<pre>
|
574
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
575
|
-
|
576
|
-
|
577
|
-
|
581
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 77</span>
|
582
|
+
77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">setup</span>
|
583
|
+
78: <span class="ruby-comment cmt"># does nothing, unless overridden in subclass.</span>
|
584
|
+
79: <span class="ruby-keyword kw">end</span>
|
578
585
|
</pre>
|
579
586
|
</div>
|
580
587
|
</div>
|
@@ -599,15 +606,15 @@ like to force the writing of the file, use the :force => true option.
|
|
599
606
|
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
600
607
|
<div class="method-source-code" id="M000012-source">
|
601
608
|
<pre>
|
602
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
609
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 140</span>
|
610
|
+
140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">template</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-identifier">output_file</span>, <span class="ruby-identifier">options</span> = <span class="ruby-ivar">@options</span>)
|
611
|
+
141: <span class="ruby-identifier">output_file</span> = <span class="ruby-identifier">template_copy_common</span>(<span class="ruby-identifier">output_file</span>, <span class="ruby-identifier">options</span>)
|
612
|
+
142: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">output_file</span>.<span class="ruby-identifier">nil?</span>
|
613
|
+
143: <span class="ruby-comment cmt"># File.open(output_file, "w") {|f| f.puts ERB.new(File.open(input_file).read, nil, "->").result(binding)}</span>
|
614
|
+
144: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">output_file</span>, <span class="ruby-value str">"w"</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">puts</span> <span class="ruby-constant">ERB</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-value str">"->"</span>).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>)}
|
615
|
+
145: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Wrote: #{output_file}"</span>
|
616
|
+
146: <span class="ruby-keyword kw">end</span>
|
617
|
+
147: <span class="ruby-keyword kw">end</span>
|
611
618
|
</pre>
|
612
619
|
</div>
|
613
620
|
</div>
|
@@ -636,10 +643,10 @@ return the correct path.
|
|
636
643
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
637
644
|
<div class="method-source-code" id="M000003-source">
|
638
645
|
<pre>
|
639
|
-
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line
|
640
|
-
|
641
|
-
|
642
|
-
|
646
|
+
<span class="ruby-comment cmt"># File lib/genosaurus.rb, line 64</span>
|
647
|
+
64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">templates_directory_path</span>
|
648
|
+
65: <span class="ruby-ivar">@templates_directory_path</span>
|
649
|
+
66: <span class="ruby-keyword kw">end</span>
|
643
650
|
</pre>
|
644
651
|
</div>
|
645
652
|
</div>
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Fri, 29 Aug 2008 14:56:58 -0400
|
data/lib/genosaurus.rb
CHANGED
@@ -33,6 +33,13 @@ class Genosaurus
|
|
33
33
|
# Takes any options needed for this generator. If the generator requires any parameters an ArgumentError exception will be
|
34
34
|
# raised if those parameters are found in the options Hash. The setup method is called at the end of the initialization.
|
35
35
|
def initialize(options = {})
|
36
|
+
unless options.is_a?(Hash)
|
37
|
+
opts = [options].flatten
|
38
|
+
options = {}
|
39
|
+
self.class.required_params.each_with_index do |p, i|
|
40
|
+
options[p.to_s] = opts[i]
|
41
|
+
end
|
42
|
+
end
|
36
43
|
@options = options
|
37
44
|
self.class.required_params.each do |p|
|
38
45
|
raise ::ArgumentError.new("The required parameter '#{p.to_s.upcase}' is missing for this generator!") unless param(p)
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe Genosaurus do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
clean_tmp
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
clean_tmp
|
11
|
+
end
|
12
|
+
|
13
|
+
it "test_simple_implied_generator" do
|
14
|
+
hello_file = File.join($genosaurus_output_directory, "hello_world.rb")
|
15
|
+
goodbye_file = File.join($genosaurus_output_directory, "goodbye_world.rb")
|
16
|
+
File.should_not be_exists(hello_file)
|
17
|
+
File.should_not be_exists(goodbye_file)
|
18
|
+
@generator = HelloGoodbyeGenerator.run("name" => "Mark")
|
19
|
+
File.should be_exists(hello_file)
|
20
|
+
File.should be_exists(goodbye_file)
|
21
|
+
File.read(hello_file).should == "Hello Mark\n"
|
22
|
+
File.read(goodbye_file).should == "Goodbye cruel world! Love, Mark\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "test_simple_implied_manifest" do
|
26
|
+
@generator = HelloGoodbyeGenerator.new("name" => "Mark")
|
27
|
+
manifest = @generator.manifest
|
28
|
+
manifest.should be_is_a(Hash)
|
29
|
+
manifest.size.should == 2
|
30
|
+
temp1 = manifest["template_1"]
|
31
|
+
temp1["type"].should == "file"
|
32
|
+
temp1["template_path"].should == File.join(File.dirname(__FILE__), "lib", "hello_goodbye_generator", "templates", "goodbye_world.rb.template")
|
33
|
+
temp1["output_path"].should == "goodbye_world.rb"
|
34
|
+
temp2 = manifest["template_2"]
|
35
|
+
temp2["type"].should == "file"
|
36
|
+
temp2["template_path"].should == File.join(File.dirname(__FILE__), "lib", "hello_goodbye_generator", "templates", "hello_world.rb.template")
|
37
|
+
temp2["output_path"].should == "hello_world.rb"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should take a hash of options and raise an exception for the required ones" do
|
41
|
+
lambda { HelloGoodbyeGenerator.new }.should raise_error(ArgumentError)
|
42
|
+
@generator = HelloGoodbyeGenerator.new("name" => :foo)
|
43
|
+
@generator.should_not be_nil
|
44
|
+
@generator.param(:name).should == :foo
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should take an array of options and raise an exception for the required ones" do
|
48
|
+
lambda { HelloGoodbyeGenerator.new }.should raise_error(ArgumentError)
|
49
|
+
@generator = HelloGoodbyeGenerator.new(:foo)
|
50
|
+
@generator.should_not be_nil
|
51
|
+
@generator.param(:name).should == :foo
|
52
|
+
end
|
53
|
+
|
54
|
+
it "test_complex_implied_generator" do
|
55
|
+
album_dir = File.join($genosaurus_output_directory, "beatles", "albums")
|
56
|
+
lyrics_file = File.join($genosaurus_output_directory, "beatles", "lyrics", "i_am_the_walrus.txt")
|
57
|
+
File.should_not be_exists(album_dir)
|
58
|
+
File.should_not be_exists(lyrics_file)
|
59
|
+
@generator = IAmTheWalrusGenerator.run("name" => "i_am_the_walrus")
|
60
|
+
File.should be_exists(album_dir)
|
61
|
+
File.should be_exists(lyrics_file)
|
62
|
+
File.read(lyrics_file).should == "Lyrics for: I Am The Walrus\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "test_simple_yml_manifest" do
|
66
|
+
@generator = StrawberryFieldsGenerator.new
|
67
|
+
manifest = @generator.manifest
|
68
|
+
manifest.should be_is_a(Hash)
|
69
|
+
manifest.size.should == 2
|
70
|
+
info = manifest["directory_1"]
|
71
|
+
info["output_path"].should == "beatles/albums/magical_mystery_tour"
|
72
|
+
info["type"].should == "directory"
|
73
|
+
info = manifest["template_1"]
|
74
|
+
info["template_path"].should == File.join(File.dirname(__FILE__), "lib", "strawberry_fields_generator", "templates", "fields.txt")
|
75
|
+
info["output_path"].should == "beatles/albums/magical_mystery_tour/lyrics/strawberry_fields_forever.lyrics"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "test_directory" do
|
79
|
+
@generator = DirectoryGenerator.run
|
80
|
+
File.should be_exists(File.join($genosaurus_output_directory, "months", "january"))
|
81
|
+
File.should be_exists(File.join($genosaurus_output_directory, "months", "february"))
|
82
|
+
File.should be_exists(File.join($genosaurus_output_directory, "months", "march"))
|
83
|
+
end
|
84
|
+
|
85
|
+
it "test_copy" do
|
86
|
+
File.should_not be_exists(File.join($genosaurus_output_directory, "hw.txt"))
|
87
|
+
@generator = CopyMachineGenerator.run
|
88
|
+
File.should be_exists(File.join($genosaurus_output_directory, "hw.txt"))
|
89
|
+
end
|
90
|
+
|
91
|
+
def clean_tmp
|
92
|
+
FileUtils.rm_rf($genosaurus_output_directory, :verbose => false)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/test/spec.opts
ADDED
@@ -1,5 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec'
|
3
|
+
require 'spec'
|
4
|
+
|
3
5
|
require File.join(File.dirname(__FILE__), "..", "lib", "genosaurus")
|
4
6
|
# place common methods, assertions, and other type things in this file so
|
5
7
|
# other tests will have access to them.
|
@@ -18,7 +20,3 @@ class String
|
|
18
20
|
self.gsub(/\b\w/) {|s| s.upcase}
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
22
|
-
class Test::Unit::TestCase
|
23
|
-
|
24
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genosaurus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-29 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -71,7 +71,7 @@ signing_key:
|
|
71
71
|
specification_version: 2
|
72
72
|
summary: genosaurus
|
73
73
|
test_files:
|
74
|
-
- test/
|
74
|
+
- test/genosaurus_spec.rb
|
75
75
|
- test/lib
|
76
76
|
- test/lib/copy_machine_generator
|
77
77
|
- test/lib/copy_machine_generator/copy_machine_generator.rb
|
@@ -97,9 +97,12 @@ test_files:
|
|
97
97
|
- test/lib/i_am_the_walrus_generator/templates/beatles/albums.template
|
98
98
|
- test/lib/i_am_the_walrus_generator/templates/beatles/lyrics
|
99
99
|
- test/lib/i_am_the_walrus_generator/templates/beatles/lyrics/%=name%.txt.template
|
100
|
+
- test/lib/many_requires_generator
|
101
|
+
- test/lib/many_requires_generator/many_requires_generator.rb
|
100
102
|
- test/lib/strawberry_fields_generator
|
101
103
|
- test/lib/strawberry_fields_generator/manifest.yml
|
102
104
|
- test/lib/strawberry_fields_generator/strawberry_fields_generator.rb
|
103
105
|
- test/lib/strawberry_fields_generator/templates
|
104
106
|
- test/lib/strawberry_fields_generator/templates/fields.txt
|
105
|
-
- test/
|
107
|
+
- test/spec.opts
|
108
|
+
- test/spec_helper.rb
|
data/test/genosaurus_test.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class GenosaurusBaseTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_simple_implied_generator
|
6
|
-
hello_file = File.join($genosaurus_output_directory, "hello_world.rb")
|
7
|
-
goodbye_file = File.join($genosaurus_output_directory, "goodbye_world.rb")
|
8
|
-
assert !File.exists?(hello_file)
|
9
|
-
assert !File.exists?(goodbye_file)
|
10
|
-
@generator = HelloGoodbyeGenerator.run("name" => "Mark")
|
11
|
-
assert File.exists?(hello_file)
|
12
|
-
assert File.exists?(goodbye_file)
|
13
|
-
File.open(hello_file, "r") do |f|
|
14
|
-
assert_equal "Hello Mark\n", f.read
|
15
|
-
end
|
16
|
-
File.open(goodbye_file, "r") do |f|
|
17
|
-
assert_equal "Goodbye cruel world! Love, Mark\n", f.read
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_simple_implied_manifest
|
22
|
-
@generator = HelloGoodbyeGenerator.new("name" => "Mark")
|
23
|
-
manifest = @generator.manifest
|
24
|
-
assert manifest.is_a?(Hash)
|
25
|
-
assert_equal 2, manifest.size
|
26
|
-
temp1 = manifest["template_1"]
|
27
|
-
assert_equal "file", temp1["type"]
|
28
|
-
assert_equal File.join(File.dirname(__FILE__), "lib", "hello_goodbye_generator", "templates", "goodbye_world.rb.template"), temp1["template_path"]
|
29
|
-
assert_equal "goodbye_world.rb", temp1["output_path"]
|
30
|
-
temp2 = manifest["template_2"]
|
31
|
-
assert_equal "file", temp2["type"]
|
32
|
-
assert_equal File.join(File.dirname(__FILE__), "lib", "hello_goodbye_generator", "templates", "hello_world.rb.template"), temp2["template_path"]
|
33
|
-
assert_equal "hello_world.rb", temp2["output_path"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_require_param
|
37
|
-
assert_raise(ArgumentError) { HelloGoodbyeGenerator.new }
|
38
|
-
@generator = HelloGoodbyeGenerator.new("name" => :foo)
|
39
|
-
assert_not_nil @generator
|
40
|
-
assert_equal :foo, @generator.param(:name)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_complex_implied_generator
|
44
|
-
album_dir = File.join($genosaurus_output_directory, "beatles", "albums")
|
45
|
-
lyrics_file = File.join($genosaurus_output_directory, "beatles", "lyrics", "i_am_the_walrus.txt")
|
46
|
-
assert !File.exists?(album_dir)
|
47
|
-
assert !File.exists?(lyrics_file)
|
48
|
-
@generator = IAmTheWalrusGenerator.run("name" => "i_am_the_walrus")
|
49
|
-
assert File.exists?(album_dir)
|
50
|
-
assert File.exists?(lyrics_file)
|
51
|
-
File.open(lyrics_file, "r") do |f|
|
52
|
-
assert_equal "Lyrics for: I Am The Walrus\n", f.read
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_simple_yml_manifest
|
57
|
-
@generator = StrawberryFieldsGenerator.new
|
58
|
-
manifest = @generator.manifest
|
59
|
-
assert manifest.is_a?(Hash)
|
60
|
-
assert_equal 2, manifest.size
|
61
|
-
info = manifest["directory_1"]
|
62
|
-
assert_equal "beatles/albums/magical_mystery_tour", info["output_path"]
|
63
|
-
assert_equal "directory", info["type"]
|
64
|
-
info = manifest["template_1"]
|
65
|
-
assert_equal File.join(File.dirname(__FILE__), "lib", "strawberry_fields_generator", "templates", "fields.txt"), info["template_path"]
|
66
|
-
assert_equal "beatles/albums/magical_mystery_tour/lyrics/strawberry_fields_forever.lyrics", info["output_path"]
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_directory
|
70
|
-
@generator = DirectoryGenerator.run
|
71
|
-
assert File.exists?(File.join($genosaurus_output_directory, "months", "january"))
|
72
|
-
assert File.exists?(File.join($genosaurus_output_directory, "months", "february"))
|
73
|
-
assert File.exists?(File.join($genosaurus_output_directory, "months", "march"))
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_copy
|
77
|
-
assert !File.exists?(File.join($genosaurus_output_directory, "hw.txt"))
|
78
|
-
@generator = CopyMachineGenerator.run
|
79
|
-
assert File.exists?(File.join($genosaurus_output_directory, "hw.txt"))
|
80
|
-
end
|
81
|
-
|
82
|
-
def clean_tmp
|
83
|
-
FileUtils.rm_rf($genosaurus_output_directory, :verbose => false)
|
84
|
-
end
|
85
|
-
|
86
|
-
def setup
|
87
|
-
clean_tmp
|
88
|
-
end
|
89
|
-
|
90
|
-
def teardown
|
91
|
-
clean_tmp
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|