classx 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +84 -0
- data/README +4 -2
- data/Rakefile +1 -1
- data/bench/attribute_set.rb +56 -0
- data/bench/initialize.rb +59 -0
- data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-block_rb.html +1 -1
- data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-callbacks_rb.html +1 -1
- data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-change_rb.html +1 -1
- data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-hunk_rb.html +1 -1
- data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs_rb.html +1 -1
- data/doc/output/coverage/-Library-Ruby-Gems-gems-rcov-0_8_1_2_0-lib-rcov_rb.html +1 -1
- data/doc/output/coverage/index.html +27 -27
- data/doc/output/coverage/lib-classx-attribute_rb.html +82 -75
- data/doc/output/coverage/lib-classx-attributes_rb.html +101 -94
- data/doc/output/coverage/lib-classx-validate_rb.html +14 -11
- data/doc/output/coverage/lib-classx_rb.html +75 -65
- data/example/commandable.rb +9 -3
- data/lib/classx.rb +12 -2
- data/lib/classx/attribute.rb +10 -3
- data/lib/classx/attributes.rb +10 -3
- data/lib/classx/commandable.rb +27 -7
- data/lib/classx/declare.rb +12 -0
- data/lib/classx/role/logger.rb +70 -0
- data/lib/classx/validate.rb +6 -3
- data/spec/classx/default_option_spec.rb +16 -12
- data/spec/classx/handles_spec.rb +5 -2
- data/spec/classx/with_coerce.rb +12 -4
- data/spec/classx/with_extend.rb +3 -1
- data/spec/classx/with_include.rb +3 -1
- data/spec/classx/with_multiple_class_spec.rb +4 -2
- data/spec/classx/without_accessor_spec.rb +2 -1
- data/spec/classx/without_anyoption_spec.rb +3 -1
- data/spec/classx/writable_option_spec.rb +8 -4
- data/spec/classx_attributes_spec.rb +6 -1
- data/tasks/basic_config.rake +1 -1
- 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
|
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>
|
574
|
+
<td class='lines_total'><tt>92</tt>
|
575
575
|
</td>
|
576
|
-
<td class='lines_code'><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'>
|
578
|
+
<td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>97.8%</tt>
|
579
579
|
</td>
|
580
|
-
<td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='
|
581
|
-
<td class='uncovered' width='
|
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'>
|
588
|
+
<td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>97.4%</tt>
|
589
589
|
</td>
|
590
|
-
<td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='
|
591
|
-
<td class='uncovered' width='
|
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="
|
602
|
-
</span><span class="
|
603
|
-
</span><span class="
|
604
|
-
</span><span class="
|
605
|
-
</span><span class="
|
606
|
-
</span><span class="
|
607
|
-
</span><span class="
|
608
|
-
</span><span class="
|
609
|
-
</span><span class="
|
610
|
-
</span><span class="
|
611
|
-
</span><span class="
|
612
|
-
</span><span class="
|
613
|
-
</span><span class="
|
614
|
-
</span><span class="
|
615
|
-
</span><span class="
|
616
|
-
</span><span class="
|
617
|
-
</span><span class="
|
618
|
-
</span><span class="
|
619
|
-
</span><span class="
|
620
|
-
</span><span class="
|
621
|
-
</span><span class="
|
622
|
-
</span><span class="
|
623
|
-
</span><span class="
|
624
|
-
</span><span class="
|
625
|
-
</span><span class="
|
626
|
-
</span><span class="
|
627
|
-
</span><span class="
|
628
|
-
</span><span class="
|
629
|
-
</span><span class="
|
630
|
-
</span><span class="
|
631
|
-
</span><span class="
|
632
|
-
</span><span class="
|
633
|
-
</span><span class="
|
634
|
-
</span><span class="
|
635
|
-
</span><span class="
|
636
|
-
</span><span class="
|
637
|
-
</span><span class="
|
638
|
-
</span><span class="
|
639
|
-
</span><span class="
|
640
|
-
</span><span class="
|
641
|
-
</span><span class="
|
642
|
-
</span><span class="
|
643
|
-
</span><span class="
|
644
|
-
</span><span class="
|
645
|
-
</span><span class="
|
646
|
-
</span><span class="
|
647
|
-
</span><span class="
|
648
|
-
</span><span class="
|
649
|
-
</span><span class="
|
650
|
-
</span><span class="
|
651
|
-
</span><span class="
|
652
|
-
</span><span class="
|
653
|
-
</span><span class="
|
654
|
-
</span><span class="
|
655
|
-
</span><span class="
|
656
|
-
</span><span class="
|
657
|
-
</span><span class="
|
658
|
-
</span><span class="
|
659
|
-
</span><span class="
|
660
|
-
</span><span class="
|
661
|
-
</span><span class="
|
662
|
-
</span><span class="
|
663
|
-
</span><span class="
|
664
|
-
</span><span class="
|
665
|
-
</span><span class="
|
666
|
-
</span><span class="
|
667
|
-
</span><span class="
|
668
|
-
</span><span class="
|
669
|
-
</span><span class="
|
670
|
-
</span><span class="
|
671
|
-
</span><span class="
|
672
|
-
</span><span class="
|
673
|
-
</span><span class="
|
674
|
-
</span><span class="
|
675
|
-
</span><span class="
|
676
|
-
</span><span class="
|
677
|
-
</span><span class="
|
678
|
-
</span><span class="
|
679
|
-
</span><span class="
|
680
|
-
</span><span class="
|
681
|
-
</span><span class="
|
682
|
-
</span><span class="
|
683
|
-
</span><span class="
|
684
|
-
</span><span class="
|
685
|
-
</span><span class="
|
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__ "attribute_of:#{key}"
|
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 => 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 "attribute_of:#{name}" 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 "attribute_of:#{name}"
|
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 "attribute_of:#{name}" 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 "attribute_of:#{name}"
|
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 "#{name}=" 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 "#{name}="
|
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
|
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>
|
574
|
+
<td class='lines_total'><tt>38</tt>
|
575
575
|
</td>
|
576
|
-
<td class='lines_code'><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
|
</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
|
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
|
631
|
-
</span><span class="marked1"><a name="line31"></a>31 @@__validate_cached[uniq_key].class_eval
|
632
|
-
</span><span class="
|
633
|
-
</span><span class="
|
634
|
-
</span><span class="
|
635
|
-
</span><span class="inferred1"><a name="line35"></a>35
|
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(&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
|
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>
|
574
|
+
<td class='lines_total'><tt>75</tt>
|
575
575
|
</td>
|
576
|
-
<td class='lines_code'><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
|
</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
|
605
|
-
</span><span class="marked1"><a name="line5"></a> 5
|
606
|
-
</span><span class="marked0"><a name="line6"></a> 6
|
607
|
-
</span><span class="marked1"><a name="line7"></a> 7
|
608
|
-
</span><span class="marked0"><a name="line8"></a> 8
|
609
|
-
</span><span class="marked1"><a name="line9"></a> 9
|
610
|
-
</span><span class="marked0"><a name="line10"></a>10
|
611
|
-
</span><span class="inferred1"><a name="line11"></a>11
|
612
|
-
</span><span class="
|
613
|
-
</span><span class="
|
614
|
-
</span><span class="marked0"><a name="line14"></a>14
|
615
|
-
</span><span class="marked1"><a name="line15"></a>15
|
616
|
-
</span><span class="
|
617
|
-
</span><span class="marked1"><a name="line17"></a>17
|
618
|
-
</span><span class="marked0"><a name="line18"></a>18
|
619
|
-
</span><span class="inferred1"><a name="line19"></a>19
|
620
|
-
</span><span class="
|
621
|
-
</span><span class="
|
622
|
-
</span><span class="marked0"><a name="line22"></a>22
|
623
|
-
</span><span class="
|
624
|
-
</span><span class="marked0"><a name="line24"></a>24
|
625
|
-
</span><span class="
|
626
|
-
</span><span class="
|
627
|
-
</span><span class="
|
628
|
-
</span><span class="marked0"><a name="line28"></a>28
|
629
|
-
</span><span class="
|
630
|
-
</span><span class="
|
631
|
-
</span><span class="
|
632
|
-
</span><span class="
|
633
|
-
</span><span class="
|
634
|
-
</span><span class="
|
635
|
-
</span><span class="
|
636
|
-
</span><span class="marked0"><a name="line36"></a>36
|
637
|
-
</span><span class="
|
638
|
-
</span><span class="
|
639
|
-
</span><span class="
|
640
|
-
</span><span class="marked0"><a name="line40"></a>40
|
641
|
-
</span><span class="
|
642
|
-
</span><span class="inferred0"><a name="line42"></a>42
|
643
|
-
</span><span class="
|
644
|
-
</span><span class="
|
645
|
-
</span><span class="marked1"><a name="line45"></a>45
|
646
|
-
</span><span class="marked0"><a name="line46"></a>46
|
647
|
-
</span><span class="marked1"><a name="line47"></a>47
|
648
|
-
</span><span class="inferred0"><a name="line48"></a>48
|
649
|
-
</span><span class="inferred1"><a name="line49"></a>49
|
650
|
-
</span><span class="
|
651
|
-
</span><span class="
|
652
|
-
</span><span class="inferred0"><a name="line52"></a>52
|
653
|
-
</span><span class="
|
654
|
-
</span><span class="
|
655
|
-
</span><span class="marked1"><a name="line55"></a>55
|
656
|
-
</span><span class="marked0"><a name="line56"></a>56
|
657
|
-
</span><span class="
|
658
|
-
</span><span class="
|
659
|
-
</span><span class="
|
660
|
-
</span><span class="inferred0"><a name="line60"></a>60
|
661
|
-
</span><span class="
|
662
|
-
</span><span class="
|
663
|
-
</span><span class="
|
664
|
-
</span><span class="inferred0"><a name="line64"></a>64
|
665
|
-
</span><span class="
|
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 < Exception; end
|
614
|
+
</span><span class="marked0"><a name="line14"></a>14 class AttrRequiredError < InstanceException; end
|
615
|
+
</span><span class="marked1"><a name="line15"></a>15 class InvalidAttrArgument < InstanceException; end
|
616
|
+
</span><span class="marked0"><a name="line16"></a>16 class LazyOptionShouldHaveDefault < Exception; end
|
617
|
+
</span><span class="marked1"><a name="line17"></a>17 class OptionalAttrShouldBeWritable < Exception; end
|
618
|
+
</span><span class="marked0"><a name="line18"></a>18 class RequiredAttrShouldNotHaveDefault < 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 && hash.kind_of?(Hash)
|
628
|
+
</span><span class="marked0"><a name="line28"></a>28 raise ArgumentError, "#{hash.inspect} was wrong as arguments. please specify kind of Hash instance"
|
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, "param: :#{key} is required to #{hash.inspect}" if !val.class.optional? && !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__ "attribute_of:#{key}"
|
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 > 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>
|
data/example/commandable.rb
CHANGED
@@ -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
|
8
|
-
|
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
|
-
|
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
|
|