classx 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/ChangeLog +84 -0
  2. data/README +4 -2
  3. data/Rakefile +1 -1
  4. data/bench/attribute_set.rb +56 -0
  5. data/bench/initialize.rb +59 -0
  6. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-block_rb.html +1 -1
  7. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-callbacks_rb.html +1 -1
  8. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-change_rb.html +1 -1
  9. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-hunk_rb.html +1 -1
  10. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs_rb.html +1 -1
  11. data/doc/output/coverage/-Library-Ruby-Gems-gems-rcov-0_8_1_2_0-lib-rcov_rb.html +1 -1
  12. data/doc/output/coverage/index.html +27 -27
  13. data/doc/output/coverage/lib-classx-attribute_rb.html +82 -75
  14. data/doc/output/coverage/lib-classx-attributes_rb.html +101 -94
  15. data/doc/output/coverage/lib-classx-validate_rb.html +14 -11
  16. data/doc/output/coverage/lib-classx_rb.html +75 -65
  17. data/example/commandable.rb +9 -3
  18. data/lib/classx.rb +12 -2
  19. data/lib/classx/attribute.rb +10 -3
  20. data/lib/classx/attributes.rb +10 -3
  21. data/lib/classx/commandable.rb +27 -7
  22. data/lib/classx/declare.rb +12 -0
  23. data/lib/classx/role/logger.rb +70 -0
  24. data/lib/classx/validate.rb +6 -3
  25. data/spec/classx/default_option_spec.rb +16 -12
  26. data/spec/classx/handles_spec.rb +5 -2
  27. data/spec/classx/with_coerce.rb +12 -4
  28. data/spec/classx/with_extend.rb +3 -1
  29. data/spec/classx/with_include.rb +3 -1
  30. data/spec/classx/with_multiple_class_spec.rb +4 -2
  31. data/spec/classx/without_accessor_spec.rb +2 -1
  32. data/spec/classx/without_anyoption_spec.rb +3 -1
  33. data/spec/classx/writable_option_spec.rb +8 -4
  34. data/spec/classx_attributes_spec.rb +6 -1
  35. data/tasks/basic_config.rake +1 -1
  36. metadata +7 -2
@@ -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 Thu Aug 21 17:23:12 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
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>
557
557
  </p>
558
558
  <hr/>
559
559
  <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
@@ -571,24 +571,24 @@ span.run100 {
571
571
  </thead>
572
572
  <tbody><tr class='light'><td><a href='lib-classx-attributes_rb.html'>lib/classx/attributes.rb</a>
573
573
  </td>
574
- <td class='lines_total'><tt>85</tt>
574
+ <td class='lines_total'><tt>92</tt>
575
575
  </td>
576
- <td class='lines_code'><tt>70</tt>
576
+ <td class='lines_code'><tt>76</tt>
577
577
  </td>
578
- <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>95.3%</tt>
578
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>97.8%</tt>
579
579
  &nbsp;</td>
580
- <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='95'/>
581
- <td class='uncovered' width='5'/>
580
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='98'/>
581
+ <td class='uncovered' width='2'/>
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'>94.3%</tt>
588
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>97.4%</tt>
589
589
  &nbsp;</td>
590
- <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='94'/>
591
- <td class='uncovered' width='6'/>
590
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='97'/>
591
+ <td class='uncovered' width='3'/>
592
592
  </tr>
593
593
  </table>
594
594
  </td>
@@ -598,91 +598,98 @@ span.run100 {
598
598
  </tr>
599
599
  </tbody>
600
600
  </table>
601
- <pre><span class="marked0"><a name="line1"></a> 1 class ClassX
602
- </span><span class="marked1"><a name="line2"></a> 2 module Attributes
603
- </span><span class="marked0"><a name="line3"></a> 3 ATTRIBUTE_REGEX = /\Aattribute_of:(\w+)\z/
604
- </span><span class="inferred1"><a name="line4"></a> 4
605
- </span><span class="marked0"><a name="line5"></a> 5 def attribute_of
606
- </span><span class="marked1"><a name="line6"></a> 6 unless @__attribute_of
607
- </span><span class="marked0"><a name="line7"></a> 7 @__attribute_of = {}
608
- </span><span class="marked1"><a name="line8"></a> 8 private_instance_methods.select {|meth| meth.to_s =~ ATTRIBUTE_REGEX }.each do |meth|
609
- </span><span class="marked0"><a name="line9"></a> 9 key = meth.to_s.sub(ATTRIBUTE_REGEX) { $1 }
610
- </span><span class="marked1"><a name="line10"></a>10 @__attribute_of[key] = __send__ &quot;attribute_of:#{key}&quot;
611
- </span><span class="inferred0"><a name="line11"></a>11 end
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="marked1"><a name="line14"></a>14 @__attribute_of
615
- </span><span class="inferred0"><a name="line15"></a>15 end
616
- </span><span class="inferred1"><a name="line16"></a>16
617
- </span><span class="marked0"><a name="line17"></a>17 private
618
- </span><span class="marked1"><a name="line18"></a>18 def define_attribute name, attribute
619
- </span><span class="marked0"><a name="line19"></a>19 klass_attribute = ClassX::AttributeFactory.create(attribute)
620
- </span><span class="marked1"><a name="line20"></a>20 mod = Module.new
621
- </span><span class="marked0"><a name="line21"></a>21 mod.module_eval do
622
- </span><span class="marked1"><a name="line22"></a>22 define_method &quot;attribute_of:#{name}&quot; do
623
- </span><span class="uncovered0"><a name="line23"></a>23 klass_attribute
624
- </span><span class="uncovered1"><a name="line24"></a>24 end
625
- </span><span class="inferred0"><a name="line25"></a>25
626
- </span><span class="marked1"><a name="line26"></a>26 private &quot;attribute_of:#{name}&quot;
627
- </span><span class="inferred0"><a name="line27"></a>27 end
628
- </span><span class="marked1"><a name="line28"></a>28 self.extend(mod)
629
- </span><span class="marked0"><a name="line29"></a>29 @__attribute_of ||= {}
630
- </span><span class="marked1"><a name="line30"></a>30 @__attribute_of[name] = klass_attribute
631
- </span><span class="inferred0"><a name="line31"></a>31
632
- </span><span class="marked1"><a name="line32"></a>32 define_method &quot;attribute_of:#{name}&quot; do
633
- </span><span class="marked0"><a name="line33"></a>33 @__attribute_of ||= {}
634
- </span><span class="marked1"><a name="line34"></a>34 @__attribute_of[name] ||= klass_attribute.new(self)
635
- </span><span class="inferred0"><a name="line35"></a>35 end
636
- </span><span class="inferred1"><a name="line36"></a>36
637
- </span><span class="marked0"><a name="line37"></a>37 private &quot;attribute_of:#{name}&quot;
638
- </span><span class="inferred1"><a name="line38"></a>38 end
639
- </span><span class="inferred0"><a name="line39"></a>39
640
- </span><span class="marked1"><a name="line40"></a>40 def add_attribute name, attrs={}
641
- </span><span class="marked0"><a name="line41"></a>41 name = name.to_s
642
- </span><span class="inferred1"><a name="line42"></a>42
643
- </span><span class="marked0"><a name="line43"></a>43 define_attribute(name, attrs)
644
- </span><span class="inferred1"><a name="line44"></a>44
645
- </span><span class="marked0"><a name="line45"></a>45 define_method name do
646
- </span><span class="marked1"><a name="line46"></a>46 attribute_of[name].get
647
- </span><span class="inferred0"><a name="line47"></a>47 end
648
- </span><span class="inferred1"><a name="line48"></a>48
649
- </span><span class="marked0"><a name="line49"></a>49 define_method &quot;#{name}=&quot; do |val|
650
- </span><span class="uncovered1"><a name="line50"></a>50 attribute_of[name].set val
651
- </span><span class="uncovered0"><a name="line51"></a>51 end
652
- </span><span class="inferred1"><a name="line52"></a>52
653
- </span><span class="marked0"><a name="line53"></a>53 cached_attribute_of = attribute_of
654
- </span><span class="marked1"><a name="line54"></a>54 if cached_attribute_of[name]
655
- </span><span class="marked0"><a name="line55"></a>55 unless cached_attribute_of[name].config[:writable]
656
- </span><span class="marked1"><a name="line56"></a>56 private &quot;#{name}=&quot;
657
- </span><span class="inferred0"><a name="line57"></a>57 end
658
- </span><span class="inferred1"><a name="line58"></a>58
659
- </span><span class="marked0"><a name="line59"></a>59 if cached_attribute_of[name].config[:handles]
660
- </span><span class="marked1"><a name="line60"></a>60 case cached_attribute_of[name].config[:handles]
661
- </span><span class="marked0"><a name="line61"></a>61 when Hash
662
- </span><span class="marked1"><a name="line62"></a>62 cached_attribute_of[name].config[:handles].each do |before, after|
663
- </span><span class="marked0"><a name="line63"></a>63 define_method before do
664
- </span><span class="marked1"><a name="line64"></a>64 attribute_of[name].get.__send__ after
665
- </span><span class="inferred0"><a name="line65"></a>65 end
666
- </span><span class="inferred1"><a name="line66"></a>66 end
667
- </span><span class="marked0"><a name="line67"></a>67 when Array
668
- </span><span class="marked1"><a name="line68"></a>68 cached_attribute_of[name].config[:handles].each do |meth|
669
- </span><span class="marked0"><a name="line69"></a>69 define_method meth do
670
- </span><span class="marked1"><a name="line70"></a>70 attribute_of[name].get.__send__ meth
671
- </span><span class="inferred0"><a name="line71"></a>71 end
672
- </span><span class="inferred1"><a name="line72"></a>72 end
673
- </span><span class="inferred0"><a name="line73"></a>73 end
674
- </span><span class="inferred1"><a name="line74"></a>74 end
675
- </span><span class="inferred0"><a name="line75"></a>75 end
676
- </span><span class="inferred1"><a name="line76"></a>76 end
677
- </span><span class="inferred0"><a name="line77"></a>77
678
- </span><span class="marked1"><a name="line78"></a>78 alias has add_attribute
679
- </span><span class="inferred0"><a name="line79"></a>79
680
- </span><span class="marked1"><a name="line80"></a>80 def included klass
681
- </span><span class="marked0"><a name="line81"></a>81 klass.extend self
682
- </span><span class="marked1"><a name="line82"></a>82 end
683
- </span><span class="inferred0"><a name="line83"></a>83
684
- </span><span class="inferred1"><a name="line84"></a>84 end
685
- </span><span class="inferred0"><a name="line85"></a>85 end
601
+ <pre><span class="marked1"><a name="line1"></a> 1 module ClassX
602
+ </span><span class="marked0"><a name="line2"></a> 2 module Attributes
603
+ </span><span class="marked1"><a name="line3"></a> 3 ATTRIBUTE_REGEX = /\Aattribute_of:(\w+)\z/
604
+ </span><span class="inferred0"><a name="line4"></a> 4
605
+ </span><span class="marked1"><a name="line5"></a> 5 def attribute_of
606
+ </span><span class="marked0"><a name="line6"></a> 6 unless @__attribute_of
607
+ </span><span class="marked1"><a name="line7"></a> 7 @__attribute_of = {}
608
+ </span><span class="marked0"><a name="line8"></a> 8 private_instance_methods.select {|meth| meth.to_s =~ ATTRIBUTE_REGEX }.each do |meth|
609
+ </span><span class="marked1"><a name="line9"></a> 9 key = meth.to_s.sub(ATTRIBUTE_REGEX) { $1 }
610
+ </span><span class="marked0"><a name="line10"></a>10 @__attribute_of[key] = __send__ &quot;attribute_of:#{key}&quot;
611
+ </span><span class="inferred1"><a name="line11"></a>11 end
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="marked0"><a name="line14"></a>14 @__attribute_of
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="marked1"><a name="line17"></a>17 private
618
+ </span><span class="marked0"><a name="line18"></a>18 def define_attribute name, attribute
619
+ </span><span class="marked1"><a name="line19"></a>19 klass_attribute = ClassX::AttributeFactory.create(attribute)
620
+ </span><span class="marked0"><a name="line20"></a>20 mod = Module.new
621
+ </span><span class="marked1"><a name="line21"></a>21 begin
622
+ </span><span class="marked0"><a name="line22"></a>22 mod = self.const_get('ClassMethods')
623
+ </span><span class="inferred1"><a name="line23"></a>23 rescue NameError =&gt; e
624
+ </span><span class="marked0"><a name="line24"></a>24 mod = Module.new
625
+ </span><span class="marked1"><a name="line25"></a>25 const_set('ClassMethods', mod)
626
+ </span><span class="inferred0"><a name="line26"></a>26 end
627
+ </span><span class="marked1"><a name="line27"></a>27 mod.module_eval do
628
+ </span><span class="marked0"><a name="line28"></a>28 define_method &quot;attribute_of:#{name}&quot; do
629
+ </span><span class="marked1"><a name="line29"></a>29 klass_attribute
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 private &quot;attribute_of:#{name}&quot;
633
+ </span><span class="inferred1"><a name="line33"></a>33 end
634
+ </span><span class="marked0"><a name="line34"></a>34 self.extend(mod)
635
+ </span><span class="marked1"><a name="line35"></a>35 @__attribute_of ||= self.attribute_of
636
+ </span><span class="marked0"><a name="line36"></a>36 @__attribute_of[name] = klass_attribute
637
+ </span><span class="inferred1"><a name="line37"></a>37
638
+ </span><span class="marked0"><a name="line38"></a>38 define_method &quot;attribute_of:#{name}&quot; do
639
+ </span><span class="marked1"><a name="line39"></a>39 @__attribute_of ||= {}
640
+ </span><span class="marked0"><a name="line40"></a>40 @__attribute_of[name] ||= klass_attribute.new(self)
641
+ </span><span class="inferred1"><a name="line41"></a>41 end
642
+ </span><span class="inferred0"><a name="line42"></a>42
643
+ </span><span class="marked1"><a name="line43"></a>43 private &quot;attribute_of:#{name}&quot;
644
+ </span><span class="inferred0"><a name="line44"></a>44 end
645
+ </span><span class="inferred1"><a name="line45"></a>45
646
+ </span><span class="marked0"><a name="line46"></a>46 def add_attribute name, attrs={}
647
+ </span><span class="marked1"><a name="line47"></a>47 name = name.to_s
648
+ </span><span class="inferred0"><a name="line48"></a>48
649
+ </span><span class="marked1"><a name="line49"></a>49 define_attribute(name, attrs)
650
+ </span><span class="inferred0"><a name="line50"></a>50
651
+ </span><span class="marked1"><a name="line51"></a>51 define_method name do
652
+ </span><span class="marked0"><a name="line52"></a>52 attribute_of[name].get
653
+ </span><span class="inferred1"><a name="line53"></a>53 end
654
+ </span><span class="inferred0"><a name="line54"></a>54
655
+ </span><span class="marked1"><a name="line55"></a>55 define_method &quot;#{name}=&quot; do |val|
656
+ </span><span class="uncovered0"><a name="line56"></a>56 attribute_of[name].set val
657
+ </span><span class="uncovered1"><a name="line57"></a>57 end
658
+ </span><span class="inferred0"><a name="line58"></a>58
659
+ </span><span class="marked1"><a name="line59"></a>59 cached_attribute_of = attribute_of
660
+ </span><span class="marked0"><a name="line60"></a>60 if cached_attribute_of[name]
661
+ </span><span class="marked1"><a name="line61"></a>61 unless cached_attribute_of[name].config[:writable]
662
+ </span><span class="marked0"><a name="line62"></a>62 private &quot;#{name}=&quot;
663
+ </span><span class="inferred1"><a name="line63"></a>63 end
664
+ </span><span class="inferred0"><a name="line64"></a>64
665
+ </span><span class="marked1"><a name="line65"></a>65 if cached_attribute_of[name].config[:handles]
666
+ </span><span class="marked0"><a name="line66"></a>66 case cached_attribute_of[name].config[:handles]
667
+ </span><span class="marked1"><a name="line67"></a>67 when Hash
668
+ </span><span class="marked0"><a name="line68"></a>68 cached_attribute_of[name].config[:handles].each do |before, after|
669
+ </span><span class="marked1"><a name="line69"></a>69 define_method before do
670
+ </span><span class="marked0"><a name="line70"></a>70 attribute_of[name].get.__send__ after
671
+ </span><span class="inferred1"><a name="line71"></a>71 end
672
+ </span><span class="inferred0"><a name="line72"></a>72 end
673
+ </span><span class="marked1"><a name="line73"></a>73 when Array
674
+ </span><span class="marked0"><a name="line74"></a>74 cached_attribute_of[name].config[:handles].each do |meth|
675
+ </span><span class="marked1"><a name="line75"></a>75 define_method meth do
676
+ </span><span class="marked0"><a name="line76"></a>76 attribute_of[name].get.__send__ meth
677
+ </span><span class="inferred1"><a name="line77"></a>77 end
678
+ </span><span class="inferred0"><a name="line78"></a>78 end
679
+ </span><span class="inferred1"><a name="line79"></a>79 end
680
+ </span><span class="inferred0"><a name="line80"></a>80 end
681
+ </span><span class="inferred1"><a name="line81"></a>81 end
682
+ </span><span class="inferred0"><a name="line82"></a>82 end
683
+ </span><span class="inferred1"><a name="line83"></a>83
684
+ </span><span class="marked0"><a name="line84"></a>84 alias has add_attribute
685
+ </span><span class="inferred1"><a name="line85"></a>85
686
+ </span><span class="inferred0"><a name="line86"></a>86 # hook for module to ClassX base class.
687
+ </span><span class="marked1"><a name="line87"></a>87 def included klass
688
+ </span><span class="marked0"><a name="line88"></a>88 klass.extend(self.const_get('ClassMethods'))
689
+ </span><span class="marked1"><a name="line89"></a>89 end
690
+ </span><span class="inferred0"><a name="line90"></a>90
691
+ </span><span class="inferred1"><a name="line91"></a>91 end
692
+ </span><span class="inferred0"><a name="line92"></a>92 end
686
693
  </span></pre><hr/>
687
694
  <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
688
695
  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 Thu Aug 21 17:23:12 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
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>
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>35</tt>
574
+ <td class='lines_total'><tt>38</tt>
575
575
  </td>
576
- <td class='lines_code'><tt>12</tt>
576
+ <td class='lines_code'><tt>15</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>
@@ -605,8 +605,8 @@ span.run100 {
605
605
  </span><span class="inferred1"><a name="line5"></a> 5 #
606
606
  </span><span class="inferred0"><a name="line6"></a> 6 # require 'classx/validate'
607
607
  </span><span class="inferred1"><a name="line7"></a> 7 #
608
- </span><span class="inferred0"><a name="line8"></a> 8 # class YourClass &lt; ClassX
609
- </span><span class="inferred1"><a name="line9"></a> 9 # include Validate
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
610
  </span><span class="inferred0"><a name="line10"></a>10 #
611
611
  </span><span class="inferred1"><a name="line11"></a>11 # def run params
612
612
  </span><span class="inferred0"><a name="line12"></a>12 # validate params do
@@ -627,12 +627,15 @@ span.run100 {
627
627
  </span><span class="marked1"><a name="line27"></a>27 @@__validate_cached ||= {}
628
628
  </span><span class="marked0"><a name="line28"></a>28 uniq_key = caller[0]
629
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(ClassX)
631
- </span><span class="marked1"><a name="line31"></a>31 @@__validate_cached[uniq_key].class_eval(&amp;block)
632
- </span><span class="inferred0"><a name="line32"></a>32 end
633
- </span><span class="marked1"><a name="line33"></a>33 @@__validate_cached[uniq_key].new hash
634
- </span><span class="inferred0"><a name="line34"></a>34 end
635
- </span><span class="inferred1"><a name="line35"></a>35 end
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
636
639
  </span></pre><hr/>
637
640
  <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
638
641
  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 Thu Aug 21 17:23:12 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
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>
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>65</tt>
574
+ <td class='lines_total'><tt>75</tt>
575
575
  </td>
576
- <td class='lines_code'><tt>49</tt>
576
+ <td class='lines_code'><tt>58</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>
@@ -601,68 +601,78 @@ span.run100 {
601
601
  <pre><span class="marked1"><a name="line1"></a> 1 require 'classx/attribute'
602
602
  </span><span class="marked0"><a name="line2"></a> 2 require 'classx/attributes'
603
603
  </span><span class="inferred1"><a name="line3"></a> 3
604
- </span><span class="marked0"><a name="line4"></a> 4 class ClassX
605
- </span><span class="marked1"><a name="line5"></a> 5 class InstanceException &lt; Exception; end
606
- </span><span class="marked0"><a name="line6"></a> 6 class AttrRequiredError &lt; InstanceException; end
607
- </span><span class="marked1"><a name="line7"></a> 7 class InvalidAttrArgument &lt; InstanceException; end
608
- </span><span class="marked0"><a name="line8"></a> 8 class LazyOptionShouldHaveDefault &lt; Exception; end
609
- </span><span class="marked1"><a name="line9"></a> 9 class OptionalAttrShouldBeWritable &lt; Exception; end
610
- </span><span class="marked0"><a name="line10"></a>10 class RequiredAttrShouldNotHaveDefault &lt; Exception; end
611
- </span><span class="inferred1"><a name="line11"></a>11
612
- </span><span class="marked0"><a name="line12"></a>12 extend Attributes
613
- </span><span class="inferred1"><a name="line13"></a>13
614
- </span><span class="marked0"><a name="line14"></a>14 def initialize *args
615
- </span><span class="marked1"><a name="line15"></a>15 hash = before_init(*args)
616
- </span><span class="inferred0"><a name="line16"></a>16
617
- </span><span class="marked1"><a name="line17"></a>17 unless hash &amp;&amp; hash.kind_of?(Hash)
618
- </span><span class="marked0"><a name="line18"></a>18 raise ArgumentError, &quot;#{hash.inspect} was wrong as arguments. please specify kind of Hash instance&quot;
619
- </span><span class="inferred1"><a name="line19"></a>19 end
620
- </span><span class="inferred0"><a name="line20"></a>20
621
- </span><span class="inferred1"><a name="line21"></a>21 # allow String or Symbol for key
622
- </span><span class="marked0"><a name="line22"></a>22 tmp_hash = {}
623
- </span><span class="marked1"><a name="line23"></a>23 hash.each do |key,val|
624
- </span><span class="marked0"><a name="line24"></a>24 tmp_hash[key.to_s] = val
625
- </span><span class="inferred1"><a name="line25"></a>25 end
626
- </span><span class="marked0"><a name="line26"></a>26 hash = tmp_hash
627
- </span><span class="inferred1"><a name="line27"></a>27
628
- </span><span class="marked0"><a name="line28"></a>28 cached_attribute_of = attribute_of
629
- </span><span class="marked1"><a name="line29"></a>29 hash.each do |key, val|
630
- </span><span class="marked0"><a name="line30"></a>30 if cached_attribute_of[key]
631
- </span><span class="marked1"><a name="line31"></a>31 cached_attribute_of[key].set val
632
- </span><span class="inferred0"><a name="line32"></a>32 end
633
- </span><span class="inferred1"><a name="line33"></a>33 end
634
- </span><span class="inferred0"><a name="line34"></a>34
635
- </span><span class="marked1"><a name="line35"></a>35 cached_attribute_of.each do |key, val|
636
- </span><span class="marked0"><a name="line36"></a>36 next if val.class.lazy?
637
- </span><span class="marked1"><a name="line37"></a>37 raise AttrRequiredError, &quot;param: :#{key} is required to #{hash.inspect}&quot; if !val.class.optional? &amp;&amp; !val.get
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 after_init
641
- </span><span class="inferred1"><a name="line41"></a>41 end
642
- </span><span class="inferred0"><a name="line42"></a>42
643
- </span><span class="marked1"><a name="line43"></a>43 def attribute_of
644
- </span><span class="marked0"><a name="line44"></a>44 hash = {}
645
- </span><span class="marked1"><a name="line45"></a>45 if self.class.attribute_of
646
- </span><span class="marked0"><a name="line46"></a>46 self.class.attribute_of.keys.each do |key|
647
- </span><span class="marked1"><a name="line47"></a>47 hash[key] = __send__ &quot;attribute_of:#{key}&quot;
648
- </span><span class="inferred0"><a name="line48"></a>48 end
649
- </span><span class="inferred1"><a name="line49"></a>49 end
650
- </span><span class="inferred0"><a name="line50"></a>50
651
- </span><span class="marked1"><a name="line51"></a>51 hash
652
- </span><span class="inferred0"><a name="line52"></a>52 end
653
- </span><span class="inferred1"><a name="line53"></a>53
654
- </span><span class="inferred0"><a name="line54"></a>54 # just extend point
655
- </span><span class="marked1"><a name="line55"></a>55 def before_init *args
656
- </span><span class="marked0"><a name="line56"></a>56 raise ArgumentError if args.size &gt; 1
657
- </span><span class="inferred1"><a name="line57"></a>57
658
- </span><span class="marked0"><a name="line58"></a>58 hash = args.first
659
- </span><span class="marked1"><a name="line59"></a>59 hash.nil? ? {} : hash
660
- </span><span class="inferred0"><a name="line60"></a>60 end
661
- </span><span class="inferred1"><a name="line61"></a>61
662
- </span><span class="marked0"><a name="line62"></a>62 def after_init
663
- </span><span class="marked1"><a name="line63"></a>63 end
664
- </span><span class="inferred0"><a name="line64"></a>64
665
- </span><span class="inferred1"><a name="line65"></a>65 end
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
666
676
  </span></pre><hr/>
667
677
  <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
668
678
  version 0.8.1.2.</p>
@@ -1,11 +1,15 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib' )))
2
2
  require 'classx'
3
3
  require 'classx/commandable'
4
+ require 'classx/role/logger'
5
+ require 'pp'
4
6
 
5
7
  $ClassXCommandableMappingOf[Symbol] = String
6
8
 
7
- class YourApp < ClassX
8
- extend Commandable
9
+ class YourApp
10
+ include ClassX
11
+ extend ClassX::Commandable
12
+ include ClassX::Role::Logger
9
13
 
10
14
  has :arg1,
11
15
  :kind_of => Symbol,
@@ -19,7 +23,9 @@ class YourApp < ClassX
19
23
 
20
24
  def run
21
25
  # do something!!
22
- p attribute_of
26
+ logger.info('starting your_app')
27
+ logger.debug(attribute_of.pretty_inspect)
28
+ logger.info('end your app')
23
29
  end
24
30
  end
25
31