classx-pluggable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/ChangeLog +221 -0
  2. data/README +88 -0
  3. data/Rakefile +52 -0
  4. data/doc/output/coverage/-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx-attribute_rb.html +925 -0
  5. data/doc/output/coverage/-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx-attributes_rb.html +772 -0
  6. data/doc/output/coverage/-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx-bracketable_rb.html +671 -0
  7. data/doc/output/coverage/-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx-role-logger_rb.html +716 -0
  8. data/doc/output/coverage/-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx-validate_rb.html +663 -0
  9. data/doc/output/coverage/-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx_rb.html +820 -0
  10. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-block_rb.html +661 -0
  11. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-callbacks_rb.html +932 -0
  12. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-change_rb.html +779 -0
  13. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs-hunk_rb.html +867 -0
  14. data/doc/output/coverage/-Library-Ruby-Gems-gems-diff-lcs-1_1_2-lib-diff-lcs_rb.html +1715 -0
  15. data/doc/output/coverage/-Library-Ruby-Gems-gems-rcov-0_8_1_2_0-lib-rcov_rb.html +1598 -0
  16. data/doc/output/coverage/examples-test_runner-bin-test_runner_rb.html +628 -0
  17. data/doc/output/coverage/examples-test_runner-lib-test_runner-plugin-setup_fixture_rb.html +641 -0
  18. data/doc/output/coverage/examples-test_runner-lib-test_runner-plugin-test_info_rb.html +638 -0
  19. data/doc/output/coverage/examples-test_runner-lib-test_runner-plugin-test_timer_rb.html +666 -0
  20. data/doc/output/coverage/examples-test_runner-lib-test_runner_rb.html +643 -0
  21. data/doc/output/coverage/index.html +711 -0
  22. data/doc/output/coverage/lib-classx-pluggable-plugin_rb.html +676 -0
  23. data/doc/output/coverage/lib-classx-pluggable_rb.html +841 -0
  24. data/examples/test_runner/bin/test_runner.rb +18 -0
  25. data/examples/test_runner/conf/config.yaml +19 -0
  26. data/examples/test_runner/lib/test_runner.rb +33 -0
  27. data/examples/test_runner/lib/test_runner/plugin/setup_fixture.rb +31 -0
  28. data/examples/test_runner/lib/test_runner/plugin/test_info.rb +28 -0
  29. data/examples/test_runner/lib/test_runner/plugin/test_timer.rb +56 -0
  30. data/lib/classx/pluggable.rb +231 -0
  31. data/lib/classx/pluggable/plugin.rb +66 -0
  32. data/spec/classx-pluggable-util/module2path_spec.rb +30 -0
  33. data/spec/classx-pluggable-util/nested_autoload_spec.rb +48 -0
  34. data/spec/classx-pluggable-util/nested_const_get_spec.rb +48 -0
  35. data/spec/classx-pluggable/component_class_get.rb +18 -0
  36. data/spec/classx-pluggable_spec.rb +5 -0
  37. data/spec/example_spec.rb +20 -0
  38. data/spec/spec.opts +1 -0
  39. data/spec/spec_helper.rb +6 -0
  40. data/tasks/basic_config.rake +22 -0
  41. data/tasks/basic_tasks.rake +139 -0
  42. metadata +127 -0
@@ -0,0 +1,221 @@
1
+ commit 24bae0c9a654d82bc92cd7ab0887da0be0cbfb64
2
+ Author: Keiji, Yoshimi <walf443@gmail.com>
3
+ Date: Sat Nov 8 17:31:45 2008 +0900
4
+
5
+ fixed doc.
6
+
7
+ commit a18710a05b958ec6767ca1d45520692d1d23922f
8
+ Author: Keiji, Yoshimi <walf443@gmail.com>
9
+ Date: Sat Nov 8 16:59:39 2008 +0900
10
+
11
+ added example spec.
12
+
13
+ commit e953bcdd9c9897270901042ffaa9c2f034bd5efd
14
+ Author: Keiji, Yoshimi <walf443@gmail.com>
15
+ Date: Sat Nov 8 16:38:29 2008 +0900
16
+
17
+ create test_runner directory.
18
+
19
+ commit 95d40a3eb0e8c61bfbf328335e0be93251170346
20
+ Author: Keiji, Yoshimi <walf443@gmail.com>
21
+ Date: Sat Nov 8 16:37:46 2008 +0900
22
+
23
+ trivial changes.
24
+
25
+ commit f89521694116306068afdc43711963e1c7053769
26
+ Author: Keiji, Yoshimi <walf443@gmail.com>
27
+ Date: Sat Nov 8 16:33:46 2008 +0900
28
+
29
+ no need to use instance variable.
30
+
31
+ commit 4b928f5c1a6a9ddb2d183ffe46aa6d12e264a639
32
+ Author: Keiji, Yoshimi <walf443@gmail.com>
33
+ Date: Fri Nov 7 08:57:31 2008 +0900
34
+
35
+ added doc.
36
+
37
+ commit 409de53aca3428583ca4b6572eb74ec58e6d8c9b
38
+ Author: Keiji, Yoshimi <walf443@gmail.com>
39
+ Date: Fri Nov 7 08:27:48 2008 +0900
40
+
41
+ fixed plagger's spell
42
+
43
+ commit 481ab26c8164d2dd9ef76daa1862b30aa21e298b
44
+ Author: Keiji, Yoshimi <walf443@gmail.com>
45
+ Date: Fri Nov 7 08:27:17 2008 +0900
46
+
47
+ fixed README.
48
+
49
+ commit cd5ea112391bdc2962466c34b86d72e7a74511b6
50
+ Author: Keiji, Yoshimi <walf443@gmail.com>
51
+ Date: Fri Nov 7 08:20:28 2008 +0900
52
+
53
+ fixed example loading conf/config.yaml as default.
54
+
55
+ commit 6615d1f4bad4f8ac951211e7a06e66771633cd5c
56
+ Author: Keiji, Yoshimi <walf443@gmail.com>
57
+ Date: Fri Nov 7 08:04:07 2008 +0900
58
+
59
+ rename method around_event to call_event_around. you can easy to find for event point with greping call_event.
60
+
61
+ commit 2145538c94cc7047c0f74468fe3b5f7ea345d5f2
62
+ Author: Keiji, Yoshimi <walf443@gmail.com>
63
+ Date: Fri Nov 7 07:54:24 2008 +0900
64
+
65
+ separete example files.
66
+
67
+ commit 9a03c71d4d9f916634a15c36059bf30fa431679f
68
+ Author: Keiji, Yoshimi <walf443@gmail.com>
69
+ Date: Fri Nov 7 07:31:43 2008 +0900
70
+
71
+ implement feature for auto loading plugin.
72
+
73
+ commit 107e01ce7a0cabe7f946b3749de6cd6c12a13411
74
+ Author: Keiji, Yoshimi <walf443@gmail.com>
75
+ Date: Tue Nov 4 08:29:45 2008 +0900
76
+
77
+ refactoring.
78
+
79
+ commit 7e11c5539cff81ca012543aa08e5b2b669d04d7d
80
+ Author: Keiji, Yoshimi <walf443@gmail.com>
81
+ Date: Tue Nov 4 08:04:59 2008 +0900
82
+
83
+ dupping for saving original config.
84
+
85
+ commit c97fc9ffa9bafe9aab1af2466bf9bfeec2187479
86
+ Author: Keiji, Yoshimi <walf443@gmail.com>
87
+ Date: Tue Nov 4 01:55:28 2008 +0900
88
+
89
+ you can specify target component as base_name + component name + "+plugin_name". ( for example. "+Hoge" is YourApp::Plugin::Hoge )
90
+
91
+ commit aec0021f58c11110c73b72686c5d8bb4edebf31b
92
+ Author: Keiji, Yoshimi <walf443@gmail.com>
93
+ Date: Tue Nov 4 01:38:37 2008 +0900
94
+
95
+ tweaked interface.
96
+
97
+ commit cec519d34be81c883f2150e4778b4b547ff42dea
98
+ Author: Keiji, Yoshimi <walf443@gmail.com>
99
+ Date: Tue Nov 4 00:48:16 2008 +0900
100
+
101
+ added testing plugin example.
102
+
103
+ commit 3e9f024bf23716200a00a4bdec8b322808f07e78
104
+ Author: Keiji, Yoshimi <walf443@gmail.com>
105
+ Date: Mon Nov 3 23:19:09 2008 +0900
106
+
107
+ added plugin to example.
108
+
109
+ commit 4406106bb55056fde3a7fe1f0f6f49521368d608
110
+ Author: Keiji, Yoshimi <walf443@gmail.com>
111
+ Date: Fri Oct 31 09:40:22 2008 +0900
112
+
113
+ use method!!
114
+
115
+ commit 5dd5b3206120e18ac01c17df56a7bda2c3c584ce
116
+ Author: Keiji, Yoshimi <walf443@gmail.com>
117
+ Date: Fri Oct 31 09:35:47 2008 +0900
118
+
119
+ I think it better not to use context directly.
120
+
121
+ commit 187a33e4a3daf4ef07fc286d1385016c1d555c81
122
+ Author: Keiji, Yoshimi <walf443@gmail.com>
123
+ Date: Thu Oct 30 08:49:04 2008 +0900
124
+
125
+ fixed doc.
126
+
127
+ commit a36478b464cd59fefc18c4380ec97a3571f8990e
128
+ Author: Keiji, Yoshimi <walf443@gmail.com>
129
+ Date: Wed Oct 29 01:24:59 2008 +0900
130
+
131
+ You can manage events in your application class. It may be prevend extending event not intentionally.
132
+
133
+ commit a7a25bb08969ce9ab62444f6e77855850a0b0925
134
+ Author: Keiji, Yoshimi <walf443@gmail.com>
135
+ Date: Wed Oct 29 00:57:45 2008 +0900
136
+
137
+ fixed doc.
138
+
139
+ commit 9ff373f239903d756569159b8f2ba0d119793bee
140
+ Author: Keiji, Yoshimi <walf443@gmail.com>
141
+ Date: Wed Oct 29 00:28:53 2008 +0900
142
+
143
+ You can define event with yield. It's useful to hook before and after for some event.
144
+
145
+ commit f6c77aabe86111978a84dd666afc43737fe931b2
146
+ Author: Keiji, Yoshimi <walf443@gmail.com>
147
+ Date: Tue Oct 28 07:55:42 2008 +0900
148
+
149
+ added original Exception class.
150
+
151
+ commit 781f68b0244461039c51fa99dd4c09eed7ab4c22
152
+ Author: Keiji, Yoshimi <walf443@gmail.com>
153
+ Date: Tue Oct 28 07:45:27 2008 +0900
154
+
155
+ added around_event
156
+
157
+ commit d26926274ab44e2b2c05272ca4c1ed4da6874dd2
158
+ Author: Keiji, Yoshimi <walf443@gmail.com>
159
+ Date: Tue Oct 28 07:34:51 2008 +0900
160
+
161
+ added doc for ClassX::Plugin::AutoRegister
162
+
163
+ commit ce8f46a6006ed62c76ccdfd3964684a847442177
164
+ Author: Keiji, Yoshimi <walf443@gmail.com>
165
+ Date: Tue Oct 28 00:44:46 2008 +0900
166
+
167
+ added CassX::Pluggable::Plugin::AutoRegister
168
+
169
+ commit b8d748953c9c6ce53453184e36d27ebf04aaf18e
170
+ Author: Keiji, Yoshimi <walf443@gmail.com>
171
+ Date: Tue Oct 28 00:24:41 2008 +0900
172
+
173
+ added define_event.
174
+
175
+ commit 81227fc1cc165f6dbb344850f95e7d7547df3eeb
176
+ Author: Keiji, Yoshimi <walf443@gmail.com>
177
+ Date: Tue Oct 28 00:13:15 2008 +0900
178
+
179
+ fixed doc.
180
+
181
+ commit 55c572cd701fc0bc6ac7efde644027c3c67c2e2e
182
+ Author: Keiji, Yoshimi <walf443@gmail.com>
183
+ Date: Tue Oct 28 00:10:24 2008 +0900
184
+
185
+ changed Plugin API. Proc is not easy testing and debugging.
186
+
187
+ commit 0d7000a3971badf43e84b540350d59fae758e716
188
+ Author: Keiji, Yoshimi <walf443@gmail.com>
189
+ Date: Mon Oct 27 23:23:12 2008 +0900
190
+
191
+ It's better to write dispatch method for testability.
192
+
193
+ commit caf6e5c6567ad542cb2d293a7b7ef10d4b5dc12e
194
+ Author: Keiji, Yoshimi <walf443@gmail.com>
195
+ Date: Sun Oct 26 03:02:26 2008 +0900
196
+
197
+ In this example, a plugin should inherite TestRunner::Plugin class.
198
+
199
+ commit f95e4d36eb61cc6254498d7dd2a99e7e5abffb20
200
+ Author: Keiji, Yoshimi <walf443@gmail.com>
201
+ Date: Sat Oct 25 16:43:41 2008 +0900
202
+
203
+ :module can take String.
204
+
205
+ commit 6dc389dcb998ad7e2a1b6541d8ef588718423314
206
+ Author: Keiji, Yoshimi <walf443@gmail.com>
207
+ Date: Sat Oct 25 16:38:44 2008 +0900
208
+
209
+ added docs.
210
+
211
+ commit f293440cc27414be86f2ec9aa0de420aabe5a633
212
+ Author: Keiji, Yoshimi <walf443@gmail.com>
213
+ Date: Sat Oct 25 13:45:54 2008 +0900
214
+
215
+ remove garvage.
216
+
217
+ commit 1e8c86c0f53671bb18eda1044c35bd4296a2cbdc
218
+ Author: Keiji, Yoshimi <walf443@gmail.com>
219
+ Date: Sat Oct 25 13:44:48 2008 +0900
220
+
221
+ initial import.
data/README ADDED
@@ -0,0 +1,88 @@
1
+
2
+ = classx-pluggable
3
+
4
+ plagger's like plugin system for classx based applicaton
5
+
6
+ == Synopsis
7
+
8
+ in your context class.
9
+
10
+ require 'classx'
11
+ require 'classx/pluggable'
12
+ class YourApp
13
+ include ClassX
14
+ include ClassX::Pluggable
15
+
16
+ def run
17
+ call_event("SETUP", {})
18
+ # you app
19
+ call_event("TEARDOWN", {})
20
+ end
21
+ end
22
+
23
+ in your plugin class
24
+
25
+ require 'classx'
26
+ require 'classx/pluggable'
27
+ class YourApp
28
+ class Plugin
29
+ include ClassX
30
+ include ClassX::Pluggable::Plugin
31
+
32
+ class SomePlugin < Plugin
33
+ def register
34
+ add_event("SETUP", :on_setup)
35
+ end
36
+
37
+ def on_setup param
38
+ # param is Hash
39
+ # hooked setup
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ or it's easy to defining with ClassX::Pluggable::Plugin::AutoRegister
46
+
47
+ class YourApp
48
+ class Plugin
49
+ include ClassX
50
+ include ClassX::Pluggable::Plugin
51
+ include ClassX::Pluggable::Plugin::AutoRegister
52
+
53
+ class SomePlugin < Plugin
54
+ def on_setup param
55
+ # do some thing.
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ and, on your start up script.
62
+
63
+ app = YourApp.new
64
+ app.load_plugins([
65
+ { :module => YourApp::Plugin::SomePlugin, :config => {} },
66
+ ])
67
+
68
+ app.run
69
+
70
+ == Description
71
+
72
+ == Installation
73
+
74
+ === Archive Installation
75
+
76
+ rake install
77
+
78
+ === Gem Installation
79
+
80
+ == Features/Problems
81
+
82
+ CAVEAT: this project is early development. API may be vary in future.
83
+
84
+ == Copyright
85
+
86
+ Author:: Keiji, Yoshimi <walf443 at gmail.com>
87
+ Copyright:: Copyright (c) 2008 Keiji, Yoshimi
88
+ License:: you can redistribute it and/or modify it under the same terms as Ruby itself.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'rake/contrib/sshpublisher'
10
+ require 'fileutils'
11
+ include FileUtils
12
+
13
+ load File.join(File.dirname(__FILE__), 'tasks', 'basic_config.rake')
14
+
15
+ NAME = "classx-pluggable"
16
+ DESCRIPTION = <<-"END_DESCRIPTION"
17
+ make your class to pluggable.
18
+ END_DESCRIPTION
19
+ BIN_FILES = %w( )
20
+ VERS = "0.0.1"
21
+
22
+ EXTRA_RDOC_FILES = []
23
+ HECKLE_ROOT_MODULES = ["ClassX::Pluggable"]
24
+
25
+ SPEC = Gem::Specification.new do |s|
26
+ s.name = NAME
27
+ s.version = VERS
28
+ s.platform = Gem::Platform::RUBY
29
+ s.has_rdoc = true
30
+ s.extra_rdoc_files = DEFAULT_EXTRA_RDOC_FILES + EXTRA_RDOC_FILES
31
+ s.rdoc_options += RDOC_OPTS + ['--title', "#{NAME} documentation"]
32
+ s.summary = DESCRIPTION
33
+ s.description = DESCRIPTION
34
+ s.author = AUTHOR
35
+ s.email = EMAIL
36
+ s.homepage = HOMEPATH
37
+ s.executables = BIN_FILES
38
+ s.rubyforge_project = RUBYFORGE_PROJECT
39
+ s.bindir = "bin"
40
+ s.require_path = "lib"
41
+ s.autorequire = ""
42
+ s.test_files = Dir["spec/*_spec.rb"]
43
+
44
+ #s.add_dependency('activesupport', '>=1.3.1')
45
+ #s.required_ruby_version = '>= 1.8.2'
46
+ s.add_dependency('classx', '>= 0.0.1')
47
+
48
+ s.files = PKG_FILES + EXTRA_RDOC_FILES
49
+ s.extensions = EXTENSIONS
50
+ end
51
+
52
+ import File.join(File.dirname(__FILE__), 'tasks', 'basic_tasks.rake')
@@ -0,0 +1,925 @@
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/classx-0.0.5/lib/classx/attribute.rb - C0 code coverage information</title>
3
+ <style type='text/css'>body { background-color: rgb(240, 240, 245); }</style>
4
+ <style type='text/css'>span.cross-ref-title {
5
+ font-size: 140%;
6
+ }
7
+ span.cross-ref a {
8
+ text-decoration: none;
9
+ }
10
+ span.cross-ref {
11
+ background-color:#f3f7fa;
12
+ border: 1px dashed #333;
13
+ margin: 1em;
14
+ padding: 0.5em;
15
+ overflow: hidden;
16
+ }
17
+ a.crossref-toggle {
18
+ text-decoration: none;
19
+ }
20
+ span.marked0 {
21
+ background-color: rgb(185, 210, 200);
22
+ display: block;
23
+ }
24
+ span.marked1 {
25
+ background-color: rgb(190, 215, 205);
26
+ display: block;
27
+ }
28
+ span.inferred0 {
29
+ background-color: rgb(175, 200, 200);
30
+ display: block;
31
+ }
32
+ span.inferred1 {
33
+ background-color: rgb(180, 205, 205);
34
+ display: block;
35
+ }
36
+ span.uncovered0 {
37
+ background-color: rgb(225, 110, 110);
38
+ display: block;
39
+ }
40
+ span.uncovered1 {
41
+ background-color: rgb(235, 120, 120);
42
+ display: block;
43
+ }
44
+ span.overview {
45
+ border-bottom: 8px solid black;
46
+ }
47
+ div.overview {
48
+ border-bottom: 8px solid black;
49
+ }
50
+ body {
51
+ font-family: verdana, arial, helvetica;
52
+ }
53
+ div.footer {
54
+ font-size: 68%;
55
+ margin-top: 1.5em;
56
+ }
57
+ h1, h2, h3, h4, h5, h6 {
58
+ margin-bottom: 0.5em;
59
+ }
60
+ h5 {
61
+ margin-top: 0.5em;
62
+ }
63
+ .hidden {
64
+ display: none;
65
+ }
66
+ div.separator {
67
+ height: 10px;
68
+ }
69
+ /* Commented out for better readability, esp. on IE */
70
+ /*
71
+ table tr td, table tr th {
72
+ font-size: 68%;
73
+ }
74
+ td.value table tr td {
75
+ font-size: 11px;
76
+ }
77
+ */
78
+ table.percent_graph {
79
+ height: 12px;
80
+ border: #808080 1px solid;
81
+ empty-cells: show;
82
+ }
83
+ table.percent_graph td.covered {
84
+ height: 10px;
85
+ background: #00f000;
86
+ }
87
+ table.percent_graph td.uncovered {
88
+ height: 10px;
89
+ background: #e00000;
90
+ }
91
+ table.percent_graph td.NA {
92
+ height: 10px;
93
+ background: #eaeaea;
94
+ }
95
+ table.report {
96
+ border-collapse: collapse;
97
+ width: 100%;
98
+ }
99
+ table.report td.heading {
100
+ background: #dcecff;
101
+ border: #d0d0d0 1px solid;
102
+ font-weight: bold;
103
+ text-align: center;
104
+ }
105
+ table.report td.heading:hover {
106
+ background: #c0ffc0;
107
+ }
108
+ table.report td.text {
109
+ border: #d0d0d0 1px solid;
110
+ }
111
+ table.report td.value,
112
+ table.report td.lines_total,
113
+ table.report td.lines_code {
114
+ text-align: right;
115
+ border: #d0d0d0 1px solid;
116
+ }
117
+ table.report tr.light {
118
+ background-color: rgb(240, 240, 245);
119
+ }
120
+ table.report tr.dark {
121
+ background-color: rgb(230, 230, 235);
122
+ }
123
+ </style>
124
+ <script type='text/javascript'>
125
+ // <![CDATA[
126
+ function toggleCode( id ) {
127
+ if ( document.getElementById )
128
+ elem = document.getElementById( id );
129
+ else if ( document.all )
130
+ elem = eval( "document.all." + id );
131
+ else
132
+ return false;
133
+
134
+ elemStyle = elem.style;
135
+
136
+ if ( elemStyle.display != "block" ) {
137
+ elemStyle.display = "block"
138
+ } else {
139
+ elemStyle.display = "none"
140
+ }
141
+
142
+ return true;
143
+ }
144
+
145
+ // Make cross-references hidden by default
146
+ document.writeln( "<style type=\"text/css\">span.cross-ref { display: none }</style>" )
147
+ // ]]>
148
+ </script>
149
+ <style type='text/css'>span.run0 {
150
+ background-color: rgb(178, 204, 255);
151
+ display: block;
152
+ }
153
+ span.run1 {
154
+ background-color: rgb(178, 206, 255);
155
+ display: block;
156
+ }
157
+ span.run2 {
158
+ background-color: rgb(178, 209, 255);
159
+ display: block;
160
+ }
161
+ span.run3 {
162
+ background-color: rgb(178, 211, 255);
163
+ display: block;
164
+ }
165
+ span.run4 {
166
+ background-color: rgb(178, 214, 255);
167
+ display: block;
168
+ }
169
+ span.run5 {
170
+ background-color: rgb(178, 218, 255);
171
+ display: block;
172
+ }
173
+ span.run6 {
174
+ background-color: rgb(178, 220, 255);
175
+ display: block;
176
+ }
177
+ span.run7 {
178
+ background-color: rgb(178, 223, 255);
179
+ display: block;
180
+ }
181
+ span.run8 {
182
+ background-color: rgb(178, 225, 255);
183
+ display: block;
184
+ }
185
+ span.run9 {
186
+ background-color: rgb(178, 228, 255);
187
+ display: block;
188
+ }
189
+ span.run10 {
190
+ background-color: rgb(178, 232, 255);
191
+ display: block;
192
+ }
193
+ span.run11 {
194
+ background-color: rgb(178, 234, 255);
195
+ display: block;
196
+ }
197
+ span.run12 {
198
+ background-color: rgb(178, 237, 255);
199
+ display: block;
200
+ }
201
+ span.run13 {
202
+ background-color: rgb(178, 239, 255);
203
+ display: block;
204
+ }
205
+ span.run14 {
206
+ background-color: rgb(178, 242, 255);
207
+ display: block;
208
+ }
209
+ span.run15 {
210
+ background-color: rgb(178, 246, 255);
211
+ display: block;
212
+ }
213
+ span.run16 {
214
+ background-color: rgb(178, 248, 255);
215
+ display: block;
216
+ }
217
+ span.run17 {
218
+ background-color: rgb(178, 251, 255);
219
+ display: block;
220
+ }
221
+ span.run18 {
222
+ background-color: rgb(178, 253, 255);
223
+ display: block;
224
+ }
225
+ span.run19 {
226
+ background-color: rgb(178, 255, 253);
227
+ display: block;
228
+ }
229
+ span.run20 {
230
+ background-color: rgb(178, 255, 249);
231
+ display: block;
232
+ }
233
+ span.run21 {
234
+ background-color: rgb(178, 255, 247);
235
+ display: block;
236
+ }
237
+ span.run22 {
238
+ background-color: rgb(178, 255, 244);
239
+ display: block;
240
+ }
241
+ span.run23 {
242
+ background-color: rgb(178, 255, 242);
243
+ display: block;
244
+ }
245
+ span.run24 {
246
+ background-color: rgb(178, 255, 239);
247
+ display: block;
248
+ }
249
+ span.run25 {
250
+ background-color: rgb(178, 255, 235);
251
+ display: block;
252
+ }
253
+ span.run26 {
254
+ background-color: rgb(178, 255, 233);
255
+ display: block;
256
+ }
257
+ span.run27 {
258
+ background-color: rgb(178, 255, 230);
259
+ display: block;
260
+ }
261
+ span.run28 {
262
+ background-color: rgb(178, 255, 228);
263
+ display: block;
264
+ }
265
+ span.run29 {
266
+ background-color: rgb(178, 255, 225);
267
+ display: block;
268
+ }
269
+ span.run30 {
270
+ background-color: rgb(178, 255, 221);
271
+ display: block;
272
+ }
273
+ span.run31 {
274
+ background-color: rgb(178, 255, 219);
275
+ display: block;
276
+ }
277
+ span.run32 {
278
+ background-color: rgb(178, 255, 216);
279
+ display: block;
280
+ }
281
+ span.run33 {
282
+ background-color: rgb(178, 255, 214);
283
+ display: block;
284
+ }
285
+ span.run34 {
286
+ background-color: rgb(178, 255, 211);
287
+ display: block;
288
+ }
289
+ span.run35 {
290
+ background-color: rgb(178, 255, 207);
291
+ display: block;
292
+ }
293
+ span.run36 {
294
+ background-color: rgb(178, 255, 205);
295
+ display: block;
296
+ }
297
+ span.run37 {
298
+ background-color: rgb(178, 255, 202);
299
+ display: block;
300
+ }
301
+ span.run38 {
302
+ background-color: rgb(178, 255, 200);
303
+ display: block;
304
+ }
305
+ span.run39 {
306
+ background-color: rgb(178, 255, 197);
307
+ display: block;
308
+ }
309
+ span.run40 {
310
+ background-color: rgb(178, 255, 193);
311
+ display: block;
312
+ }
313
+ span.run41 {
314
+ background-color: rgb(178, 255, 191);
315
+ display: block;
316
+ }
317
+ span.run42 {
318
+ background-color: rgb(178, 255, 188);
319
+ display: block;
320
+ }
321
+ span.run43 {
322
+ background-color: rgb(178, 255, 186);
323
+ display: block;
324
+ }
325
+ span.run44 {
326
+ background-color: rgb(178, 255, 183);
327
+ display: block;
328
+ }
329
+ span.run45 {
330
+ background-color: rgb(178, 255, 179);
331
+ display: block;
332
+ }
333
+ span.run46 {
334
+ background-color: rgb(179, 255, 178);
335
+ display: block;
336
+ }
337
+ span.run47 {
338
+ background-color: rgb(182, 255, 178);
339
+ display: block;
340
+ }
341
+ span.run48 {
342
+ background-color: rgb(184, 255, 178);
343
+ display: block;
344
+ }
345
+ span.run49 {
346
+ background-color: rgb(187, 255, 178);
347
+ display: block;
348
+ }
349
+ span.run50 {
350
+ background-color: rgb(191, 255, 178);
351
+ display: block;
352
+ }
353
+ span.run51 {
354
+ background-color: rgb(193, 255, 178);
355
+ display: block;
356
+ }
357
+ span.run52 {
358
+ background-color: rgb(196, 255, 178);
359
+ display: block;
360
+ }
361
+ span.run53 {
362
+ background-color: rgb(198, 255, 178);
363
+ display: block;
364
+ }
365
+ span.run54 {
366
+ background-color: rgb(201, 255, 178);
367
+ display: block;
368
+ }
369
+ span.run55 {
370
+ background-color: rgb(205, 255, 178);
371
+ display: block;
372
+ }
373
+ span.run56 {
374
+ background-color: rgb(207, 255, 178);
375
+ display: block;
376
+ }
377
+ span.run57 {
378
+ background-color: rgb(210, 255, 178);
379
+ display: block;
380
+ }
381
+ span.run58 {
382
+ background-color: rgb(212, 255, 178);
383
+ display: block;
384
+ }
385
+ span.run59 {
386
+ background-color: rgb(215, 255, 178);
387
+ display: block;
388
+ }
389
+ span.run60 {
390
+ background-color: rgb(219, 255, 178);
391
+ display: block;
392
+ }
393
+ span.run61 {
394
+ background-color: rgb(221, 255, 178);
395
+ display: block;
396
+ }
397
+ span.run62 {
398
+ background-color: rgb(224, 255, 178);
399
+ display: block;
400
+ }
401
+ span.run63 {
402
+ background-color: rgb(226, 255, 178);
403
+ display: block;
404
+ }
405
+ span.run64 {
406
+ background-color: rgb(229, 255, 178);
407
+ display: block;
408
+ }
409
+ span.run65 {
410
+ background-color: rgb(233, 255, 178);
411
+ display: block;
412
+ }
413
+ span.run66 {
414
+ background-color: rgb(235, 255, 178);
415
+ display: block;
416
+ }
417
+ span.run67 {
418
+ background-color: rgb(238, 255, 178);
419
+ display: block;
420
+ }
421
+ span.run68 {
422
+ background-color: rgb(240, 255, 178);
423
+ display: block;
424
+ }
425
+ span.run69 {
426
+ background-color: rgb(243, 255, 178);
427
+ display: block;
428
+ }
429
+ span.run70 {
430
+ background-color: rgb(247, 255, 178);
431
+ display: block;
432
+ }
433
+ span.run71 {
434
+ background-color: rgb(249, 255, 178);
435
+ display: block;
436
+ }
437
+ span.run72 {
438
+ background-color: rgb(252, 255, 178);
439
+ display: block;
440
+ }
441
+ span.run73 {
442
+ background-color: rgb(255, 255, 178);
443
+ display: block;
444
+ }
445
+ span.run74 {
446
+ background-color: rgb(255, 252, 178);
447
+ display: block;
448
+ }
449
+ span.run75 {
450
+ background-color: rgb(255, 248, 178);
451
+ display: block;
452
+ }
453
+ span.run76 {
454
+ background-color: rgb(255, 246, 178);
455
+ display: block;
456
+ }
457
+ span.run77 {
458
+ background-color: rgb(255, 243, 178);
459
+ display: block;
460
+ }
461
+ span.run78 {
462
+ background-color: rgb(255, 240, 178);
463
+ display: block;
464
+ }
465
+ span.run79 {
466
+ background-color: rgb(255, 238, 178);
467
+ display: block;
468
+ }
469
+ span.run80 {
470
+ background-color: rgb(255, 234, 178);
471
+ display: block;
472
+ }
473
+ span.run81 {
474
+ background-color: rgb(255, 232, 178);
475
+ display: block;
476
+ }
477
+ span.run82 {
478
+ background-color: rgb(255, 229, 178);
479
+ display: block;
480
+ }
481
+ span.run83 {
482
+ background-color: rgb(255, 226, 178);
483
+ display: block;
484
+ }
485
+ span.run84 {
486
+ background-color: rgb(255, 224, 178);
487
+ display: block;
488
+ }
489
+ span.run85 {
490
+ background-color: rgb(255, 220, 178);
491
+ display: block;
492
+ }
493
+ span.run86 {
494
+ background-color: rgb(255, 218, 178);
495
+ display: block;
496
+ }
497
+ span.run87 {
498
+ background-color: rgb(255, 215, 178);
499
+ display: block;
500
+ }
501
+ span.run88 {
502
+ background-color: rgb(255, 212, 178);
503
+ display: block;
504
+ }
505
+ span.run89 {
506
+ background-color: rgb(255, 210, 178);
507
+ display: block;
508
+ }
509
+ span.run90 {
510
+ background-color: rgb(255, 206, 178);
511
+ display: block;
512
+ }
513
+ span.run91 {
514
+ background-color: rgb(255, 204, 178);
515
+ display: block;
516
+ }
517
+ span.run92 {
518
+ background-color: rgb(255, 201, 178);
519
+ display: block;
520
+ }
521
+ span.run93 {
522
+ background-color: rgb(255, 198, 178);
523
+ display: block;
524
+ }
525
+ span.run94 {
526
+ background-color: rgb(255, 196, 178);
527
+ display: block;
528
+ }
529
+ span.run95 {
530
+ background-color: rgb(255, 192, 178);
531
+ display: block;
532
+ }
533
+ span.run96 {
534
+ background-color: rgb(255, 189, 178);
535
+ display: block;
536
+ }
537
+ span.run97 {
538
+ background-color: rgb(255, 187, 178);
539
+ display: block;
540
+ }
541
+ span.run98 {
542
+ background-color: rgb(255, 184, 178);
543
+ display: block;
544
+ }
545
+ span.run99 {
546
+ background-color: rgb(255, 182, 178);
547
+ display: block;
548
+ }
549
+ span.run100 {
550
+ background-color: rgb(255, 178, 178);
551
+ display: block;
552
+ }
553
+ </style>
554
+ </head>
555
+ <body><h3>C0 code coverage information</h3>
556
+ <p>Generated on Sat Nov 08 17:43:41 +0900 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
557
+ </p>
558
+ <hr/>
559
+ <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
560
+ </span><span class='marked1'>and this: this line is also marked as covered.
561
+ </span><span class='inferred0'>Lines considered as run by rcov, but not reported by Ruby, look like this,
562
+ </span><span class='inferred1'>and this: these lines were inferred by rcov (using simple heuristics).
563
+ </span><span class='uncovered0'>Finally, here&apos;s a line marked as not executed.
564
+ </span></pre>
565
+ <table class='report'><thead><tr><td class='heading'>Name</td>
566
+ <td class='heading'>Total lines</td>
567
+ <td class='heading'>Lines of code</td>
568
+ <td class='heading'>Total coverage</td>
569
+ <td class='heading'>Code coverage</td>
570
+ </tr>
571
+ </thead>
572
+ <tbody><tr class='light'><td><a href='-Library-Ruby-Gems-gems-classx-0_0_5-lib-classx-attribute_rb.html'>/Library/Ruby/Gems/gems/classx-0.0.5/lib/classx/attribute.rb</a>
573
+ </td>
574
+ <td class='lines_total'><tt>315</tt>
575
+ </td>
576
+ <td class='lines_code'><tt>244</tt>
577
+ </td>
578
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_total'>64.8%</tt>
579
+ &nbsp;</td>
580
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='65'/>
581
+ <td class='uncovered' width='35'/>
582
+ </tr>
583
+ </table>
584
+ </td>
585
+ </tr>
586
+ </table>
587
+ </td>
588
+ <td><table cellspacing='0' cellpadding='0' align='right'><tr><td><tt class='coverage_code'>57.4%</tt>
589
+ &nbsp;</td>
590
+ <td><table cellspacing='0' class='percent_graph' cellpadding='0' width='100'><tr><td class='covered' width='57'/>
591
+ <td class='uncovered' width='43'/>
592
+ </tr>
593
+ </table>
594
+ </td>
595
+ </tr>
596
+ </table>
597
+ </td>
598
+ </tr>
599
+ </tbody>
600
+ </table>
601
+ <pre><span class="marked1"><a name="line1"></a> 1 module ClassX
602
+ </span><span class="marked0"><a name="line2"></a> 2 module AttributeMethods #:nodoc:
603
+ </span><span class="marked1"><a name="line3"></a> 3 module ClassMethods #:nodoc:
604
+ </span><span class="marked0"><a name="line4"></a> 4 def value_class
605
+ </span><span class="marked1"><a name="line5"></a> 5 config[:isa] || config[:kind_of]
606
+ </span><span class="marked0"><a name="line6"></a> 6 end
607
+ </span><span class="inferred1"><a name="line7"></a> 7
608
+ </span><span class="inferred0"><a name="line8"></a> 8 # description for attribute
609
+ </span><span class="marked1"><a name="line9"></a> 9 def desc
610
+ </span><span class="uncovered0"><a name="line10"></a> 10 config[:desc]
611
+ </span><span class="uncovered1"><a name="line11"></a> 11 end
612
+ </span><span class="inferred0"><a name="line12"></a> 12
613
+ </span><span class="inferred1"><a name="line13"></a> 13 # when this option specify true, not raise error in #initialize without value.
614
+ </span><span class="marked0"><a name="line14"></a> 14 def optional?
615
+ </span><span class="marked1"><a name="line15"></a> 15 return config[:optional]
616
+ </span><span class="marked0"><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 # when it lazy option specified, it will not be initialized when #initialize.
619
+ </span><span class="marked1"><a name="line19"></a> 19 def lazy?
620
+ </span><span class="marked0"><a name="line20"></a> 20 return config[:lazy]
621
+ </span><span class="marked1"><a name="line21"></a> 21 end
622
+ </span><span class="inferred0"><a name="line22"></a> 22
623
+ </span><span class="marked1"><a name="line23"></a> 23 def inspect
624
+ </span><span class="uncovered0"><a name="line24"></a> 24 &quot;ClassX::Attribute[#{self.config.inspect}]&quot;
625
+ </span><span class="uncovered1"><a name="line25"></a> 25 end
626
+ </span><span class="inferred0"><a name="line26"></a> 26
627
+ </span><span class="marked1"><a name="line27"></a> 27 module CoerceWithHash #:nodoc:
628
+ </span><span class="marked0"><a name="line28"></a> 28 def coerce val
629
+ </span><span class="uncovered1"><a name="line29"></a> 29 result = val
630
+ </span><span class="uncovered0"><a name="line30"></a> 30 config[:coerce].each do |cond, rule|
631
+ </span><span class="uncovered1"><a name="line31"></a> 31 case cond
632
+ </span><span class="uncovered0"><a name="line32"></a> 32 when Proc
633
+ </span><span class="uncovered1"><a name="line33"></a> 33 if cond.call(val)
634
+ </span><span class="uncovered0"><a name="line34"></a> 34 result = rule.call(val)
635
+ </span><span class="uncovered1"><a name="line35"></a> 35 break
636
+ </span><span class="uncovered0"><a name="line36"></a> 36 end
637
+ </span><span class="uncovered1"><a name="line37"></a> 37 when Symbol
638
+ </span><span class="uncovered0"><a name="line38"></a> 38 if val.respond_to? cond
639
+ </span><span class="uncovered1"><a name="line39"></a> 39 result = rule.call(val)
640
+ </span><span class="uncovered0"><a name="line40"></a> 40 break
641
+ </span><span class="uncovered1"><a name="line41"></a> 41 end
642
+ </span><span class="uncovered0"><a name="line42"></a> 42 when Module
643
+ </span><span class="uncovered1"><a name="line43"></a> 43 if val.kind_of? cond
644
+ </span><span class="uncovered0"><a name="line44"></a> 44 result = rule.call(val)
645
+ </span><span class="uncovered1"><a name="line45"></a> 45 break
646
+ </span><span class="uncovered0"><a name="line46"></a> 46 end
647
+ </span><span class="uncovered1"><a name="line47"></a> 47 end
648
+ </span><span class="uncovered0"><a name="line48"></a> 48 end
649
+ </span><span class="uncovered1"><a name="line49"></a> 49
650
+ </span><span class="uncovered0"><a name="line50"></a> 50 return result
651
+ </span><span class="uncovered1"><a name="line51"></a> 51 end
652
+ </span><span class="uncovered0"><a name="line52"></a> 52 end
653
+ </span><span class="marked1"><a name="line53"></a> 53 module CoerceWithArray #:nodoc:
654
+ </span><span class="marked0"><a name="line54"></a> 54 def coerce val
655
+ </span><span class="uncovered1"><a name="line55"></a> 55 result = val
656
+ </span><span class="uncovered0"><a name="line56"></a> 56 config[:coerce].each do |item|
657
+ </span><span class="uncovered1"><a name="line57"></a> 57 raise unless item.kind_of? Hash
658
+ </span><span class="uncovered0"><a name="line58"></a> 58
659
+ </span><span class="uncovered1"><a name="line59"></a> 59 case item
660
+ </span><span class="uncovered0"><a name="line60"></a> 60 when Hash
661
+ </span><span class="uncovered1"><a name="line61"></a> 61 item.each do |cond, rule|
662
+ </span><span class="uncovered0"><a name="line62"></a> 62 case cond
663
+ </span><span class="uncovered1"><a name="line63"></a> 63 when Proc
664
+ </span><span class="uncovered0"><a name="line64"></a> 64 if cond.call(val)
665
+ </span><span class="uncovered1"><a name="line65"></a> 65 result = rule.call(val)
666
+ </span><span class="uncovered0"><a name="line66"></a> 66 break
667
+ </span><span class="uncovered1"><a name="line67"></a> 67 end
668
+ </span><span class="uncovered0"><a name="line68"></a> 68 end
669
+ </span><span class="uncovered1"><a name="line69"></a> 69
670
+ </span><span class="uncovered0"><a name="line70"></a> 70 break if result
671
+ </span><span class="uncovered1"><a name="line71"></a> 71 end
672
+ </span><span class="uncovered0"><a name="line72"></a> 72 end
673
+ </span><span class="uncovered1"><a name="line73"></a> 73
674
+ </span><span class="uncovered0"><a name="line74"></a> 74 break if result
675
+ </span><span class="uncovered1"><a name="line75"></a> 75 end
676
+ </span><span class="uncovered0"><a name="line76"></a> 76
677
+ </span><span class="uncovered1"><a name="line77"></a> 77 return result
678
+ </span><span class="uncovered0"><a name="line78"></a> 78 end
679
+ </span><span class="uncovered1"><a name="line79"></a> 79 end
680
+ </span><span class="inferred0"><a name="line80"></a> 80
681
+ </span><span class="marked1"><a name="line81"></a> 81 module CoerceWithProc #:nodoc:
682
+ </span><span class="marked0"><a name="line82"></a> 82 def coerce val
683
+ </span><span class="uncovered1"><a name="line83"></a> 83 config[:coerce].call(val)
684
+ </span><span class="uncovered0"><a name="line84"></a> 84 end
685
+ </span><span class="uncovered1"><a name="line85"></a> 85 end
686
+ </span><span class="inferred0"><a name="line86"></a> 86
687
+ </span><span class="marked1"><a name="line87"></a> 87 module CoerceNothing #:nodoc:
688
+ </span><span class="marked0"><a name="line88"></a> 88 def coerce val
689
+ </span><span class="marked1"><a name="line89"></a> 89 val
690
+ </span><span class="marked0"><a name="line90"></a> 90 end
691
+ </span><span class="inferred1"><a name="line91"></a> 91 end
692
+ </span><span class="inferred0"><a name="line92"></a> 92
693
+ </span><span class="marked1"><a name="line93"></a> 93 module DefaultWithProc #:nodoc:
694
+ </span><span class="marked0"><a name="line94"></a> 94 def default parent
695
+ </span><span class="marked1"><a name="line95"></a> 95 config[:default].call(parent)
696
+ </span><span class="marked0"><a name="line96"></a> 96 end
697
+ </span><span class="inferred1"><a name="line97"></a> 97 end
698
+ </span><span class="marked0"><a name="line98"></a> 98 module DefaultWithNoProc #:nodoc:
699
+ </span><span class="marked1"><a name="line99"></a> 99 def default parent
700
+ </span><span class="marked0"><a name="line100"></a>100 config[:default].dup
701
+ </span><span class="inferred1"><a name="line101"></a>101 rescue Exception
702
+ </span><span class="marked0"><a name="line102"></a>102 config[:default]
703
+ </span><span class="marked1"><a name="line103"></a>103 end
704
+ </span><span class="inferred0"><a name="line104"></a>104 end
705
+ </span><span class="inferred1"><a name="line105"></a>105
706
+ </span><span class="marked0"><a name="line106"></a>106 module ValidateWithProc #:nodoc:
707
+ </span><span class="marked1"><a name="line107"></a>107 def validate? val
708
+ </span><span class="marked0"><a name="line108"></a>108 return config[:validate].call(val)
709
+ </span><span class="marked1"><a name="line109"></a>109 end
710
+ </span><span class="inferred0"><a name="line110"></a>110 end
711
+ </span><span class="inferred1"><a name="line111"></a>111
712
+ </span><span class="marked0"><a name="line112"></a>112 module ValidateWithNotProc #:nodoc:
713
+ </span><span class="marked1"><a name="line113"></a>113 def validate? val
714
+ </span><span class="uncovered0"><a name="line114"></a>114 return config[:validate] === val
715
+ </span><span class="uncovered1"><a name="line115"></a>115 end
716
+ </span><span class="uncovered0"><a name="line116"></a>116 end
717
+ </span><span class="inferred1"><a name="line117"></a>117
718
+ </span><span class="marked0"><a name="line118"></a>118 module ValidateEach #:nodoc:
719
+ </span><span class="marked1"><a name="line119"></a>119 def validate? val
720
+ </span><span class="uncovered0"><a name="line120"></a>120 return false unless val.respond_to? :all?
721
+ </span><span class="uncovered1"><a name="line121"></a>121
722
+ </span><span class="uncovered0"><a name="line122"></a>122 if self.value_class
723
+ </span><span class="uncovered1"><a name="line123"></a>123 return false unless val.kind_of?(self.value_class)
724
+ </span><span class="uncovered0"><a name="line124"></a>124
725
+ </span><span class="uncovered1"><a name="line125"></a>125 case val
726
+ </span><span class="uncovered0"><a name="line126"></a>126 when Hash
727
+ </span><span class="uncovered1"><a name="line127"></a>127 if config[:validate_each].arity == 2
728
+ </span><span class="uncovered0"><a name="line128"></a>128 val.all? {|item| config[:validate_each].call(*item) }
729
+ </span><span class="uncovered1"><a name="line129"></a>129 else
730
+ </span><span class="uncovered0"><a name="line130"></a>130 ClassX::Validate.validate(val, &amp;config[:validate_each])
731
+ </span><span class="uncovered1"><a name="line131"></a>131 end
732
+ </span><span class="uncovered0"><a name="line132"></a>132 else
733
+ </span><span class="uncovered1"><a name="line133"></a>133 val.all? {|item| config[:validate_each].call(*item) }
734
+ </span><span class="uncovered0"><a name="line134"></a>134 end
735
+ </span><span class="uncovered1"><a name="line135"></a>135 else
736
+ </span><span class="uncovered0"><a name="line136"></a>136 val.all? {|item| config[:validate_each].call(*item) }
737
+ </span><span class="uncovered1"><a name="line137"></a>137 end
738
+ </span><span class="uncovered0"><a name="line138"></a>138 end
739
+ </span><span class="uncovered1"><a name="line139"></a>139 end
740
+ </span><span class="inferred0"><a name="line140"></a>140
741
+ </span><span class="marked1"><a name="line141"></a>141 module ValidateKindOf #:nodoc:
742
+ </span><span class="marked0"><a name="line142"></a>142 def validate? val
743
+ </span><span class="marked1"><a name="line143"></a>143 return val.kind_of?(self.value_class)
744
+ </span><span class="marked0"><a name="line144"></a>144 end
745
+ </span><span class="inferred1"><a name="line145"></a>145 end
746
+ </span><span class="inferred0"><a name="line146"></a>146
747
+ </span><span class="marked1"><a name="line147"></a>147 module ValidateRespondTo #:nodoc:
748
+ </span><span class="marked0"><a name="line148"></a>148 def validate? val
749
+ </span><span class="uncovered1"><a name="line149"></a>149 return val.respond_to?(config[:respond_to])
750
+ </span><span class="uncovered0"><a name="line150"></a>150 end
751
+ </span><span class="uncovered1"><a name="line151"></a>151 end
752
+ </span><span class="inferred0"><a name="line152"></a>152
753
+ </span><span class="marked1"><a name="line153"></a>153 module ValidateNothing #:nodoc:
754
+ </span><span class="marked0"><a name="line154"></a>154 def validate? val
755
+ </span><span class="inferred1"><a name="line155"></a>155 # nothing checked.
756
+ </span><span class="marked0"><a name="line156"></a>156 true
757
+ </span><span class="marked1"><a name="line157"></a>157 end
758
+ </span><span class="inferred0"><a name="line158"></a>158 end
759
+ </span><span class="inferred1"><a name="line159"></a>159
760
+ </span><span class="marked0"><a name="line160"></a>160 module TriggerArrayProc #:nodoc:
761
+ </span><span class="marked1"><a name="line161"></a>161 def trigger parent, val
762
+ </span><span class="marked0"><a name="line162"></a>162 config[:trigger].each do |trg|
763
+ </span><span class="uncovered1"><a name="line163"></a>163 trg.call(parent, val)
764
+ </span><span class="uncovered0"><a name="line164"></a>164 end
765
+ </span><span class="marked1"><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 end
768
+ </span><span class="inferred0"><a name="line168"></a>168
769
+ </span><span class="marked1"><a name="line169"></a>169 module InstanceMethods #:nodoc:
770
+ </span><span class="marked0"><a name="line170"></a>170 def initialize val
771
+ </span><span class="marked1"><a name="line171"></a>171 @parent = val
772
+ </span><span class="marked0"><a name="line172"></a>172 @data = nil
773
+ </span><span class="inferred1"><a name="line173"></a>173 end
774
+ </span><span class="inferred0"><a name="line174"></a>174
775
+ </span><span class="marked1"><a name="line175"></a>175 def get
776
+ </span><span class="marked0"><a name="line176"></a>176 @data ||= self.class.default(@parent)
777
+ </span><span class="marked1"><a name="line177"></a>177 end
778
+ </span><span class="inferred0"><a name="line178"></a>178
779
+ </span><span class="inferred1"><a name="line179"></a>179 # XXX:
780
+ </span><span class="inferred0"><a name="line180"></a>180 # you should not call this method except for @parent instance's setter method.
781
+ </span><span class="inferred1"><a name="line181"></a>181 # It's because caching as instance_variable in @parent instance for performance.
782
+ </span><span class="marked0"><a name="line182"></a>182 def set val
783
+ </span><span class="marked1"><a name="line183"></a>183 val = self.class.coerce(val)
784
+ </span><span class="marked0"><a name="line184"></a>184 raise ClassX::InvalidAttrArgument, &quot;#{val.inspect} is not valid for #{self.inspect}&quot; unless self.class.validate? val
785
+ </span><span class="marked1"><a name="line185"></a>185 @data = val
786
+ </span><span class="inferred0"><a name="line186"></a>186
787
+ </span><span class="marked1"><a name="line187"></a>187 self.class.trigger(@parent, val)
788
+ </span><span class="marked0"><a name="line188"></a>188 @data
789
+ </span><span class="inferred1"><a name="line189"></a>189 end
790
+ </span><span class="inferred0"><a name="line190"></a>190
791
+ </span><span class="marked1"><a name="line191"></a>191 def inspect
792
+ </span><span class="uncovered0"><a name="line192"></a>192 &quot;&lt;#ClassX::Attribute:#{object_id} #{ @data.nil? ? '@data=nil' : '@data=' + @data.inspect } @parent=#{@parent} config=#{self.class.config.inspect}&gt;&quot;
793
+ </span><span class="uncovered1"><a name="line193"></a>193 end
794
+ </span><span class="uncovered0"><a name="line194"></a>194 end
795
+ </span><span class="uncovered1"><a name="line195"></a>195 end
796
+ </span><span class="inferred0"><a name="line196"></a>196
797
+ </span><span class="inferred1"><a name="line197"></a>197 #
798
+ </span><span class="inferred0"><a name="line198"></a>198 # generating anonymous class for meta attribute class.
799
+ </span><span class="inferred1"><a name="line199"></a>199 #
800
+ </span><span class="marked0"><a name="line200"></a>200 class AttributeFactory
801
+ </span><span class="inferred1"><a name="line201"></a>201 #
802
+ </span><span class="inferred0"><a name="line202"></a>202 # creating anonymous class for meta attribute class.
803
+ </span><span class="marked1"><a name="line203"></a>203 def self.create args
804
+ </span><span class="inferred0"><a name="line204"></a>204 # TODO: hmm, ClassX::Commandable do nothing when freezed.
805
+ </span><span class="inferred1"><a name="line205"></a>205 #
806
+ </span><span class="inferred0"><a name="line206"></a>206 # if you would like to change attribute's infomation, it's better to redefine attribute.
807
+ </span><span class="inferred1"><a name="line207"></a>207 # So, config should freezed.
808
+ </span><span class="inferred0"><a name="line208"></a>208 # args.each do |key, val|
809
+ </span><span class="inferred1"><a name="line209"></a>209 # key.freeze
810
+ </span><span class="inferred0"><a name="line210"></a>210 # val.freeze
811
+ </span><span class="inferred1"><a name="line211"></a>211 # end
812
+ </span><span class="inferred0"><a name="line212"></a>212 # args.freeze
813
+ </span><span class="inferred1"><a name="line213"></a>213
814
+ </span><span class="marked0"><a name="line214"></a>214 raise ClassX::RequiredAttrShouldNotHaveDefault if args[:optional] == false &amp;&amp; !args[:default].nil?
815
+ </span><span class="marked1"><a name="line215"></a>215 raise ClassX::OptionalAttrShouldBeWritable if args[:optional] &amp;&amp; args[:writable] == false
816
+ </span><span class="inferred0"><a name="line216"></a>216
817
+ </span><span class="marked1"><a name="line217"></a>217 klass = Class.new
818
+ </span><span class="inferred0"><a name="line218"></a>218
819
+ </span><span class="marked1"><a name="line219"></a>219 klass.extend(ClassX::AttributeMethods::ClassMethods)
820
+ </span><span class="inferred0"><a name="line220"></a>220
821
+ </span><span class="inferred1"><a name="line221"></a>221 # you specify type changing rule with :coerce option.
822
+ </span><span class="marked0"><a name="line222"></a>222 if args[:coerce]
823
+ </span><span class="marked1"><a name="line223"></a>223 case args[:coerce]
824
+ </span><span class="marked0"><a name="line224"></a>224 when Hash
825
+ </span><span class="uncovered1"><a name="line225"></a>225 klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceWithHash)
826
+ </span><span class="marked0"><a name="line226"></a>226 when Array
827
+ </span><span class="uncovered1"><a name="line227"></a>227 klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceWithArray)
828
+ </span><span class="marked0"><a name="line228"></a>228 when Proc
829
+ </span><span class="marked1"><a name="line229"></a>229 klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceWithProc)
830
+ </span><span class="inferred0"><a name="line230"></a>230 end
831
+ </span><span class="inferred1"><a name="line231"></a>231 else
832
+ </span><span class="marked0"><a name="line232"></a>232 klass.extend(ClassX::AttributeMethods::ClassMethods::CoerceNothing)
833
+ </span><span class="inferred1"><a name="line233"></a>233 end
834
+ </span><span class="inferred0"><a name="line234"></a>234
835
+ </span><span class="inferred1"><a name="line235"></a>235 # default paramater for attribute.
836
+ </span><span class="inferred0"><a name="line236"></a>236 # if default is Proc, run Proc every time in instanciate.
837
+ </span><span class="marked1"><a name="line237"></a>237 case args[:default]
838
+ </span><span class="marked0"><a name="line238"></a>238 when Proc
839
+ </span><span class="marked1"><a name="line239"></a>239 klass.extend(ClassX::AttributeMethods::ClassMethods::DefaultWithProc)
840
+ </span><span class="inferred0"><a name="line240"></a>240 else
841
+ </span><span class="marked1"><a name="line241"></a>241 klass.extend(ClassX::AttributeMethods::ClassMethods::DefaultWithNoProc)
842
+ </span><span class="inferred0"><a name="line242"></a>242 end
843
+ </span><span class="inferred1"><a name="line243"></a>243
844
+ </span><span class="inferred0"><a name="line244"></a>244 # you can specify :validate option for checking when value is setted.
845
+ </span><span class="inferred1"><a name="line245"></a>245 # you can use :respond_to as shotcut for specifying { :validate =&gt; proc {|val| respond_to?(val, true) } }
846
+ </span><span class="inferred0"><a name="line246"></a>246 # you can use :isa or :kind_of as shotcut for specifying { :validate =&gt; proc {|val| kind_of?(val) } }
847
+ </span><span class="marked1"><a name="line247"></a>247 if args[:validate]
848
+ </span><span class="marked0"><a name="line248"></a>248 case args[:validate]
849
+ </span><span class="marked1"><a name="line249"></a>249 when Proc
850
+ </span><span class="marked0"><a name="line250"></a>250 klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateWithProc)
851
+ </span><span class="uncovered1"><a name="line251"></a>251 else
852
+ </span><span class="uncovered0"><a name="line252"></a>252 klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateWithNotProc)
853
+ </span><span class="uncovered1"><a name="line253"></a>253 end
854
+ </span><span class="marked0"><a name="line254"></a>254 elsif args[:validate_each]
855
+ </span><span class="uncovered1"><a name="line255"></a>255 klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateEach)
856
+ </span><span class="marked0"><a name="line256"></a>256 elsif mod = ( args[:isa] || args[:kind_of] )
857
+ </span><span class="marked1"><a name="line257"></a>257 klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateKindOf)
858
+ </span><span class="marked0"><a name="line258"></a>258 elsif args[:respond_to]
859
+ </span><span class="uncovered1"><a name="line259"></a>259 klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateRespondTo)
860
+ </span><span class="inferred0"><a name="line260"></a>260 else
861
+ </span><span class="marked1"><a name="line261"></a>261 klass.extend(ClassX::AttributeMethods::ClassMethods::ValidateNothing)
862
+ </span><span class="inferred0"><a name="line262"></a>262 end
863
+ </span><span class="inferred1"><a name="line263"></a>263
864
+ </span><span class="inferred0"><a name="line264"></a>264 # you can specify :trigger option for invoking event on setting value to attribute.
865
+ </span><span class="inferred1"><a name="line265"></a>265 # :trigger should take Proc or multi Proc Array.
866
+ </span><span class="marked0"><a name="line266"></a>266 if args[:trigger]
867
+ </span><span class="uncovered1"><a name="line267"></a>267 unless args[:trigger].kind_of?(Array)
868
+ </span><span class="uncovered0"><a name="line268"></a>268 args[:trigger] = [ args[:trigger] ]
869
+ </span><span class="uncovered1"><a name="line269"></a>269 end
870
+ </span><span class="uncovered0"><a name="line270"></a>270 klass.extend(ClassX::AttributeMethods::ClassMethods::TriggerArrayProc)
871
+ </span><span class="inferred1"><a name="line271"></a>271 else
872
+ </span><span class="marked0"><a name="line272"></a>272 args[:trigger] = []
873
+ </span><span class="marked1"><a name="line273"></a>273 klass.extend(ClassX::AttributeMethods::ClassMethods::TriggerArrayProc)
874
+ </span><span class="inferred0"><a name="line274"></a>274 end
875
+ </span><span class="inferred1"><a name="line275"></a>275
876
+ </span><span class="inferred0"><a name="line276"></a>276 # for extending attribute point.
877
+ </span><span class="marked1"><a name="line277"></a>277 if args[:include]
878
+ </span><span class="marked0"><a name="line278"></a>278 case args[:include]
879
+ </span><span class="marked1"><a name="line279"></a>279 when Array
880
+ </span><span class="uncovered0"><a name="line280"></a>280 args[:include].each do |mod|
881
+ </span><span class="uncovered1"><a name="line281"></a>281 klass.__send__ :include, mod
882
+ </span><span class="uncovered0"><a name="line282"></a>282 end
883
+ </span><span class="inferred1"><a name="line283"></a>283 else
884
+ </span><span class="marked0"><a name="line284"></a>284 klass.__send__ :include, args[:include]
885
+ </span><span class="inferred1"><a name="line285"></a>285 end
886
+ </span><span class="inferred0"><a name="line286"></a>286 end
887
+ </span><span class="inferred1"><a name="line287"></a>287
888
+ </span><span class="marked0"><a name="line288"></a>288 if args[:extend]
889
+ </span><span class="uncovered1"><a name="line289"></a>289 case args[:extend]
890
+ </span><span class="uncovered0"><a name="line290"></a>290 when Array
891
+ </span><span class="uncovered1"><a name="line291"></a>291 args[:extend].each do |mod|
892
+ </span><span class="uncovered0"><a name="line292"></a>292 klass.__send__ :extend, mod
893
+ </span><span class="uncovered1"><a name="line293"></a>293 end
894
+ </span><span class="uncovered0"><a name="line294"></a>294 else
895
+ </span><span class="uncovered1"><a name="line295"></a>295 klass.__send__ :extend, args[:extend]
896
+ </span><span class="uncovered0"><a name="line296"></a>296 end
897
+ </span><span class="uncovered1"><a name="line297"></a>297 end
898
+ </span><span class="inferred0"><a name="line298"></a>298
899
+ </span><span class="inferred1"><a name="line299"></a>299 # XXX: Hack for defining class method for klass
900
+ </span><span class="marked0"><a name="line300"></a>300 tmp_mod = Module.new
901
+ </span><span class="marked1"><a name="line301"></a>301 tmp_mod.module_eval do
902
+ </span><span class="marked0"><a name="line302"></a>302 define_method :config do
903
+ </span><span class="marked1"><a name="line303"></a>303 args
904
+ </span><span class="inferred0"><a name="line304"></a>304 end
905
+ </span><span class="inferred1"><a name="line305"></a>305 end
906
+ </span><span class="marked0"><a name="line306"></a>306 klass.extend(tmp_mod)
907
+ </span><span class="inferred1"><a name="line307"></a>307
908
+ </span><span class="marked0"><a name="line308"></a>308 klass.class_eval do
909
+ </span><span class="marked1"><a name="line309"></a>309 include ClassX::AttributeMethods::InstanceMethods
910
+ </span><span class="inferred0"><a name="line310"></a>310 end
911
+ </span><span class="inferred1"><a name="line311"></a>311
912
+ </span><span class="marked0"><a name="line312"></a>312 klass
913
+ </span><span class="inferred1"><a name="line313"></a>313 end
914
+ </span><span class="inferred0"><a name="line314"></a>314 end
915
+ </span><span class="inferred1"><a name="line315"></a>315 end
916
+ </span></pre><hr/>
917
+ <p>Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'>rcov code coverage analysis tool for Ruby</a>
918
+ version 0.8.1.2.</p>
919
+ <p><a href='http://validator.w3.org/check/referer'><img src='http://www.w3.org/Icons/valid-xhtml10' height='31' alt='Valid XHTML 1.0!' width='88'/>
920
+ </a>
921
+ <a href='http://jigsaw.w3.org/css-validator/check/referer'><img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' style='border:0;width:88px;height:31px'/>
922
+ </a>
923
+ </p>
924
+ </body>
925
+ </html>