draper 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1222 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: Draper::Base
8
+
9
+ &mdash; Documentation by YARD 0.7.2
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '..';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="../_index.html">Index (B)</a> &raquo;
37
+ <span class='title'><span class='object_link'><a href="../Draper.html" title="Draper (module)">Draper</a></span></span>
38
+ &raquo;
39
+ <span class="title">Base</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Class: Draper::Base
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+ <dt class="r1">Inherits:</dt>
68
+ <dd class="r1">
69
+ <span class="inheritName">Object</span>
70
+
71
+ <ul class="fullTree">
72
+ <li>Object</li>
73
+
74
+ <li class="next">Draper::Base</li>
75
+
76
+ </ul>
77
+ <a href="#" class="inheritanceTree">show all</a>
78
+
79
+ </dd>
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ <dt class="r2 last">Defined in:</dt>
90
+ <dd class="r2 last">lib/draper/base.rb</dd>
91
+
92
+ </dl>
93
+ <div class="clear"></div>
94
+
95
+
96
+ <h2>Constant Summary</h2>
97
+
98
+ <dl class="constants">
99
+
100
+ <dt id="DEFAULT_DENIED-constant" class="">DEFAULT_DENIED =
101
+
102
+ </dt>
103
+ <dd><pre class="code"><span class='Object constant id'>Object</span><span class='dot token'>.</span><span class='new identifier id'>new</span><span class='dot token'>.</span><span class='methods identifier id'>methods</span> <span class='lshft op'>&lt;&lt;</span> <span class='symbol val'>:method_missing</span>
104
+ </pre></dd>
105
+
106
+ <dt id="FORCED_PROXY-constant" class="">FORCED_PROXY =
107
+
108
+ </dt>
109
+ <dd><pre class="code"><span class='lbrack token'>[</span><span class='symbol val'>:to_param</span><span class='rbrack token'>]</span>
110
+ </pre></dd>
111
+
112
+ </dl>
113
+
114
+
115
+
116
+ <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
117
+ <ul class="summary">
118
+
119
+ <li class="public ">
120
+ <span class="summary_signature">
121
+
122
+ <a href="#context-instance_method" title="#context (instance method)">- (Object) <strong>context</strong> </a>
123
+
124
+
125
+
126
+ </span>
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+ <span class="summary_desc"><div class='inline'><p>Returns the value of attribute context.</p>
139
+ </div></span>
140
+
141
+ </li>
142
+
143
+
144
+ <li class="public ">
145
+ <span class="summary_signature">
146
+
147
+ <a href="#model-instance_method" title="#model (instance method)">- (Object) <strong>model</strong> </a>
148
+
149
+
150
+
151
+ </span>
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+ <span class="summary_desc"><div class='inline'><p>Returns the value of attribute model.</p>
164
+ </div></span>
165
+
166
+ </li>
167
+
168
+
169
+ </ul>
170
+
171
+
172
+
173
+
174
+
175
+ <h2>
176
+ Class Method Summary
177
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
178
+ </h2>
179
+
180
+ <ul class="summary">
181
+
182
+ <li class="public ">
183
+ <span class="summary_signature">
184
+
185
+ <a href="#allows-class_method" title="allows (class method)">+ (Object) <strong>allows</strong>(*input_allows) </a>
186
+
187
+
188
+
189
+ </span>
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+ <span class="summary_desc"><div class='inline'><p>Specifies a white list of methods which <em>may</em> be proxied to
199
+ to the wrapped object.</p>
200
+ </div></span>
201
+
202
+ </li>
203
+
204
+
205
+ <li class="public ">
206
+ <span class="summary_signature">
207
+
208
+ <a href="#decorate-class_method" title="decorate (class method)">+ (Object) <strong>decorate</strong>(input, context = nil) </a>
209
+
210
+
211
+
212
+ </span>
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ <span class="summary_desc"><div class='inline'><p>Initialize a new decorator instance by passing in
222
+ an instance of the source class.</p>
223
+ </div></span>
224
+
225
+ </li>
226
+
227
+
228
+ <li class="public ">
229
+ <span class="summary_signature">
230
+
231
+ <a href="#decorates-class_method" title="decorates (class method)">+ (Object) <strong>decorates</strong>(input) </a>
232
+
233
+
234
+
235
+ </span>
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+ <span class="summary_desc"><div class='inline'><p>Typically called within a decorator definition, this method
245
+ specifies the name of the wrapped object class.</p>
246
+ </div></span>
247
+
248
+ </li>
249
+
250
+
251
+ <li class="public ">
252
+ <span class="summary_signature">
253
+
254
+ <a href="#denies-class_method" title="denies (class method)">+ (Object) <strong>denies</strong>(*input_denied) </a>
255
+
256
+
257
+
258
+ </span>
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+ <span class="summary_desc"><div class='inline'><p>Specifies a black list of methods which may <em>not</em> be proxied to
268
+ to the wrapped object.</p>
269
+ </div></span>
270
+
271
+ </li>
272
+
273
+
274
+ <li class="public ">
275
+ <span class="summary_signature">
276
+
277
+ <a href="#find-class_method" title="find (class method)">+ (Object) <strong>find</strong>(input) </a>
278
+
279
+
280
+
281
+ </span>
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+ <span class="summary_desc"><div class='inline'><p>Proxies to the class specified by <code>decorates</code> to automatically
291
+ lookup an object in the database and decorate it.</p>
292
+ </div></span>
293
+
294
+ </li>
295
+
296
+
297
+ <li class="public ">
298
+ <span class="summary_signature">
299
+
300
+ <a href="#lazy_helpers-class_method" title="lazy_helpers (class method)">+ (Object) <strong>lazy_helpers</strong> </a>
301
+
302
+
303
+
304
+ </span>
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+ <span class="summary_desc"><div class='inline'><p>Calling <code>lazy_helpers</code> will make the built-in and
314
+ user-defined Rails helpers accessible as class methods
315
+ in the decorator without using the <code>h.</code> or <code>helpers.</code> proxy.</p>
316
+ </div></span>
317
+
318
+ </li>
319
+
320
+
321
+ <li class="public ">
322
+ <span class="summary_signature">
323
+
324
+ <a href="#model_name-class_method" title="model_name (class method)">+ (ActiveModel::Name) <strong>model_name</strong> </a>
325
+
326
+
327
+
328
+ </span>
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+ <span class="summary_desc"><div class='inline'><p>Use primarily by <code>form_for</code>, this returns an instance of
338
+ <code>ActiveModel::Name</code> set to the wrapped model's class name.</p>
339
+ </div></span>
340
+
341
+ </li>
342
+
343
+
344
+ </ul>
345
+
346
+ <h2>
347
+ Instance Method Summary
348
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
349
+ </h2>
350
+
351
+ <ul class="summary">
352
+
353
+ <li class="public ">
354
+ <span class="summary_signature">
355
+
356
+ <a href="#helpers-instance_method" title="#helpers (instance method)">- (Object) <strong>helpers</strong> </a>
357
+
358
+
359
+
360
+ (also: #h)
361
+
362
+ </span>
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+ <span class="summary_desc"><div class='inline'><p>Access the helpers proxy to call built-in and user-defined
372
+ Rails helpers.</p>
373
+ </div></span>
374
+
375
+ </li>
376
+
377
+
378
+ <li class="public ">
379
+ <span class="summary_signature">
380
+
381
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (Base) <strong>initialize</strong>(input, context = nil) </a>
382
+
383
+
384
+
385
+ </span>
386
+
387
+ <span class="note title constructor">constructor</span>
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+ <span class="summary_desc"><div class='inline'><p>Initialize a new decorator instance by passing in
397
+ an instance of the source class.</p>
398
+ </div></span>
399
+
400
+ </li>
401
+
402
+
403
+ <li class="public ">
404
+ <span class="summary_signature">
405
+
406
+ <a href="#to_model-instance_method" title="#to_model (instance method)">- (Object) <strong>to_model</strong> </a>
407
+
408
+
409
+
410
+ </span>
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+ <span class="summary_desc"><div class='inline'><p>Fetch the original wrapped model.</p>
420
+ </div></span>
421
+
422
+ </li>
423
+
424
+
425
+ </ul>
426
+
427
+
428
+ <div id="constructor_details" class="method_details_list">
429
+ <h2>Constructor Details</h2>
430
+
431
+ <div class="method_details first">
432
+ <p class="signature first" id="initialize-instance_method">
433
+
434
+ - (<tt><span class='object_link'><a href="" title="Draper::Base (class)">Base</a></span></tt>) <strong>initialize</strong>(input, context = nil)
435
+
436
+
437
+
438
+ </p><div class="docstring">
439
+ <div class="discussion">
440
+ <p>Initialize a new decorator instance by passing in
441
+ an instance of the source class. Pass in an optional
442
+ context is stored for later use.</p>
443
+
444
+
445
+ </div>
446
+ </div>
447
+ <div class="tags">
448
+ <h3>Parameters:</h3>
449
+ <ul class="param">
450
+
451
+ <li>
452
+
453
+ <span class='name'>instance</span>
454
+
455
+
456
+ <span class='type'>(<tt>Object</tt>)</span>
457
+
458
+
459
+
460
+ &mdash;
461
+ <div class='inline'><p>to wrap</p>
462
+ </div>
463
+
464
+ </li>
465
+
466
+ <li>
467
+
468
+ <span class='name'>context</span>
469
+
470
+
471
+ <span class='type'>(<tt>Object</tt>)</span>
472
+
473
+
474
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
475
+
476
+
477
+ &mdash;
478
+ <div class='inline'><p>(optional)</p>
479
+ </div>
480
+
481
+ </li>
482
+
483
+ </ul>
484
+
485
+ </div><table class="source_code">
486
+ <tr>
487
+ <td>
488
+ <pre class="lines">
489
+
490
+
491
+ 17
492
+ 18
493
+ 19
494
+ 20
495
+ 21
496
+ 22
497
+ 23</pre>
498
+ </td>
499
+ <td>
500
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 17</span>
501
+
502
+ <span class='def def kw'>def</span> <span class='initialize identifier id'>initialize</span><span class='lparen token'>(</span><span class='input identifier id'>input</span><span class='comma token'>,</span> <span class='context identifier id'>context</span> <span class='assign token'>=</span> <span class='nil nil kw'>nil</span><span class='rparen token'>)</span>
503
+ <span class='input identifier id'>input</span><span class='dot token'>.</span><span class='inspect identifier id'>inspect</span> <span class='comment val'># forces evaluation of a lazy query from AR</span>
504
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='class identifier id'>class</span><span class='dot token'>.</span><span class='model_class identifier id'>model_class</span> <span class='assign token'>=</span> <span class='input identifier id'>input</span><span class='dot token'>.</span><span class='class identifier id'>class</span> <span class='if if_mod kw'>if</span> <span class='model_class identifier id'>model_class</span><span class='dot token'>.</span><span class='nil? fid id'>nil?</span>
505
+ <span class='@model ivar id'>@model</span> <span class='assign token'>=</span> <span class='input identifier id'>input</span>
506
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='context identifier id'>context</span> <span class='assign token'>=</span> <span class='context identifier id'>context</span>
507
+ <span class='build_methods identifier id'>build_methods</span>
508
+ <span class='end end kw'>end</span>
509
+ </pre>
510
+ </td>
511
+ </tr>
512
+ </table>
513
+ </div>
514
+
515
+ </div>
516
+
517
+ <div id="instance_attr_details" class="attr_details">
518
+ <h2>Instance Attribute Details</h2>
519
+
520
+
521
+ <span id="context=-instance_method"></span>
522
+ <span id="context-instance_method"></span>
523
+ <div class="method_details first">
524
+ <p class="signature first" id="context-instance_method">
525
+
526
+ - (<tt>Object</tt>) <strong>context</strong>
527
+
528
+
529
+
530
+ </p><div class="docstring">
531
+ <div class="discussion">
532
+ <p>Returns the value of attribute context</p>
533
+
534
+
535
+ </div>
536
+ </div>
537
+ <div class="tags">
538
+
539
+ </div><table class="source_code">
540
+ <tr>
541
+ <td>
542
+ <pre class="lines">
543
+
544
+
545
+ 5
546
+ 6
547
+ 7</pre>
548
+ </td>
549
+ <td>
550
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 5</span>
551
+
552
+ <span class='def def kw'>def</span> <span class='context identifier id'>context</span>
553
+ <span class='@context ivar id'>@context</span>
554
+ <span class='end end kw'>end</span>
555
+ </pre>
556
+ </td>
557
+ </tr>
558
+ </table>
559
+ </div>
560
+
561
+
562
+ <span id="model=-instance_method"></span>
563
+ <span id="model-instance_method"></span>
564
+ <div class="method_details ">
565
+ <p class="signature " id="model-instance_method">
566
+
567
+ - (<tt>Object</tt>) <strong>model</strong>
568
+
569
+
570
+
571
+ </p><div class="docstring">
572
+ <div class="discussion">
573
+ <p>Returns the value of attribute model</p>
574
+
575
+
576
+ </div>
577
+ </div>
578
+ <div class="tags">
579
+
580
+ </div><table class="source_code">
581
+ <tr>
582
+ <td>
583
+ <pre class="lines">
584
+
585
+
586
+ 5
587
+ 6
588
+ 7</pre>
589
+ </td>
590
+ <td>
591
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 5</span>
592
+
593
+ <span class='def def kw'>def</span> <span class='model identifier id'>model</span>
594
+ <span class='@model ivar id'>@model</span>
595
+ <span class='end end kw'>end</span>
596
+ </pre>
597
+ </td>
598
+ </tr>
599
+ </table>
600
+ </div>
601
+
602
+ </div>
603
+
604
+
605
+ <div id="class_method_details" class="method_details_list">
606
+ <h2>Class Method Details</h2>
607
+
608
+
609
+ <div class="method_details first">
610
+ <p class="signature first" id="allows-class_method">
611
+
612
+ + (<tt>Object</tt>) <strong>allows</strong>(*input_allows)
613
+
614
+
615
+
616
+ </p><div class="docstring">
617
+ <div class="discussion">
618
+ <p>Specifies a white list of methods which <em>may</em> be proxied to
619
+ to the wrapped object. When <code>allows</code> is used, only the listed
620
+ methods and methods defined in the decorator itself will be
621
+ available.</p>
622
+
623
+ <p>Do not use both <code>.allows</code> and <code>.denies</code> together, either write
624
+ a whitelist with <code>.allows</code> or a blacklist with <code>.denies</code></p>
625
+
626
+
627
+ </div>
628
+ </div>
629
+ <div class="tags">
630
+ <h3>Parameters:</h3>
631
+ <ul class="param">
632
+
633
+ <li>
634
+
635
+ <span class='name'>methods</span>
636
+
637
+
638
+ <span class='type'>(<tt>Symbols*</tt>)</span>
639
+
640
+
641
+
642
+ &mdash;
643
+ <div class='inline'><p>to allow like <code>:find, :find_by_name</code></p>
644
+ </div>
645
+
646
+ </li>
647
+
648
+ </ul>
649
+ <h3>Raises:</h3>
650
+ <ul class="raise">
651
+
652
+ <li>
653
+
654
+
655
+ <span class='type'>(<tt>ArgumentError</tt>)</span>
656
+
657
+
658
+
659
+ </li>
660
+
661
+ </ul>
662
+
663
+ </div><table class="source_code">
664
+ <tr>
665
+ <td>
666
+ <pre class="lines">
667
+
668
+
669
+ 73
670
+ 74
671
+ 75
672
+ 76
673
+ 77</pre>
674
+ </td>
675
+ <td>
676
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 73</span>
677
+
678
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='allows identifier id'>allows</span><span class='lparen token'>(</span><span class='mult op'>*</span><span class='input_allows identifier id'>input_allows</span><span class='rparen token'>)</span>
679
+ <span class='raise identifier id'>raise</span> <span class='ArgumentError constant id'>ArgumentError</span><span class='comma token'>,</span> <span class='string val'>&quot;Specify at least one method (as a symbol) to allow when using allows&quot;</span> <span class='if if_mod kw'>if</span> <span class='input_allows identifier id'>input_allows</span><span class='dot token'>.</span><span class='empty? fid id'>empty?</span>
680
+ <span class='raise identifier id'>raise</span> <span class='ArgumentError constant id'>ArgumentError</span><span class='comma token'>,</span> <span class='string val'>&quot;Use either 'allows' or 'denies', but not both.&quot;</span> <span class='unless unless_mod kw'>unless</span> <span class='lparen token'>(</span><span class='self self kw'>self</span><span class='dot token'>.</span><span class='denied identifier id'>denied</span> <span class='eq op'>==</span> <span class='DEFAULT_DENIED constant id'>DEFAULT_DENIED</span><span class='rparen token'>)</span>
681
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='allowed identifier id'>allowed</span> <span class='assign token'>=</span> <span class='input_allows identifier id'>input_allows</span>
682
+ <span class='end end kw'>end</span>
683
+ </pre>
684
+ </td>
685
+ </tr>
686
+ </table>
687
+ </div>
688
+
689
+ <div class="method_details ">
690
+ <p class="signature " id="decorate-class_method">
691
+
692
+ + (<tt>Object</tt>) <strong>decorate</strong>(input, context = nil)
693
+
694
+
695
+
696
+ </p><div class="docstring">
697
+ <div class="discussion">
698
+ <p>Initialize a new decorator instance by passing in
699
+ an instance of the source class. Pass in an optional
700
+ context is stored for later use.</p>
701
+
702
+ <p>When passing in a single object, using <code>.decorate</code> is
703
+ identical to calling <code>.new</code>. However, <code>.decorate</code> can
704
+ also accept a collection and return a collection of
705
+ individually decorated objects.</p>
706
+
707
+
708
+ </div>
709
+ </div>
710
+ <div class="tags">
711
+ <h3>Parameters:</h3>
712
+ <ul class="param">
713
+
714
+ <li>
715
+
716
+ <span class='name'>instance(s)</span>
717
+
718
+
719
+ <span class='type'>(<tt>Object</tt>)</span>
720
+
721
+
722
+
723
+ &mdash;
724
+ <div class='inline'><p>to wrap</p>
725
+ </div>
726
+
727
+ </li>
728
+
729
+ <li>
730
+
731
+ <span class='name'>context</span>
732
+
733
+
734
+ <span class='type'>(<tt>Object</tt>)</span>
735
+
736
+
737
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
738
+
739
+
740
+ &mdash;
741
+ <div class='inline'><p>(optional)</p>
742
+ </div>
743
+
744
+ </li>
745
+
746
+ </ul>
747
+
748
+ </div><table class="source_code">
749
+ <tr>
750
+ <td>
751
+ <pre class="lines">
752
+
753
+
754
+ 90
755
+ 91
756
+ 92</pre>
757
+ </td>
758
+ <td>
759
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 90</span>
760
+
761
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='decorate identifier id'>decorate</span><span class='lparen token'>(</span><span class='input identifier id'>input</span><span class='comma token'>,</span> <span class='context identifier id'>context</span> <span class='assign token'>=</span> <span class='nil nil kw'>nil</span><span class='rparen token'>)</span>
762
+ <span class='input identifier id'>input</span><span class='dot token'>.</span><span class='respond_to? fid id'>respond_to?</span><span class='lparen token'>(</span><span class='symbol val'>:each</span><span class='rparen token'>)</span> <span class='question op'>?</span> <span class='input identifier id'>input</span><span class='dot token'>.</span><span class='map identifier id'>map</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='i identifier id'>i</span><span class='bitor op'>|</span> <span class='new identifier id'>new</span><span class='lparen token'>(</span><span class='i identifier id'>i</span><span class='comma token'>,</span> <span class='context identifier id'>context</span><span class='rparen token'>)</span><span class='rbrace token'>}</span> <span class='colon op'>:</span> <span class='new identifier id'>new</span><span class='lparen token'>(</span><span class='input identifier id'>input</span><span class='comma token'>,</span> <span class='context identifier id'>context</span><span class='rparen token'>)</span>
763
+ <span class='end end kw'>end</span>
764
+ </pre>
765
+ </td>
766
+ </tr>
767
+ </table>
768
+ </div>
769
+
770
+ <div class="method_details ">
771
+ <p class="signature " id="decorates-class_method">
772
+
773
+ + (<tt>Object</tt>) <strong>decorates</strong>(input)
774
+
775
+
776
+
777
+ </p><div class="docstring">
778
+ <div class="discussion">
779
+ <p>Typically called within a decorator definition, this method
780
+ specifies the name of the wrapped object class.</p>
781
+
782
+ <p>For instance, a <code>ProductDecorator</code> class might call <code>decorates :product</code></p>
783
+
784
+ <p>But they don't have to match in name, so a <code>EmployeeDecorator</code>
785
+ class could call <code>decorates :person</code> to wrap instances of <code>Person</code></p>
786
+
787
+ <p>This is primarilly set so the <code>.find</code> method knows which class
788
+ to query.</p>
789
+
790
+
791
+ </div>
792
+ </div>
793
+ <div class="tags">
794
+ <h3>Parameters:</h3>
795
+ <ul class="param">
796
+
797
+ <li>
798
+
799
+ <span class='name'>class_name</span>
800
+
801
+
802
+ <span class='type'>(<tt>Symbol</tt>)</span>
803
+
804
+
805
+
806
+ &mdash;
807
+ <div class='inline'><p>snakecase name of the decorated class, like <code>:product</code></p>
808
+ </div>
809
+
810
+ </li>
811
+
812
+ </ul>
813
+
814
+ </div><table class="source_code">
815
+ <tr>
816
+ <td>
817
+ <pre class="lines">
818
+
819
+
820
+ 46
821
+ 47
822
+ 48
823
+ 49</pre>
824
+ </td>
825
+ <td>
826
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 46</span>
827
+
828
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='decorates identifier id'>decorates</span><span class='lparen token'>(</span><span class='input identifier id'>input</span><span class='rparen token'>)</span>
829
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='model_class identifier id'>model_class</span> <span class='assign token'>=</span> <span class='input identifier id'>input</span><span class='dot token'>.</span><span class='to_s identifier id'>to_s</span><span class='dot token'>.</span><span class='camelize identifier id'>camelize</span><span class='dot token'>.</span><span class='constantize identifier id'>constantize</span>
830
+ <span class='model_class identifier id'>model_class</span><span class='dot token'>.</span><span class='send identifier id'>send</span> <span class='symbol val'>:include</span><span class='comma token'>,</span> <span class='Draper constant id'>Draper</span><span class='colon2 op'>::</span><span class='ModelSupport constant id'>ModelSupport</span>
831
+ <span class='end end kw'>end</span>
832
+ </pre>
833
+ </td>
834
+ </tr>
835
+ </table>
836
+ </div>
837
+
838
+ <div class="method_details ">
839
+ <p class="signature " id="denies-class_method">
840
+
841
+ + (<tt>Object</tt>) <strong>denies</strong>(*input_denied)
842
+
843
+
844
+
845
+ </p><div class="docstring">
846
+ <div class="discussion">
847
+ <p>Specifies a black list of methods which may <em>not</em> be proxied to
848
+ to the wrapped object.</p>
849
+
850
+ <p>Do not use both <code>.allows</code> and <code>.denies</code> together, either write
851
+ a whitelist with <code>.allows</code> or a blacklist with <code>.denies</code></p>
852
+
853
+
854
+ </div>
855
+ </div>
856
+ <div class="tags">
857
+ <h3>Parameters:</h3>
858
+ <ul class="param">
859
+
860
+ <li>
861
+
862
+ <span class='name'>methods</span>
863
+
864
+
865
+ <span class='type'>(<tt>Symbols*</tt>)</span>
866
+
867
+
868
+
869
+ &mdash;
870
+ <div class='inline'><p>to deny like <code>:find, :find_by_name</code></p>
871
+ </div>
872
+
873
+ </li>
874
+
875
+ </ul>
876
+ <h3>Raises:</h3>
877
+ <ul class="raise">
878
+
879
+ <li>
880
+
881
+
882
+ <span class='type'>(<tt>ArgumentError</tt>)</span>
883
+
884
+
885
+
886
+ </li>
887
+
888
+ </ul>
889
+
890
+ </div><table class="source_code">
891
+ <tr>
892
+ <td>
893
+ <pre class="lines">
894
+
895
+
896
+ 58
897
+ 59
898
+ 60
899
+ 61
900
+ 62</pre>
901
+ </td>
902
+ <td>
903
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 58</span>
904
+
905
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='denies identifier id'>denies</span><span class='lparen token'>(</span><span class='mult op'>*</span><span class='input_denied identifier id'>input_denied</span><span class='rparen token'>)</span>
906
+ <span class='raise identifier id'>raise</span> <span class='ArgumentError constant id'>ArgumentError</span><span class='comma token'>,</span> <span class='string val'>&quot;Specify at least one method (as a symbol) to exclude when using denies&quot;</span> <span class='if if_mod kw'>if</span> <span class='input_denied identifier id'>input_denied</span><span class='dot token'>.</span><span class='empty? fid id'>empty?</span>
907
+ <span class='raise identifier id'>raise</span> <span class='ArgumentError constant id'>ArgumentError</span><span class='comma token'>,</span> <span class='string val'>&quot;Use either 'allows' or 'denies', but not both.&quot;</span> <span class='if if_mod kw'>if</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='allowed? fid id'>allowed?</span>
908
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='denied identifier id'>denied</span> <span class='opasgn op'>+=</span> <span class='input_denied identifier id'>input_denied</span>
909
+ <span class='end end kw'>end</span>
910
+ </pre>
911
+ </td>
912
+ </tr>
913
+ </table>
914
+ </div>
915
+
916
+ <div class="method_details ">
917
+ <p class="signature " id="find-class_method">
918
+
919
+ + (<tt>Object</tt>) <strong>find</strong>(input)
920
+
921
+
922
+
923
+ </p><div class="docstring">
924
+ <div class="discussion">
925
+ <p>Proxies to the class specified by <code>decorates</code> to automatically
926
+ lookup an object in the database and decorate it.</p>
927
+
928
+
929
+ </div>
930
+ </div>
931
+ <div class="tags">
932
+ <h3>Parameters:</h3>
933
+ <ul class="param">
934
+
935
+ <li>
936
+
937
+ <span class='name'>id</span>
938
+
939
+
940
+ <span class='type'>(<tt>Symbol or String</tt>)</span>
941
+
942
+
943
+
944
+ &mdash;
945
+ <div class='inline'><p>to lookup</p>
946
+ </div>
947
+
948
+ </li>
949
+
950
+ </ul>
951
+ <h3>Returns:</h3>
952
+ <ul class="return">
953
+
954
+ <li>
955
+
956
+
957
+ <span class='type'>(<tt>Object</tt>)</span>
958
+
959
+
960
+
961
+ &mdash;
962
+ <div class='inline'><p>instance of this decorator class</p>
963
+ </div>
964
+
965
+ </li>
966
+
967
+ </ul>
968
+
969
+ </div><table class="source_code">
970
+ <tr>
971
+ <td>
972
+ <pre class="lines">
973
+
974
+
975
+ 30
976
+ 31
977
+ 32</pre>
978
+ </td>
979
+ <td>
980
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 30</span>
981
+
982
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='find identifier id'>find</span><span class='lparen token'>(</span><span class='input identifier id'>input</span><span class='rparen token'>)</span>
983
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='new identifier id'>new</span><span class='lparen token'>(</span><span class='model_class identifier id'>model_class</span><span class='dot token'>.</span><span class='find identifier id'>find</span><span class='lparen token'>(</span><span class='input identifier id'>input</span><span class='rparen token'>)</span><span class='rparen token'>)</span>
984
+ <span class='end end kw'>end</span>
985
+ </pre>
986
+ </td>
987
+ </tr>
988
+ </table>
989
+ </div>
990
+
991
+ <div class="method_details ">
992
+ <p class="signature " id="lazy_helpers-class_method">
993
+
994
+ + (<tt>Object</tt>) <strong>lazy_helpers</strong>
995
+
996
+
997
+
998
+ </p><div class="docstring">
999
+ <div class="discussion">
1000
+ <p>Calling <code>lazy_helpers</code> will make the built-in and
1001
+ user-defined Rails helpers accessible as class methods
1002
+ in the decorator without using the <code>h.</code> or <code>helpers.</code> proxy.</p>
1003
+
1004
+ <p>The drawback is that you dump many methods into your decorator's
1005
+ namespace and collisions could create unexpected results.</p>
1006
+
1007
+
1008
+ </div>
1009
+ </div>
1010
+ <div class="tags">
1011
+
1012
+ </div><table class="source_code">
1013
+ <tr>
1014
+ <td>
1015
+ <pre class="lines">
1016
+
1017
+
1018
+ 109
1019
+ 110
1020
+ 111</pre>
1021
+ </td>
1022
+ <td>
1023
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 109</span>
1024
+
1025
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='lazy_helpers identifier id'>lazy_helpers</span>
1026
+ <span class='self self kw'>self</span><span class='dot token'>.</span><span class='send identifier id'>send</span><span class='lparen token'>(</span><span class='symbol val'>:include</span><span class='comma token'>,</span> <span class='Draper constant id'>Draper</span><span class='colon2 op'>::</span><span class='LazyHelpers constant id'>LazyHelpers</span><span class='rparen token'>)</span>
1027
+ <span class='end end kw'>end</span>
1028
+ </pre>
1029
+ </td>
1030
+ </tr>
1031
+ </table>
1032
+ </div>
1033
+
1034
+ <div class="method_details ">
1035
+ <p class="signature " id="model_name-class_method">
1036
+
1037
+ + (<tt>ActiveModel::Name</tt>) <strong>model_name</strong>
1038
+
1039
+
1040
+
1041
+ </p><div class="docstring">
1042
+ <div class="discussion">
1043
+ <p>Use primarily by <code>form_for</code>, this returns an instance of
1044
+ <code>ActiveModel::Name</code> set to the wrapped model's class name</p>
1045
+
1046
+
1047
+ </div>
1048
+ </div>
1049
+ <div class="tags">
1050
+ <h3>Returns:</h3>
1051
+ <ul class="return">
1052
+
1053
+ <li>
1054
+
1055
+
1056
+ <span class='type'>(<tt>ActiveModel::Name</tt>)</span>
1057
+
1058
+
1059
+
1060
+ &mdash;
1061
+ <div class='inline'><p>model_name</p>
1062
+ </div>
1063
+
1064
+ </li>
1065
+
1066
+ </ul>
1067
+
1068
+ </div><table class="source_code">
1069
+ <tr>
1070
+ <td>
1071
+ <pre class="lines">
1072
+
1073
+
1074
+ 117
1075
+ 118
1076
+ 119</pre>
1077
+ </td>
1078
+ <td>
1079
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 117</span>
1080
+
1081
+ <span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='model_name identifier id'>model_name</span>
1082
+ <span class='ActiveModel constant id'>ActiveModel</span><span class='colon2 op'>::</span><span class='Name constant id'>Name</span><span class='dot token'>.</span><span class='new identifier id'>new</span><span class='lparen token'>(</span><span class='model_class identifier id'>model_class</span><span class='rparen token'>)</span>
1083
+ <span class='end end kw'>end</span>
1084
+ </pre>
1085
+ </td>
1086
+ </tr>
1087
+ </table>
1088
+ </div>
1089
+
1090
+ </div>
1091
+
1092
+ <div id="instance_method_details" class="method_details_list">
1093
+ <h2>Instance Method Details</h2>
1094
+
1095
+
1096
+ <div class="method_details first">
1097
+ <p class="signature first" id="helpers-instance_method">
1098
+
1099
+ - (<tt>Object</tt>) <strong>helpers</strong>
1100
+
1101
+
1102
+
1103
+ <span class="aliases">Also known as:
1104
+ <span class="names"><span id='h-instance_method'>h</span></span>
1105
+ </span>
1106
+
1107
+ </p><div class="docstring">
1108
+ <div class="discussion">
1109
+ <p>Access the helpers proxy to call built-in and user-defined
1110
+ Rails helpers. Aliased to <code>.h</code> for convinience.</p>
1111
+
1112
+
1113
+ </div>
1114
+ </div>
1115
+ <div class="tags">
1116
+ <h3>Returns:</h3>
1117
+ <ul class="return">
1118
+
1119
+ <li>
1120
+
1121
+
1122
+ <span class='type'>(<tt>Object</tt>)</span>
1123
+
1124
+
1125
+
1126
+ &mdash;
1127
+ <div class='inline'><p>proxy</p>
1128
+ </div>
1129
+
1130
+ </li>
1131
+
1132
+ </ul>
1133
+
1134
+ </div><table class="source_code">
1135
+ <tr>
1136
+ <td>
1137
+ <pre class="lines">
1138
+
1139
+
1140
+ 98
1141
+ 99
1142
+ 100</pre>
1143
+ </td>
1144
+ <td>
1145
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 98</span>
1146
+
1147
+ <span class='def def kw'>def</span> <span class='helpers identifier id'>helpers</span>
1148
+ <span class='@helpers ivar id'>@helpers</span> <span class='opasgn op'>||=</span> <span class='ApplicationController constant id'>ApplicationController</span><span class='colon2 op'>::</span><span class='all_helpers identifier id'>all_helpers</span>
1149
+ <span class='end end kw'>end</span>
1150
+ </pre>
1151
+ </td>
1152
+ </tr>
1153
+ </table>
1154
+ </div>
1155
+
1156
+ <div class="method_details ">
1157
+ <p class="signature " id="to_model-instance_method">
1158
+
1159
+ - (<tt>Object</tt>) <strong>to_model</strong>
1160
+
1161
+
1162
+
1163
+ </p><div class="docstring">
1164
+ <div class="discussion">
1165
+ <p>Fetch the original wrapped model.</p>
1166
+
1167
+
1168
+ </div>
1169
+ </div>
1170
+ <div class="tags">
1171
+ <h3>Returns:</h3>
1172
+ <ul class="return">
1173
+
1174
+ <li>
1175
+
1176
+
1177
+ <span class='type'>(<tt>Object</tt>)</span>
1178
+
1179
+
1180
+
1181
+ &mdash;
1182
+ <div class='inline'><p>original_model</p>
1183
+ </div>
1184
+
1185
+ </li>
1186
+
1187
+ </ul>
1188
+
1189
+ </div><table class="source_code">
1190
+ <tr>
1191
+ <td>
1192
+ <pre class="lines">
1193
+
1194
+
1195
+ 124
1196
+ 125
1197
+ 126</pre>
1198
+ </td>
1199
+ <td>
1200
+ <pre class="code"><span class="info file"># File 'lib/draper/base.rb', line 124</span>
1201
+
1202
+ <span class='def def kw'>def</span> <span class='to_model identifier id'>to_model</span>
1203
+ <span class='@model ivar id'>@model</span>
1204
+ <span class='end end kw'>end</span>
1205
+ </pre>
1206
+ </td>
1207
+ </tr>
1208
+ </table>
1209
+ </div>
1210
+
1211
+ </div>
1212
+
1213
+ </div>
1214
+
1215
+ <div id="footer">
1216
+ Generated on Thu Sep 1 01:13:37 2011 by
1217
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1218
+ 0.7.2 (ruby-1.8.7).
1219
+ </div>
1220
+
1221
+ </body>
1222
+ </html>