classx 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/ChangeLog +354 -0
  2. data/README +5 -0
  3. data/Rakefile +2 -2
  4. data/bench/attribute_get.rb +73 -0
  5. data/bench/attribute_set.rb +53 -19
  6. data/bench/define_attribute.rb +226 -0
  7. data/bench/initialize.rb +25 -7
  8. data/doc/output/coverage/index.html +74 -128
  9. data/doc/output/coverage/lib-classx-attribute_rb.html +291 -190
  10. data/doc/output/coverage/lib-classx-attributes_rb.html +167 -101
  11. data/doc/output/coverage/lib-classx-bracketable_rb.html +671 -0
  12. data/doc/output/coverage/lib-classx-class_attributes_rb.html +775 -0
  13. data/doc/output/coverage/lib-classx-commandable_rb.html +727 -0
  14. data/doc/output/coverage/{-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-block_rb.html → lib-classx-declare_rb.html} +60 -62
  15. data/doc/output/coverage/lib-classx-validate_rb.html +43 -41
  16. data/doc/output/coverage/lib-classx_rb.html +208 -78
  17. data/example/commandable.rb +1 -0
  18. data/lib/classx.rb +146 -16
  19. data/lib/classx/attribute.rb +244 -143
  20. data/lib/classx/attributes.rb +93 -27
  21. data/lib/classx/bracketable.rb +61 -0
  22. data/lib/classx/class_attributes.rb +165 -0
  23. data/lib/classx/commandable.rb +55 -4
  24. data/lib/classx/declare.rb +40 -3
  25. data/lib/classx/role/logger.rb +17 -13
  26. data/lib/classx/validate.rb +26 -24
  27. data/spec/classx/handles_spec.rb +21 -6
  28. data/spec/classx/serialize_spec.rb +57 -0
  29. data/spec/classx/{with_coerce.rb → with_coerce_spec.rb} +0 -0
  30. data/spec/classx/with_extend_spec.rb +58 -0
  31. data/spec/classx/with_include_spec.rb +58 -0
  32. data/spec/classx/with_validate_spec.rb +363 -0
  33. data/spec/classx/without_anyoption_spec.rb +1 -1
  34. data/spec/classx/writable_option_spec.rb +29 -4
  35. data/spec/classx_bracketable_spec.rb +160 -0
  36. data/spec/classx_class_attributes/default_option_spec.rb +121 -0
  37. data/spec/classx_class_attributes/dsl_accessor_spec.rb +88 -0
  38. data/spec/classx_class_attributes/handles_spec.rb +77 -0
  39. data/spec/classx_class_attributes/with_coerce_spec.rb +119 -0
  40. data/spec/classx_class_attributes/with_extend_spec.rb +64 -0
  41. data/spec/classx_class_attributes/with_include_spec.rb +64 -0
  42. data/spec/classx_class_attributes/with_multiple_class_spec.rb +60 -0
  43. data/spec/classx_class_attributes/with_validate_spec.rb +248 -0
  44. data/spec/classx_class_attributes/without_accessor_spec.rb +19 -0
  45. data/spec/classx_class_attributes/without_anyoption_spec.rb +21 -0
  46. data/spec/classx_class_attributes/writable_option_spec.rb +100 -0
  47. data/spec/classx_declare_spec.rb +117 -0
  48. data/spec/classx_validate_spec.rb +1 -3
  49. data/tasks/basic_tasks.rake +1 -1
  50. metadata +36 -26
  51. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-callbacks_rb.html +0 -932
  52. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-change_rb.html +0 -779
  53. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-hunk_rb.html +0 -867
  54. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs_rb.html +0 -1715
  55. data/doc/output/coverage/-Library-Ruby-Gems-gems-rcov-0_8_1_2_0-lib-rcov_rb.html +0 -1598
  56. data/spec/classx/with_extend.rb +0 -27
  57. data/spec/classx/with_include.rb +0 -27
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><title>/Library/Ruby/Gems/gems/diff-lcs-1.1.2/lib/diff/lcs/block.rb - C0 code coverage information</title>
2
+ <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><title>lib/classx/declare.rb - C0 code coverage information</title>
3
3
  <style type='text/css'>body { background-color: rgb(240, 240, 245); }</style>
4
4
  <style type='text/css'>span.cross-ref-title {
5
5
  font-size: 140%;
@@ -553,7 +553,7 @@ span.run100 {
553
553
  </style>
554
554
  </head>
555
555
  <body><h3>C0 code coverage information</h3>
556
- <p>Generated on Sat Aug 23 14:29:18 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
556
+ <p>Generated on Sat Sep 13 00:31:29 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
557
557
  </p>
558
558
  <hr/>
559
559
  <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
@@ -569,26 +569,26 @@ span.run100 {
569
569
  <td class='heading'>Code coverage</td>
570
570
  </tr>
571
571
  </thead>
572
- <tbody><tr class='light'><td><a href='-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-block_rb.html'>/Library/Ruby/Gems/gems/diff-lcs-1.1.2/lib/diff/lcs/block.rb</a>
572
+ <tbody><tr class='light'><td><a href='lib-classx-declare_rb.html'>lib/classx/declare.rb</a>
573
573
  </td>
574
- <td class='lines_total'><tt>51</tt>
574
+ <td class='lines_total'><tt>49</tt>
575
575
  </td>
576
- <td class='lines_code'><tt>28</tt>
576
+ <td class='lines_code'><tt>26</tt>
577
577
  </td>
578
- <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>52.9%</tt>
578
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>93.9%</tt>
579
579
  &nbsp;</td>
580
- <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='53'/>
581
- <td class='uncovered' width='47'/>
580
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='94'/>
581
+ <td class='uncovered' width='6'/>
582
582
  </tr>
583
583
  </table>
584
584
  </td>
585
585
  </tr>
586
586
  </table>
587
587
  </td>
588
- <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>17.9%</tt>
588
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>88.5%</tt>
589
589
  &nbsp;</td>
590
- <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='18'/>
591
- <td class='uncovered' width='82'/>
590
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='88'/>
591
+ <td class='uncovered' width='12'/>
592
592
  </tr>
593
593
  </table>
594
594
  </td>
@@ -598,57 +598,55 @@ span.run100 {
598
598
  </tr>
599
599
  </tbody>
600
600
  </table>
601
- <pre><span class="inferred0"><a name="line1"></a> 1 #! /usr/env/bin ruby
602
- </span><span class="inferred1"><a name="line2"></a> 2 #--
603
- </span><span class="inferred0"><a name="line3"></a> 3 # Copyright 2004 Austin Ziegler &lt;diff-lcs@halostatue.ca&gt;
604
- </span><span class="inferred1"><a name="line4"></a> 4 # adapted from:
605
- </span><span class="inferred0"><a name="line5"></a> 5 # Algorithm::Diff (Perl) by Ned Konz &lt;perl@bike-nomad.com&gt;
606
- </span><span class="inferred1"><a name="line6"></a> 6 # Smalltalk by Mario I. Wolczko &lt;mario@wolczko.com&gt;
607
- </span><span class="inferred0"><a name="line7"></a> 7 # implements McIlroy-Hunt diff algorithm
608
- </span><span class="inferred1"><a name="line8"></a> 8 #
609
- </span><span class="inferred0"><a name="line9"></a> 9 # This program is free software. It may be redistributed and/or modified under
610
- </span><span class="inferred1"><a name="line10"></a>10 # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
611
- </span><span class="inferred0"><a name="line11"></a>11 # Ruby licence.
612
- </span><span class="inferred1"><a name="line12"></a>12 #
613
- </span><span class="inferred0"><a name="line13"></a>13 # $Id: block.rb,v 1.3 2004/08/08 20:33:09 austin Exp $
614
- </span><span class="inferred1"><a name="line14"></a>14 #++
615
- </span><span class="inferred0"><a name="line15"></a>15 # Contains Diff::LCS::Block for bin/ldiff.
616
- </span><span class="inferred1"><a name="line16"></a>16
617
- </span><span class="inferred0"><a name="line17"></a>17 # A block is an operation removing, adding, or changing a group of items.
618
- </span><span class="inferred1"><a name="line18"></a>18 # Basically, this is just a list of changes, where each change adds or
619
- </span><span class="inferred0"><a name="line19"></a>19 # deletes a single item. Used by bin/ldiff.
620
- </span><span class="marked1"><a name="line20"></a>20 class Diff::LCS::Block
621
- </span><span class="marked0"><a name="line21"></a>21 attr_reader :changes, :insert, :remove
622
- </span><span class="inferred1"><a name="line22"></a>22
623
- </span><span class="marked0"><a name="line23"></a>23 def initialize(chunk)
624
- </span><span class="uncovered1"><a name="line24"></a>24 @changes = []
625
- </span><span class="uncovered0"><a name="line25"></a>25 @insert = []
626
- </span><span class="uncovered1"><a name="line26"></a>26 @remove = []
627
- </span><span class="uncovered0"><a name="line27"></a>27
628
- </span><span class="uncovered1"><a name="line28"></a>28 chunk.each do |item|
629
- </span><span class="uncovered0"><a name="line29"></a>29 @changes &lt;&lt; item
630
- </span><span class="uncovered1"><a name="line30"></a>30 @remove &lt;&lt; item if item.deleting?
631
- </span><span class="uncovered0"><a name="line31"></a>31 @insert &lt;&lt; item if item.adding?
632
- </span><span class="uncovered1"><a name="line32"></a>32 end
633
- </span><span class="uncovered0"><a name="line33"></a>33 end
634
- </span><span class="inferred1"><a name="line34"></a>34
635
- </span><span class="marked0"><a name="line35"></a>35 def diff_size
636
- </span><span class="uncovered1"><a name="line36"></a>36 @insert.size - @remove.size
637
- </span><span class="uncovered0"><a name="line37"></a>37 end
638
- </span><span class="inferred1"><a name="line38"></a>38
639
- </span><span class="marked0"><a name="line39"></a>39 def op
640
- </span><span class="uncovered1"><a name="line40"></a>40 case [@remove.empty?, @insert.empty?]
641
- </span><span class="uncovered0"><a name="line41"></a>41 when [false, false]
642
- </span><span class="uncovered1"><a name="line42"></a>42 '!'
643
- </span><span class="uncovered0"><a name="line43"></a>43 when [false, true]
644
- </span><span class="uncovered1"><a name="line44"></a>44 '-'
645
- </span><span class="uncovered0"><a name="line45"></a>45 when [true, false]
646
- </span><span class="uncovered1"><a name="line46"></a>46 '+'
647
- </span><span class="uncovered0"><a name="line47"></a>47 else # [true, true]
648
- </span><span class="uncovered1"><a name="line48"></a>48 '^'
649
- </span><span class="uncovered0"><a name="line49"></a>49 end
650
- </span><span class="uncovered1"><a name="line50"></a>50 end
651
- </span><span class="uncovered0"><a name="line51"></a>51 end
601
+ <pre><span class="marked1"><a name="line1"></a> 1 module ClassX
602
+ </span><span class="inferred0"><a name="line2"></a> 2 # you can define classx base class using DSL
603
+ </span><span class="inferred1"><a name="line3"></a> 3 #
604
+ </span><span class="inferred0"><a name="line4"></a> 4 # require 'classx'
605
+ </span><span class="inferred1"><a name="line5"></a> 5 # require 'classx/declare'
606
+ </span><span class="inferred0"><a name="line6"></a> 6 # include ClassX::Declare
607
+ </span><span class="inferred1"><a name="line7"></a> 7 #
608
+ </span><span class="inferred0"><a name="line8"></a> 8 # classx :Klass do
609
+ </span><span class="inferred1"><a name="line9"></a> 9 # has :x
610
+ </span><span class="inferred0"><a name="line10"></a>10 # end
611
+ </span><span class="inferred1"><a name="line11"></a>11 #
612
+ </span><span class="inferred0"><a name="line12"></a>12 # Klass.new(:x =&gt; 10)
613
+ </span><span class="inferred1"><a name="line13"></a>13 #
614
+ </span><span class="inferred0"><a name="line14"></a>14 # or you can define nested.
615
+ </span><span class="inferred1"><a name="line15"></a>15 #
616
+ </span><span class="inferred0"><a name="line16"></a>16 # classx :Klass do
617
+ </span><span class="inferred1"><a name="line17"></a>17 # classx :Klass2 do
618
+ </span><span class="inferred0"><a name="line18"></a>18 # has :x
619
+ </span><span class="inferred1"><a name="line19"></a>19 # end
620
+ </span><span class="inferred0"><a name="line20"></a>20 # end
621
+ </span><span class="inferred1"><a name="line21"></a>21 #
622
+ </span><span class="inferred0"><a name="line22"></a>22 # #=&gt; define Klass::Klass2
623
+ </span><span class="inferred1"><a name="line23"></a>23 #
624
+ </span><span class="marked0"><a name="line24"></a>24 module Declare
625
+ </span><span class="marked1"><a name="line25"></a>25 def classx name, options=[] , ctx=_guess_parent_namespace(), &amp;block
626
+ </span><span class="marked0"><a name="line26"></a>26 options.push(:Declare)
627
+ </span><span class="marked1"><a name="line27"></a>27 klass = Class.new
628
+ </span><span class="marked0"><a name="line28"></a>28 klass.class_eval do
629
+ </span><span class="marked1"><a name="line29"></a>29 options.each do |mod|
630
+ </span><span class="marked0"><a name="line30"></a>30 __send__ ::ClassX::MODULE_USAGE_MAP_OF[mod], ::ClassX.const_get(mod)
631
+ </span><span class="inferred1"><a name="line31"></a>31 end
632
+ </span><span class="marked0"><a name="line32"></a>32 include(ClassX)
633
+ </span><span class="inferred1"><a name="line33"></a>33 end
634
+ </span><span class="marked0"><a name="line34"></a>34 klass.class_eval(&amp;block)
635
+ </span><span class="marked1"><a name="line35"></a>35 ctx.module_eval do
636
+ </span><span class="marked0"><a name="line36"></a>36 const_set(name.to_s.capitalize, klass)
637
+ </span><span class="inferred1"><a name="line37"></a>37 end
638
+ </span><span class="inferred0"><a name="line38"></a>38 end
639
+ </span><span class="inferred1"><a name="line39"></a>39
640
+ </span><span class="marked0"><a name="line40"></a>40 private
641
+ </span><span class="marked1"><a name="line41"></a>41 def _guess_parent_namespace klass=self
642
+ </span><span class="marked0"><a name="line42"></a>42 if self.respond_to? :module_eval
643
+ </span><span class="marked1"><a name="line43"></a>43 klass
644
+ </span><span class="uncovered0"><a name="line44"></a>44 else
645
+ </span><span class="uncovered1"><a name="line45"></a>45 klass.class
646
+ </span><span class="uncovered0"><a name="line46"></a>46 end
647
+ </span><span class="marked1"><a name="line47"></a>47 end
648
+ </span><span class="inferred0"><a name="line48"></a>48 end
649
+ </span><span class="inferred1"><a name="line49"></a>49 end
652
650
  </span></pre><hr/>
653
651
  <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
654
652
  version 0.8.1.2.</p>
@@ -553,7 +553,7 @@ span.run100 {
553
553
  </style>
554
554
  </head>
555
555
  <body><h3>C0 code coverage information</h3>
556
- <p>Generated on Sat Aug 23 14:29:20 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
556
+ <p>Generated on Sat Sep 13 00:31:29 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
557
557
  </p>
558
558
  <hr/>
559
559
  <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
@@ -571,9 +571,9 @@ span.run100 {
571
571
  </thead>
572
572
  <tbody><tr class='light'><td><a href='lib-classx-validate_rb.html'>lib/classx/validate.rb</a>
573
573
  </td>
574
- <td class='lines_total'><tt>38</tt>
574
+ <td class='lines_total'><tt>40</tt>
575
575
  </td>
576
- <td class='lines_code'><tt>15</tt>
576
+ <td class='lines_code'><tt>17</tt>
577
577
  </td>
578
578
  <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
579
579
  &nbsp;</td>
@@ -598,44 +598,46 @@ span.run100 {
598
598
  </tr>
599
599
  </tbody>
600
600
  </table>
601
- <pre><span class="marked1"><a name="line1"></a> 1 module ClassX::Validate
602
- </span><span class="marked0"><a name="line2"></a> 2 private
603
- </span><span class="inferred1"><a name="line3"></a> 3 #
604
- </span><span class="inferred0"><a name="line4"></a> 4 # for validatation Hash parameter declaretively.
605
- </span><span class="inferred1"><a name="line5"></a> 5 #
606
- </span><span class="inferred0"><a name="line6"></a> 6 # require 'classx/validate'
607
- </span><span class="inferred1"><a name="line7"></a> 7 #
608
- </span><span class="inferred0"><a name="line8"></a> 8 # class YourClass
609
- </span><span class="inferred1"><a name="line9"></a> 9 # include ClassX::Validate
610
- </span><span class="inferred0"><a name="line10"></a>10 #
611
- </span><span class="inferred1"><a name="line11"></a>11 # def run params
612
- </span><span class="inferred0"><a name="line12"></a>12 # validate params do
613
- </span><span class="inferred1"><a name="line13"></a>13 # has :x
614
- </span><span class="inferred0"><a name="line14"></a>14 # has :y, :default =&gt; &quot;hoge&quot;, :kind_of =&gt; Hash
615
- </span><span class="inferred1"><a name="line15"></a>15 # end
616
- </span><span class="inferred0"><a name="line16"></a>16 #
617
- </span><span class="inferred1"><a name="line17"></a>17 # # do something with params
618
- </span><span class="inferred0"><a name="line18"></a>18 #
619
- </span><span class="inferred1"><a name="line19"></a>19 # end
620
- </span><span class="inferred0"><a name="line20"></a>20 # end
621
- </span><span class="inferred1"><a name="line21"></a>21 #
622
- </span><span class="inferred0"><a name="line22"></a>22 # YourClass.new.run(:x =&gt; 10) # raise ClassX::AttrRequiredError
623
- </span><span class="inferred1"><a name="line23"></a>23 #
624
- </span><span class="marked0"><a name="line24"></a>24 def validate hash, &amp;block
625
- </span><span class="inferred1"><a name="line25"></a>25 # FIXME: it's experimental feature for caching validate class.
626
- </span><span class="inferred0"><a name="line26"></a>26 # it can use class variable because it use caller[0] as key.
627
- </span><span class="marked1"><a name="line27"></a>27 @@__validate_cached ||= {}
628
- </span><span class="marked0"><a name="line28"></a>28 uniq_key = caller[0]
629
- </span><span class="marked1"><a name="line29"></a>29 unless @@__validate_cached[uniq_key]
630
- </span><span class="marked0"><a name="line30"></a>30 @@__validate_cached[uniq_key] = Class.new
631
- </span><span class="marked1"><a name="line31"></a>31 @@__validate_cached[uniq_key].class_eval do
632
- </span><span class="marked0"><a name="line32"></a>32 include ::ClassX
633
- </span><span class="inferred1"><a name="line33"></a>33 end
634
- </span><span class="marked0"><a name="line34"></a>34 @@__validate_cached[uniq_key].class_eval(&amp;block)
635
- </span><span class="inferred1"><a name="line35"></a>35 end
636
- </span><span class="marked0"><a name="line36"></a>36 @@__validate_cached[uniq_key].new hash
637
- </span><span class="inferred1"><a name="line37"></a>37 end
638
- </span><span class="inferred0"><a name="line38"></a>38 end
601
+ <pre><span class="inferred0"><a name="line1"></a> 1 #
602
+ </span><span class="inferred1"><a name="line2"></a> 2 # for validatation Hash parameter declaretively.
603
+ </span><span class="inferred0"><a name="line3"></a> 3 #
604
+ </span><span class="inferred1"><a name="line4"></a> 4 # require 'classx/validate'
605
+ </span><span class="inferred0"><a name="line5"></a> 5 #
606
+ </span><span class="inferred1"><a name="line6"></a> 6 # class YourClass
607
+ </span><span class="inferred0"><a name="line7"></a> 7 #
608
+ </span><span class="inferred1"><a name="line8"></a> 8 # def run params
609
+ </span><span class="inferred0"><a name="line9"></a> 9 # validated_prams = Class::Validate.validate params do
610
+ </span><span class="inferred1"><a name="line10"></a>10 # has :x
611
+ </span><span class="inferred0"><a name="line11"></a>11 # has :y, :default =&gt; &quot;hoge&quot;, :kind_of =&gt; Hash
612
+ </span><span class="inferred1"><a name="line12"></a>12 # end
613
+ </span><span class="inferred0"><a name="line13"></a>13 #
614
+ </span><span class="inferred1"><a name="line14"></a>14 # # do something with params
615
+ </span><span class="inferred0"><a name="line15"></a>15 #
616
+ </span><span class="inferred1"><a name="line16"></a>16 # end
617
+ </span><span class="inferred0"><a name="line17"></a>17 # end
618
+ </span><span class="inferred1"><a name="line18"></a>18 #
619
+ </span><span class="inferred0"><a name="line19"></a>19 # YourClass.new.run(:x =&gt; 10) # raise ClassX::AttrRequiredError
620
+ </span><span class="inferred1"><a name="line20"></a>20 #
621
+ </span><span class="marked0"><a name="line21"></a>21 module ClassX::Validate
622
+ </span><span class="marked1"><a name="line22"></a>22 private
623
+ </span><span class="marked0"><a name="line23"></a>23 def validate hash, &amp;block #:doc:
624
+ </span><span class="inferred1"><a name="line24"></a>24 # FIXME: it's experimental feature for caching validate class.
625
+ </span><span class="inferred0"><a name="line25"></a>25 # it can use class variable because it use caller[0] as key.
626
+ </span><span class="marked1"><a name="line26"></a>26 @@__validate_cached ||= {}
627
+ </span><span class="marked0"><a name="line27"></a>27 uniq_key = caller[0]
628
+ </span><span class="marked1"><a name="line28"></a>28 unless @@__validate_cached[uniq_key]
629
+ </span><span class="marked0"><a name="line29"></a>29 @@__validate_cached[uniq_key] = Class.new
630
+ </span><span class="marked1"><a name="line30"></a>30 @@__validate_cached[uniq_key].class_eval do
631
+ </span><span class="marked0"><a name="line31"></a>31 include ::ClassX
632
+ </span><span class="marked1"><a name="line32"></a>32 include ::ClassX::Bracketable
633
+ </span><span class="inferred0"><a name="line33"></a>33 end
634
+ </span><span class="marked1"><a name="line34"></a>34 @@__validate_cached[uniq_key].class_eval(&amp;block)
635
+ </span><span class="inferred0"><a name="line35"></a>35 end
636
+ </span><span class="marked1"><a name="line36"></a>36 @@__validate_cached[uniq_key].new hash
637
+ </span><span class="inferred0"><a name="line37"></a>37 end
638
+ </span><span class="inferred1"><a name="line38"></a>38
639
+ </span><span class="marked0"><a name="line39"></a>39 module_function :validate
640
+ </span><span class="inferred1"><a name="line40"></a>40 end
639
641
  </span></pre><hr/>
640
642
  <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
641
643
  version 0.8.1.2.</p>
@@ -553,7 +553,7 @@ span.run100 {
553
553
  </style>
554
554
  </head>
555
555
  <body><h3>C0 code coverage information</h3>
556
- <p>Generated on Sat Aug 23 14:29:19 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
556
+ <p>Generated on Sat Sep 13 00:31:29 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
557
557
  </p>
558
558
  <hr/>
559
559
  <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
@@ -571,9 +571,9 @@ span.run100 {
571
571
  </thead>
572
572
  <tbody><tr class='light'><td><a href='lib-classx_rb.html'>lib/classx.rb</a>
573
573
  </td>
574
- <td class='lines_total'><tt>75</tt>
574
+ <td class='lines_total'><tt>205</tt>
575
575
  </td>
576
- <td class='lines_code'><tt>58</tt>
576
+ <td class='lines_code'><tt>130</tt>
577
577
  </td>
578
578
  <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>100.0%</tt>
579
579
  &nbsp;</td>
@@ -598,81 +598,211 @@ span.run100 {
598
598
  </tr>
599
599
  </tbody>
600
600
  </table>
601
- <pre><span class="marked1"><a name="line1"></a> 1 require 'classx/attribute'
602
- </span><span class="marked0"><a name="line2"></a> 2 require 'classx/attributes'
603
- </span><span class="inferred1"><a name="line3"></a> 3
604
- </span><span class="marked0"><a name="line4"></a> 4 module ClassX
605
- </span><span class="marked1"><a name="line5"></a> 5 autoload :Validate, 'classx/validate'
606
- </span><span class="marked0"><a name="line6"></a> 6 autoload :Commandable, 'classx/commandable'
607
- </span><span class="marked1"><a name="line7"></a> 7 autoload :Declare, 'classx/declare'
608
- </span><span class="marked0"><a name="line8"></a> 8 autoload :Util, 'classx/util'
609
- </span><span class="marked1"><a name="line9"></a> 9 module Role
610
- </span><span class="marked0"><a name="line10"></a>10 autoload :Logger, 'classx/role/logger'
611
- </span><span class="inferred1"><a name="line11"></a>11 end
612
- </span><span class="inferred0"><a name="line12"></a>12
613
- </span><span class="marked1"><a name="line13"></a>13 class InstanceException &lt; Exception; end
614
- </span><span class="marked0"><a name="line14"></a>14 class AttrRequiredError &lt; InstanceException; end
615
- </span><span class="marked1"><a name="line15"></a>15 class InvalidAttrArgument &lt; InstanceException; end
616
- </span><span class="marked0"><a name="line16"></a>16 class LazyOptionShouldHaveDefault &lt; Exception; end
617
- </span><span class="marked1"><a name="line17"></a>17 class OptionalAttrShouldBeWritable &lt; Exception; end
618
- </span><span class="marked0"><a name="line18"></a>18 class RequiredAttrShouldNotHaveDefault &lt; Exception; end
619
- </span><span class="inferred1"><a name="line19"></a>19
620
- </span><span class="marked0"><a name="line20"></a>20 def self.included klass
621
- </span><span class="marked1"><a name="line21"></a>21 klass.extend(Attributes)
622
- </span><span class="marked0"><a name="line22"></a>22 end
623
- </span><span class="inferred1"><a name="line23"></a>23
624
- </span><span class="marked0"><a name="line24"></a>24 def initialize *args
625
- </span><span class="marked1"><a name="line25"></a>25 hash = before_init(*args)
626
- </span><span class="inferred0"><a name="line26"></a>26
627
- </span><span class="marked1"><a name="line27"></a>27 unless hash &amp;&amp; hash.kind_of?(Hash)
628
- </span><span class="marked0"><a name="line28"></a>28 raise ArgumentError, &quot;#{hash.inspect} was wrong as arguments. please specify kind of Hash instance&quot;
629
- </span><span class="inferred1"><a name="line29"></a>29 end
630
- </span><span class="inferred0"><a name="line30"></a>30
631
- </span><span class="inferred1"><a name="line31"></a>31 # allow String or Symbol for key
632
- </span><span class="marked0"><a name="line32"></a>32 tmp_hash = {}
633
- </span><span class="marked1"><a name="line33"></a>33 hash.each do |key,val|
634
- </span><span class="marked0"><a name="line34"></a>34 tmp_hash[key.to_s] = val
635
- </span><span class="inferred1"><a name="line35"></a>35 end
636
- </span><span class="marked0"><a name="line36"></a>36 hash = tmp_hash
637
- </span><span class="inferred1"><a name="line37"></a>37
638
- </span><span class="marked0"><a name="line38"></a>38 cached_attribute_of = attribute_of
639
- </span><span class="marked1"><a name="line39"></a>39 hash.each do |key, val|
640
- </span><span class="marked0"><a name="line40"></a>40 if cached_attribute_of[key]
641
- </span><span class="marked1"><a name="line41"></a>41 cached_attribute_of[key].set val
642
- </span><span class="inferred0"><a name="line42"></a>42 end
643
- </span><span class="inferred1"><a name="line43"></a>43 end
644
- </span><span class="inferred0"><a name="line44"></a>44
645
- </span><span class="marked1"><a name="line45"></a>45 cached_attribute_of.each do |key, val|
646
- </span><span class="marked0"><a name="line46"></a>46 next if val.class.lazy?
647
- </span><span class="marked1"><a name="line47"></a>47 raise AttrRequiredError, &quot;param: :#{key} is required to #{hash.inspect}&quot; if !val.class.optional? &amp;&amp; !val.get
648
- </span><span class="inferred0"><a name="line48"></a>48 end
649
- </span><span class="inferred1"><a name="line49"></a>49
650
- </span><span class="marked0"><a name="line50"></a>50 after_init
651
- </span><span class="inferred1"><a name="line51"></a>51 end
652
- </span><span class="inferred0"><a name="line52"></a>52
653
- </span><span class="marked1"><a name="line53"></a>53 def attribute_of
654
- </span><span class="marked0"><a name="line54"></a>54 hash = {}
655
- </span><span class="marked1"><a name="line55"></a>55 if self.class.attribute_of
656
- </span><span class="marked0"><a name="line56"></a>56 self.class.attribute_of.keys.each do |key|
657
- </span><span class="marked1"><a name="line57"></a>57 hash[key] = __send__ &quot;attribute_of:#{key}&quot;
658
- </span><span class="inferred0"><a name="line58"></a>58 end
659
- </span><span class="inferred1"><a name="line59"></a>59 end
660
- </span><span class="inferred0"><a name="line60"></a>60
661
- </span><span class="marked1"><a name="line61"></a>61 hash
662
- </span><span class="inferred0"><a name="line62"></a>62 end
663
- </span><span class="inferred1"><a name="line63"></a>63
664
- </span><span class="inferred0"><a name="line64"></a>64 # just extend point
665
- </span><span class="marked1"><a name="line65"></a>65 def before_init *args
666
- </span><span class="marked0"><a name="line66"></a>66 raise ArgumentError if args.size &gt; 1
667
- </span><span class="inferred1"><a name="line67"></a>67
668
- </span><span class="marked0"><a name="line68"></a>68 hash = args.first
669
- </span><span class="marked1"><a name="line69"></a>69 hash.nil? ? {} : hash
670
- </span><span class="inferred0"><a name="line70"></a>70 end
671
- </span><span class="inferred1"><a name="line71"></a>71
672
- </span><span class="marked0"><a name="line72"></a>72 def after_init
673
- </span><span class="marked1"><a name="line73"></a>73 end
674
- </span><span class="inferred0"><a name="line74"></a>74
675
- </span><span class="inferred1"><a name="line75"></a>75 end
601
+ <pre><span class="marked1"><a name="line1"></a> 1 require 'classx/attribute'
602
+ </span><span class="marked0"><a name="line2"></a> 2 require 'classx/attributes'
603
+ </span><span class="inferred1"><a name="line3"></a> 3
604
+ </span><span class="inferred0"><a name="line4"></a> 4 # usage
605
+ </span><span class="inferred1"><a name="line5"></a> 5 #
606
+ </span><span class="inferred0"><a name="line6"></a> 6 # require 'classx'
607
+ </span><span class="inferred1"><a name="line7"></a> 7 # class Point
608
+ </span><span class="inferred0"><a name="line8"></a> 8 # include ClassX
609
+ </span><span class="inferred1"><a name="line9"></a> 9 #
610
+ </span><span class="inferred0"><a name="line10"></a> 10 # has :x, :kind_of =&gt; Fixnum
611
+ </span><span class="inferred1"><a name="line11"></a> 11 # has :y, :kind_of =&gt; Fixnum
612
+ </span><span class="inferred0"><a name="line12"></a> 12 # end
613
+ </span><span class="inferred1"><a name="line13"></a> 13 #
614
+ </span><span class="inferred0"><a name="line14"></a> 14 # class Point3D &lt; Point
615
+ </span><span class="inferred1"><a name="line15"></a> 15 # has :z, :writable =&gt; true, :kind_of =&gt; Fixnum, :optional =&gt; true
616
+ </span><span class="inferred0"><a name="line16"></a> 16 # end
617
+ </span><span class="inferred1"><a name="line17"></a> 17 #
618
+ </span><span class="inferred0"><a name="line18"></a> 18 # Point.new(:x =&gt; 30, :y =&gt; 40) #=&gt; &lt;# Point @x=30, @y=40 &gt;
619
+ </span><span class="inferred1"><a name="line19"></a> 19 # point3d = Point3D.new(:x =&gt; 30, :y =&gt; 40, :z =&gt; 50) #=&gt; &lt;# Point3D @x=30, @y=40, @z=50 &gt;
620
+ </span><span class="inferred0"><a name="line20"></a> 20 # point3d.z = 60.0 # raise ClassX::InvalidAttrArgument
621
+ </span><span class="marked1"><a name="line21"></a> 21 module ClassX
622
+ </span><span class="marked0"><a name="line22"></a> 22 autoload :ClassAttributes, 'classx/class_attributes'
623
+ </span><span class="marked1"><a name="line23"></a> 23 autoload :CAttrs, 'classx/class_attributes'
624
+ </span><span class="marked0"><a name="line24"></a> 24 autoload :Validate, 'classx/validate'
625
+ </span><span class="marked1"><a name="line25"></a> 25 autoload :Commandable, 'classx/commandable'
626
+ </span><span class="marked0"><a name="line26"></a> 26 autoload :Declare, 'classx/declare'
627
+ </span><span class="marked1"><a name="line27"></a> 27 autoload :Bracketable, 'classx/bracketable'
628
+ </span><span class="marked0"><a name="line28"></a> 28 module Role
629
+ </span><span class="marked1"><a name="line29"></a> 29 autoload :Logger, 'classx/role/logger'
630
+ </span><span class="inferred0"><a name="line30"></a> 30 end
631
+ </span><span class="inferred1"><a name="line31"></a> 31
632
+ </span><span class="marked0"><a name="line32"></a> 32 MODULE_USAGE_MAP_OF = {
633
+ </span><span class="inferred1"><a name="line33"></a> 33 :ClassAttributes =&gt; :extend,
634
+ </span><span class="inferred0"><a name="line34"></a> 34 :CAttrs =&gt; :extend,
635
+ </span><span class="inferred1"><a name="line35"></a> 35 :Commandable =&gt; :extend,
636
+ </span><span class="inferred0"><a name="line36"></a> 36 :Declare =&gt; :extend,
637
+ </span><span class="inferred1"><a name="line37"></a> 37 :Bracketable =&gt; :include,
638
+ </span><span class="inferred0"><a name="line38"></a> 38 :Validate =&gt; :include,
639
+ </span><span class="inferred1"><a name="line39"></a> 39 }
640
+ </span><span class="inferred0"><a name="line40"></a> 40
641
+ </span><span class="marked1"><a name="line41"></a> 41 class InstanceException &lt; Exception; end
642
+ </span><span class="marked0"><a name="line42"></a> 42 class AttrRequiredError &lt; InstanceException; end
643
+ </span><span class="marked1"><a name="line43"></a> 43 class InvalidAttrArgument &lt; InstanceException; end
644
+ </span><span class="marked0"><a name="line44"></a> 44 class LazyOptionShouldHaveDefault &lt; Exception; end
645
+ </span><span class="marked1"><a name="line45"></a> 45 class OptionalAttrShouldBeWritable &lt; Exception; end
646
+ </span><span class="marked0"><a name="line46"></a> 46 class RequiredAttrShouldNotHaveDefault &lt; Exception; end
647
+ </span><span class="inferred1"><a name="line47"></a> 47
648
+ </span><span class="inferred0"><a name="line48"></a> 48 # *args is Hash in default.
649
+ </span><span class="inferred1"><a name="line49"></a> 49 # Hash should have attribute's key and valid value for attribute.
650
+ </span><span class="inferred0"><a name="line50"></a> 50 # This method checking required value is setted and taking value is valid to attribute.
651
+ </span><span class="inferred1"><a name="line51"></a> 51 #
652
+ </span><span class="marked0"><a name="line52"></a> 52 def initialize *args
653
+ </span><span class="marked1"><a name="line53"></a> 53 hash = before_init(*args)
654
+ </span><span class="inferred0"><a name="line54"></a> 54
655
+ </span><span class="marked1"><a name="line55"></a> 55 unless hash &amp;&amp; hash.kind_of?(Hash)
656
+ </span><span class="marked0"><a name="line56"></a> 56 raise ArgumentError, &quot;#{hash.inspect} was wrong as arguments. please specify kind of Hash instance&quot;
657
+ </span><span class="inferred1"><a name="line57"></a> 57 end
658
+ </span><span class="inferred0"><a name="line58"></a> 58
659
+ </span><span class="inferred1"><a name="line59"></a> 59 # allow String or Symbol for key
660
+ </span><span class="marked0"><a name="line60"></a> 60 tmp_hash = {}
661
+ </span><span class="marked1"><a name="line61"></a> 61 hash.each do |key,val|
662
+ </span><span class="marked0"><a name="line62"></a> 62 tmp_hash[key.to_s] = val
663
+ </span><span class="inferred1"><a name="line63"></a> 63 end
664
+ </span><span class="marked0"><a name="line64"></a> 64 hash = tmp_hash
665
+ </span><span class="inferred1"><a name="line65"></a> 65
666
+ </span><span class="marked0"><a name="line66"></a> 66 hash.each do |key, val|
667
+ </span><span class="marked1"><a name="line67"></a> 67 if attribute_of[key]
668
+ </span><span class="marked0"><a name="line68"></a> 68 attribute_of[key].set val
669
+ </span><span class="inferred1"><a name="line69"></a> 69 end
670
+ </span><span class="inferred0"><a name="line70"></a> 70 end
671
+ </span><span class="inferred1"><a name="line71"></a> 71
672
+ </span><span class="marked0"><a name="line72"></a> 72 attribute_of.each do |key, val|
673
+ </span><span class="marked1"><a name="line73"></a> 73 next if val.class.lazy?
674
+ </span><span class="marked0"><a name="line74"></a> 74 raise AttrRequiredError, &quot;param: :#{key} is required to #{hash.inspect}&quot; if !val.class.optional? &amp;&amp; !val.get
675
+ </span><span class="inferred1"><a name="line75"></a> 75 end
676
+ </span><span class="inferred0"><a name="line76"></a> 76
677
+ </span><span class="marked1"><a name="line77"></a> 77 after_init
678
+ </span><span class="inferred0"><a name="line78"></a> 78 end
679
+ </span><span class="inferred1"><a name="line79"></a> 79
680
+ </span><span class="inferred0"><a name="line80"></a> 80 # return Hash of attribute's name as a key and attribute's meta class instance as a value.
681
+ </span><span class="inferred1"><a name="line81"></a> 81 # for example,
682
+ </span><span class="inferred0"><a name="line82"></a> 82 #
683
+ </span><span class="inferred1"><a name="line83"></a> 83 # class YourClass
684
+ </span><span class="inferred0"><a name="line84"></a> 84 # include ClassX
685
+ </span><span class="inferred1"><a name="line85"></a> 85 # has :x
686
+ </span><span class="inferred0"><a name="line86"></a> 86 # end
687
+ </span><span class="inferred1"><a name="line87"></a> 87 #
688
+ </span><span class="inferred0"><a name="line88"></a> 88 # obj = YourClass.new(:x =&gt; 10)
689
+ </span><span class="inferred1"><a name="line89"></a> 89 # obj.attribute_of #=&gt; { &quot;x&quot; =&gt; &lt;#&lt;ClassX::Attribute&gt; parent=&lt;# YourClass&gt; ... &gt; }
690
+ </span><span class="inferred0"><a name="line90"></a> 90 #
691
+ </span><span class="marked1"><a name="line91"></a> 91 def attribute_of
692
+ </span><span class="marked0"><a name="line92"></a> 92 unless instance_variable_defined?('@__attribute_of') &amp;&amp; @__attribute_of
693
+ </span><span class="marked1"><a name="line93"></a> 93 @__attribute_of = {}
694
+ </span><span class="marked0"><a name="line94"></a> 94 if self.class.attribute_of
695
+ </span><span class="marked1"><a name="line95"></a> 95 self.class.attribute_of.keys.each do |key|
696
+ </span><span class="marked0"><a name="line96"></a> 96 @__attribute_of[key] = __send__ &quot;attribute_of:#{key}&quot;
697
+ </span><span class="inferred1"><a name="line97"></a> 97 end
698
+ </span><span class="inferred0"><a name="line98"></a> 98 end
699
+ </span><span class="inferred1"><a name="line99"></a> 99 end
700
+ </span><span class="inferred0"><a name="line100"></a>100
701
+ </span><span class="marked1"><a name="line101"></a>101 @__attribute_of
702
+ </span><span class="inferred0"><a name="line102"></a>102 end
703
+ </span><span class="inferred1"><a name="line103"></a>103
704
+ </span><span class="inferred0"><a name="line104"></a>104 # processing initialize argument to hash
705
+ </span><span class="inferred1"><a name="line105"></a>105 # you can override this method for not taking initializer your classx based class.
706
+ </span><span class="marked0"><a name="line106"></a>106 def before_init *args
707
+ </span><span class="marked1"><a name="line107"></a>107 raise ArgumentError if args.size &gt; 1
708
+ </span><span class="inferred0"><a name="line108"></a>108
709
+ </span><span class="marked1"><a name="line109"></a>109 hash = args.first
710
+ </span><span class="marked0"><a name="line110"></a>110 hash.nil? ? {} : hash
711
+ </span><span class="inferred1"><a name="line111"></a>111 end
712
+ </span><span class="inferred0"><a name="line112"></a>112
713
+ </span><span class="marked1"><a name="line113"></a>113 alias process_init_args before_init
714
+ </span><span class="inferred0"><a name="line114"></a>114
715
+ </span><span class="inferred1"><a name="line115"></a>115 # automatically called this method on last of #initialize.
716
+ </span><span class="inferred0"><a name="line116"></a>116 # you can override this method.
717
+ </span><span class="marked1"><a name="line117"></a>117 def after_init
718
+ </span><span class="marked0"><a name="line118"></a>118 end
719
+ </span><span class="inferred1"><a name="line119"></a>119
720
+ </span><span class="inferred0"><a name="line120"></a>120 # shared implementation for comparing classx based object.
721
+ </span><span class="marked1"><a name="line121"></a>121 def == other
722
+ </span><span class="marked0"><a name="line122"></a>122 return false unless other.kind_of? self.class
723
+ </span><span class="marked1"><a name="line123"></a>123 attribute_of.all? do |key, val|
724
+ </span><span class="marked0"><a name="line124"></a>124 val.get == other.__send__(key)
725
+ </span><span class="inferred1"><a name="line125"></a>125 end
726
+ </span><span class="inferred0"><a name="line126"></a>126 end
727
+ </span><span class="inferred1"><a name="line127"></a>127
728
+ </span><span class="marked0"><a name="line128"></a>128 UNSERIALIZE_INSTANCE_VARIABLES = [&quot;@__attribute_of&quot;, &quot;@__attribute_data_of&quot;]
729
+ </span><span class="inferred1"><a name="line129"></a>129
730
+ </span><span class="inferred0"><a name="line130"></a>130 # convert attribute key and value to Hash.
731
+ </span><span class="marked1"><a name="line131"></a>131 def to_hash
732
+ </span><span class="marked0"><a name="line132"></a>132 result = {}
733
+ </span><span class="inferred1"><a name="line133"></a>133
734
+ </span><span class="marked0"><a name="line134"></a>134 attribute_of.each do |key, val|
735
+ </span><span class="marked1"><a name="line135"></a>135 result[key] = val.get
736
+ </span><span class="inferred0"><a name="line136"></a>136 end
737
+ </span><span class="inferred1"><a name="line137"></a>137
738
+ </span><span class="marked0"><a name="line138"></a>138 result
739
+ </span><span class="inferred1"><a name="line139"></a>139 end
740
+ </span><span class="inferred0"><a name="line140"></a>140
741
+ </span><span class="inferred1"><a name="line141"></a>141 # dupping classx based class.
742
+ </span><span class="marked0"><a name="line142"></a>142 def dup
743
+ </span><span class="marked1"><a name="line143"></a>143 self.class.new(to_hash)
744
+ </span><span class="marked0"><a name="line144"></a>144 end
745
+ </span><span class="inferred1"><a name="line145"></a>145
746
+ </span><span class="inferred0"><a name="line146"></a>146 # for Marshal.dump
747
+ </span><span class="marked1"><a name="line147"></a>147 def marshal_dump
748
+ </span><span class="marked0"><a name="line148"></a>148 dump_of = {}
749
+ </span><span class="marked1"><a name="line149"></a>149 dump_of[:attribute_of] = to_hash
750
+ </span><span class="marked0"><a name="line150"></a>150 dump_of[:instance_variable_of] = {}
751
+ </span><span class="marked1"><a name="line151"></a>151 ( instance_variables.map {|ival| ival.to_s } - UNSERIALIZE_INSTANCE_VARIABLES ).each do |ival|
752
+ </span><span class="marked0"><a name="line152"></a>152 dump_of[:instance_variable_of][ival] = instance_variable_get(ival)
753
+ </span><span class="inferred1"><a name="line153"></a>153 end
754
+ </span><span class="inferred0"><a name="line154"></a>154
755
+ </span><span class="marked1"><a name="line155"></a>155 dump_of
756
+ </span><span class="inferred0"><a name="line156"></a>156 end
757
+ </span><span class="inferred1"><a name="line157"></a>157
758
+ </span><span class="inferred0"><a name="line158"></a>158 # for Marshal.load
759
+ </span><span class="marked1"><a name="line159"></a>159 def marshal_load val
760
+ </span><span class="marked0"><a name="line160"></a>160 self.attribute_of.each do |k, v|
761
+ </span><span class="marked1"><a name="line161"></a>161 v.set(val[:attribute_of][k])
762
+ </span><span class="inferred0"><a name="line162"></a>162 end
763
+ </span><span class="marked1"><a name="line163"></a>163 val[:instance_variable_of].each do |key, val|
764
+ </span><span class="marked0"><a name="line164"></a>164 instance_variable_set(key, val)
765
+ </span><span class="inferred1"><a name="line165"></a>165 end
766
+ </span><span class="inferred0"><a name="line166"></a>166 end
767
+ </span><span class="inferred1"><a name="line167"></a>167
768
+ </span><span class="inferred0"><a name="line168"></a>168 # for YAML.dump
769
+ </span><span class="marked1"><a name="line169"></a>169 def to_yaml opts={}
770
+ </span><span class="marked0"><a name="line170"></a>170 require 'yaml'
771
+ </span><span class="marked1"><a name="line171"></a>171 YAML.quick_emit(self, opts) do |out|
772
+ </span><span class="marked0"><a name="line172"></a>172 out.map( taguri, to_yaml_style ) do |map|
773
+ </span><span class="marked1"><a name="line173"></a>173 attribute_of = {}
774
+ </span><span class="marked0"><a name="line174"></a>174 to_hash.each do |key, val|
775
+ </span><span class="marked1"><a name="line175"></a>175 attribute_of[key] = val
776
+ </span><span class="inferred0"><a name="line176"></a>176 end
777
+ </span><span class="marked1"><a name="line177"></a>177 map.add(:attribute_of, attribute_of)
778
+ </span><span class="inferred0"><a name="line178"></a>178
779
+ </span><span class="marked1"><a name="line179"></a>179 instance_variable_of = {}
780
+ </span><span class="marked0"><a name="line180"></a>180 ( instance_variables.map {|ival| ival.to_s } - UNSERIALIZE_INSTANCE_VARIABLES ).each do |ival|
781
+ </span><span class="marked1"><a name="line181"></a>181 instance_variable_of[ival] = instance_variable_get(ival)
782
+ </span><span class="inferred0"><a name="line182"></a>182 end
783
+ </span><span class="marked1"><a name="line183"></a>183 map.add(:instance_variable_of, instance_variable_of)
784
+ </span><span class="inferred0"><a name="line184"></a>184 end
785
+ </span><span class="inferred1"><a name="line185"></a>185 end
786
+ </span><span class="inferred0"><a name="line186"></a>186 end
787
+ </span><span class="inferred1"><a name="line187"></a>187
788
+ </span><span class="inferred0"><a name="line188"></a>188 # for YAML.load
789
+ </span><span class="marked1"><a name="line189"></a>189 def yaml_initialize tag, val
790
+ </span><span class="marked0"><a name="line190"></a>190 self.attribute_of.each do |k, v|
791
+ </span><span class="marked1"><a name="line191"></a>191 v.set(val[:attribute_of][k])
792
+ </span><span class="inferred0"><a name="line192"></a>192 end
793
+ </span><span class="inferred1"><a name="line193"></a>193
794
+ </span><span class="marked0"><a name="line194"></a>194 val[:instance_variable_of].each do |k, v|
795
+ </span><span class="marked1"><a name="line195"></a>195 instance_variable_set(k, v)
796
+ </span><span class="inferred0"><a name="line196"></a>196 end
797
+ </span><span class="inferred1"><a name="line197"></a>197 end
798
+ </span><span class="inferred0"><a name="line198"></a>198
799
+ </span><span class="marked1"><a name="line199"></a>199 private
800
+ </span><span class="inferred0"><a name="line200"></a>200
801
+ </span><span class="marked1"><a name="line201"></a>201 def self.included klass
802
+ </span><span class="marked0"><a name="line202"></a>202 klass.extend(Attributes)
803
+ </span><span class="marked1"><a name="line203"></a>203 end
804
+ </span><span class="inferred0"><a name="line204"></a>204
805
+ </span><span class="inferred1"><a name="line205"></a>205 end
676
806
  </span></pre><hr/>
677
807
  <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
678
808
  version 0.8.1.2.</p>