genosaurus 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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-ivar">@options</span> = <span class="ruby-identifier">options</span>
157
- 37: <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>
158
- 38: <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">&quot;The required parameter '#{p.to_s.upcase}' is missing for this generator!&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">param</span>(<span class="ruby-identifier">p</span>)
159
- 39: <span class="ruby-keyword kw">end</span>
160
- 40: <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>
161
- 41: <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>
162
- 42: <span class="ruby-ivar">@templates_directory_path</span> = <span class="ruby-keyword kw">nil</span>
163
- 43: <span class="ruby-ivar">@manifest_path</span> = <span class="ruby-keyword kw">nil</span>
164
- 44: <span class="ruby-identifier">$&quot;</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>
165
- 45: <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>)
166
- 46: <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">&quot;templates&quot;</span>)
167
- 47: <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">&quot;manifest.yml&quot;</span>)
168
- 48: <span class="ruby-keyword kw">end</span>
169
- 49: <span class="ruby-keyword kw">end</span>
170
- 50: <span class="ruby-identifier">setup</span>
171
- 51: <span class="ruby-keyword kw">end</span>
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">&quot;The required parameter '#{p.to_s.upcase}' is missing for this generator!&quot;</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">$&quot;</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">&quot;templates&quot;</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">&quot;manifest.yml&quot;</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 114</span>
195
- 114: <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>)
196
- 115: <span class="ruby-identifier">required_params</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">args</span>
197
- 116: <span class="ruby-identifier">required_params</span>.<span class="ruby-identifier">flatten!</span>
198
- 117: <span class="ruby-keyword kw">end</span>
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">&lt;&lt;</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 120</span>
222
- 120: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">required_params</span>
223
- 121: <span class="ruby-ivar">@required_params</span> <span class="ruby-operator">||=</span> []
224
- 122: <span class="ruby-keyword kw">end</span>
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 80</span>
284
- 80: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_generate</span>
285
- 81: <span class="ruby-keyword kw">end</span>
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 75</span>
311
- 75: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before_generate</span>
312
- 76: <span class="ruby-keyword kw">end</span>
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 155</span>
333
- 155: <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>)
334
- 156: <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>)
335
- 157: <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>)
336
- 158: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Copied: #{output_file}&quot;</span>
337
- 159: <span class="ruby-keyword kw">end</span>
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">&quot;Copied: #{output_file}&quot;</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 143</span>
361
- 143: <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>)
362
- 144: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$genosaurus_output_directory</span>
363
- 145: <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>)
364
- 146: <span class="ruby-keyword kw">end</span>
365
- 147: <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>)
366
- 148: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Exists: #{output_dir}&quot;</span>
367
- 149: <span class="ruby-keyword kw">return</span>
368
- 150: <span class="ruby-keyword kw">end</span>
369
- 151: <span class="ruby-identifier">mkdir_p</span>(<span class="ruby-identifier">output_dir</span>)
370
- 152: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Created: #{output_dir}&quot;</span>
371
- 153: <span class="ruby-keyword kw">end</span>
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">&quot;Exists: #{output_dir}&quot;</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">&quot;Created: #{output_dir}&quot;</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 162</span>
395
- 162: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate</span>
396
- 163: <span class="ruby-identifier">generate_callbacks</span> <span class="ruby-keyword kw">do</span>
397
- 164: <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>
398
- 165: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;type&quot;</span>]
399
- 166: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;file&quot;</span>
400
- 167: <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">&quot;template_path&quot;</span>]).<span class="ruby-identifier">read</span>, <span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;output_path&quot;</span>])
401
- 168: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;directory&quot;</span>
402
- 169: <span class="ruby-identifier">directory</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;output_path&quot;</span>])
403
- 170: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;copy&quot;</span>
404
- 171: <span class="ruby-identifier">copy</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;template_path&quot;</span>], <span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;output_path&quot;</span>])
405
- 172: <span class="ruby-keyword kw">else</span>
406
- 173: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Unknown 'type': #{info[&quot;type&quot;]}!&quot;</span>
407
- 174: <span class="ruby-keyword kw">end</span>
408
- 175: <span class="ruby-keyword kw">end</span>
409
- 176: <span class="ruby-keyword kw">end</span>
410
- 177: <span class="ruby-keyword kw">end</span>
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">&quot;type&quot;</span>]
406
+ 173: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;file&quot;</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">&quot;template_path&quot;</span>]).<span class="ruby-identifier">read</span>, <span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;output_path&quot;</span>])
408
+ 175: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;directory&quot;</span>
409
+ 176: <span class="ruby-identifier">directory</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;output_path&quot;</span>])
410
+ 177: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;copy&quot;</span>
411
+ 178: <span class="ruby-identifier">copy</span>(<span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;template_path&quot;</span>], <span class="ruby-identifier">info</span>[<span class="ruby-value str">&quot;output_path&quot;</span>])
412
+ 179: <span class="ruby-keyword kw">else</span>
413
+ 180: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Unknown 'type': #{info[&quot;type&quot;]}!&quot;</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 87</span>
442
- 87: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">manifest</span>
443
- 88: <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>
444
- 89: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;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.&quot;</span>
445
- 90: <span class="ruby-keyword kw">end</span>
446
- 91: <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>)
447
- 92: <span class="ruby-comment cmt"># run using the yml file</span>
448
- 93: <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">&quot;-&gt;&quot;</span>)
449
- 94: <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>))
450
- 95: <span class="ruby-keyword kw">else</span>
451
- 96: <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">&quot;**/*.template&quot;</span>))
452
- 97: <span class="ruby-identifier">man</span> = {}
453
- 98: <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>
454
- 99: <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">&quot;&quot;</span>)
455
- 100: <span class="ruby-identifier">output_path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">&quot;.template&quot;</span>, <span class="ruby-value str">&quot;&quot;</span>)
456
- 101: <span class="ruby-identifier">output_path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^\//</span>, <span class="ruby-value str">&quot;&quot;</span>)
457
- 102: <span class="ruby-identifier">man</span>[<span class="ruby-node">&quot;template_#{i+1}&quot;</span>] = {
458
- 103: <span class="ruby-value str">&quot;type&quot;</span> =<span class="ruby-operator">&gt;</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">&quot;directory&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;file&quot;</span>,
459
- 104: <span class="ruby-value str">&quot;template_path&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">f</span>,
460
- 105: <span class="ruby-value str">&quot;output_path&quot;</span> =<span class="ruby-operator">&gt;</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">&gt;</span> <span class="ruby-value str">'% %'</span>).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>)
461
- 106: }
462
- 107: <span class="ruby-keyword kw">end</span>
463
- 108: <span class="ruby-keyword kw">end</span>
464
- 109: <span class="ruby-comment cmt"># puts man.inspect</span>
465
- 110: <span class="ruby-identifier">man</span>
466
- 111: <span class="ruby-keyword kw">end</span>
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">&quot;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.&quot;</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">&quot;-&gt;&quot;</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">&quot;**/*.template&quot;</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">&quot;&quot;</span>)
462
+ 107: <span class="ruby-identifier">output_path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">&quot;.template&quot;</span>, <span class="ruby-value str">&quot;&quot;</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">&quot;&quot;</span>)
464
+ 109: <span class="ruby-identifier">man</span>[<span class="ruby-node">&quot;template_#{i+1}&quot;</span>] = {
465
+ 110: <span class="ruby-value str">&quot;type&quot;</span> =<span class="ruby-operator">&gt;</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">&quot;directory&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;file&quot;</span>,
466
+ 111: <span class="ruby-value str">&quot;template_path&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">f</span>,
467
+ 112: <span class="ruby-value str">&quot;output_path&quot;</span> =<span class="ruby-operator">&gt;</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">&gt;</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 65</span>
497
- 65: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">manifest_path</span>
498
- 66: <span class="ruby-ivar">@manifest_path</span>
499
- 67: <span class="ruby-keyword kw">end</span>
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 179</span>
520
- 179: <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>)
521
- 180: <span class="ruby-identifier">p</span> = <span class="ruby-identifier">param</span>(<span class="ruby-identifier">sym</span>)
522
- 181: <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>
523
- 182: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">sym</span>)
524
- 183: <span class="ruby-keyword kw">end</span>
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 125</span>
548
- 125: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">param</span>(<span class="ruby-identifier">key</span>)
549
- 126: (<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>])
550
- 127: <span class="ruby-keyword kw">end</span>
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 70</span>
575
- 70: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">setup</span>
576
- 71: <span class="ruby-comment cmt"># does nothing, unless overridden in subclass.</span>
577
- 72: <span class="ruby-keyword kw">end</span>
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 =&gt; 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 133</span>
603
- 133: <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>)
604
- 134: <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>)
605
- 135: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">output_file</span>.<span class="ruby-identifier">nil?</span>
606
- 136: <span class="ruby-comment cmt"># File.open(output_file, &quot;w&quot;) {|f| f.puts ERB.new(File.open(input_file).read, nil, &quot;-&gt;&quot;).result(binding)}</span>
607
- 137: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">output_file</span>, <span class="ruby-value str">&quot;w&quot;</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">&quot;-&gt;&quot;</span>).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>)}
608
- 138: <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Wrote: #{output_file}&quot;</span>
609
- 139: <span class="ruby-keyword kw">end</span>
610
- 140: <span class="ruby-keyword kw">end</span>
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, &quot;w&quot;) {|f| f.puts ERB.new(File.open(input_file).read, nil, &quot;-&gt;&quot;).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">&quot;w&quot;</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">&quot;-&gt;&quot;</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">&quot;Wrote: #{output_file}&quot;</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 57</span>
640
- 57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">templates_directory_path</span>
641
- 58: <span class="ruby-ivar">@templates_directory_path</span>
642
- 59: <span class="ruby-keyword kw">end</span>
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
- Mon, 04 Aug 2008 17:05:59 -0400
1
+ Fri, 29 Aug 2008 14:56:58 -0400
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Mon Aug 04 17:05:40 -0400 2008</td>
59
+ <td>Fri Aug 29 14:56:48 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
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
@@ -0,0 +1,4 @@
1
+ class ManyRequiresGenerator < Genosaurus
2
+ require_param :first_name
3
+ require_param :last_name
4
+ end
data/test/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
@@ -1,5 +1,7 @@
1
- require "test/unit"
2
- require 'fileutils'
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.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-04 00:00:00 -04:00
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/genosaurus_test.rb
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/test_helper.rb
107
+ - test/spec.opts
108
+ - test/spec_helper.rb
@@ -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