ruby-contract 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +56 -0
- data/Manifest +85 -0
- data/README +32 -0
- data/TODO +83 -0
- data/doc/classes/Contract.html +599 -0
- data/doc/classes/Contract/Check.html +229 -0
- data/doc/classes/Contract/Check/All.html +172 -0
- data/doc/classes/Contract/Check/Any.html +172 -0
- data/doc/classes/Contract/Check/Block.html +172 -0
- data/doc/classes/Contract/Check/None.html +173 -0
- data/doc/classes/Contract/Check/Quack.html +172 -0
- data/doc/classes/Contract/ContractError.html +151 -0
- data/doc/classes/Contract/ContractException.html +162 -0
- data/doc/classes/Contract/ContractMismatch.html +134 -0
- data/doc/classes/Kernel.html +256 -0
- data/doc/classes/Method.html +135 -0
- data/doc/classes/MethodSignatureMixin.html +208 -0
- data/doc/classes/Module.html +526 -0
- data/doc/created.rid +1 -0
- data/doc/dot/f_0.dot +14 -0
- data/doc/dot/f_0.png +0 -0
- data/doc/dot/f_1.dot +14 -0
- data/doc/dot/f_1.png +0 -0
- data/doc/dot/f_2.dot +14 -0
- data/doc/dot/f_2.png +0 -0
- data/doc/dot/f_3.dot +112 -0
- data/doc/dot/f_3.png +0 -0
- data/doc/dot/f_4.dot +62 -0
- data/doc/dot/f_4.png +0 -0
- data/doc/dot/f_5.dot +62 -0
- data/doc/dot/f_5.png +0 -0
- data/doc/dot/f_6.dot +224 -0
- data/doc/dot/f_6.png +0 -0
- data/doc/dot/f_6_0.dot +24 -0
- data/doc/dot/f_6_0.png +0 -0
- data/doc/dot/f_6_1.dot +24 -0
- data/doc/dot/f_6_1.png +0 -0
- data/doc/dot/f_7.dot +62 -0
- data/doc/dot/f_7.png +0 -0
- data/doc/files/COPYING.html +168 -0
- data/doc/files/README.html +146 -0
- data/doc/files/TODO.html +240 -0
- data/doc/files/lib/contract/assertions_rb.html +118 -0
- data/doc/files/lib/contract/exception_rb.html +125 -0
- data/doc/files/lib/contract/integration_rb.html +130 -0
- data/doc/files/lib/contract/overrides_rb.html +118 -0
- data/doc/files/lib/contract_rb.html +127 -0
- data/doc/fr_class_index.html +40 -0
- data/doc/fr_file_index.html +34 -0
- data/doc/fr_method_index.html +45 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/contract.rb +146 -0
- data/lib/contract/assertions.rb +42 -0
- data/lib/contract/exception.rb +95 -0
- data/lib/contract/integration.rb +664 -0
- data/lib/contract/overrides.rb +41 -0
- data/setup.rb +1360 -0
- data/test/coverage/_-lib-contract-assertions_rb.html +526 -0
- data/test/coverage/_-lib-contract-exception_rb.html +632 -0
- data/test/coverage/_-lib-contract-integration_rb.html +1450 -0
- data/test/coverage/_-lib-contract-overrides_rb.html +524 -0
- data/test/coverage/_-lib-contract_rb.html +724 -0
- data/test/coverage/__-lib-contract-assertions_rb.html +484 -0
- data/test/coverage/__-lib-contract-exception_rb.html +537 -0
- data/test/coverage/__-lib-contract-integration_rb.html +946 -0
- data/test/coverage/__-lib-contract-overrides_rb.html +483 -0
- data/test/coverage/__-lib-contract_rb.html +583 -0
- data/test/coverage/index.html +93 -0
- data/test/tc_all.rb +8 -0
- data/test/tc_contract.rb +109 -0
- data/test/tc_exception.rb +43 -0
- data/test/tc_integration.rb +357 -0
- metadata +136 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Contract::ContractError</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Contract::ContractError</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/contract/exception_rb.html">
|
59
|
+
lib/contract/exception.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
StandardError
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
<div id="diagram">
|
81
|
+
<map id="map" name="map">
|
82
|
+
<area shape="RECT" coords="32,113,104,161" href="../Contract.html" alt="Contract" title="Contract">
|
83
|
+
<area shape="RECT" coords="187,113,328,161" href="ContractError.html" alt="Contract::ContractError" title="Contract::ContractError">
|
84
|
+
<area shape="RECT" coords="380,113,543,161" href="ContractMismatch.html" alt="Contract::ContractMismatch" title="Contract::ContractMismatch">
|
85
|
+
<area shape="RECT" coords="273,17,428,65" href="ContractException.html" alt="Contract::ContractException" title="Contract::ContractException">
|
86
|
+
</map>
|
87
|
+
<img src="../../dot/f_3.png" usemap="#map" border=0 alt="lib/contract/exception.rb">
|
88
|
+
</div>
|
89
|
+
|
90
|
+
<div id="description">
|
91
|
+
<p>
|
92
|
+
Represents an unexpected failure while processing a contract test. This is
|
93
|
+
more critical than <a href="ContractMismatch.html">ContractMismatch</a> and
|
94
|
+
usually means that something is wrong with the test itself.
|
95
|
+
</p>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
|
106
|
+
<!-- if includes -->
|
107
|
+
<div id="includes">
|
108
|
+
<h3 class="section-bar">Included Modules</h3>
|
109
|
+
|
110
|
+
<div id="includes-list">
|
111
|
+
<span class="include-name"><a href="ContractException.html">ContractException</a></span>
|
112
|
+
</div>
|
113
|
+
</div>
|
114
|
+
|
115
|
+
<div id="section">
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<div id="attribute-list">
|
122
|
+
<h3 class="section-bar">Attributes</h3>
|
123
|
+
|
124
|
+
<div class="name-list">
|
125
|
+
<table>
|
126
|
+
<tr class="top-aligned-row context-row">
|
127
|
+
<td class="context-item-name">type</td>
|
128
|
+
<td class="context-item-value"> [R] </td>
|
129
|
+
<td class="context-item-desc">
|
130
|
+
The type of the original Exception that triggered the unexpected failure.
|
131
|
+
|
132
|
+
</td>
|
133
|
+
</tr>
|
134
|
+
</table>
|
135
|
+
</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
<!-- if method_list -->
|
141
|
+
|
142
|
+
|
143
|
+
</div>
|
144
|
+
|
145
|
+
|
146
|
+
<div id="validator-badges">
|
147
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
148
|
+
</div>
|
149
|
+
|
150
|
+
</body>
|
151
|
+
</html>
|
@@ -0,0 +1,162 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Contract::ContractException</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Contract::ContractException</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/contract/exception_rb.html">
|
59
|
+
lib/contract/exception.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
<div id="diagram">
|
75
|
+
<map id="map" name="map">
|
76
|
+
<area shape="RECT" coords="32,113,104,161" href="../Contract.html" alt="Contract" title="Contract">
|
77
|
+
<area shape="RECT" coords="187,113,328,161" href="ContractError.html" alt="Contract::ContractError" title="Contract::ContractError">
|
78
|
+
<area shape="RECT" coords="380,113,543,161" href="ContractMismatch.html" alt="Contract::ContractMismatch" title="Contract::ContractMismatch">
|
79
|
+
<area shape="RECT" coords="273,17,428,65" href="ContractException.html" alt="Contract::ContractException" title="Contract::ContractException">
|
80
|
+
</map>
|
81
|
+
<img src="../../dot/f_3.png" usemap="#map" border=0 alt="lib/contract/exception.rb">
|
82
|
+
</div>
|
83
|
+
|
84
|
+
<div id="description">
|
85
|
+
<p>
|
86
|
+
Exceptions raised by <a href="../Contract.html">Contract</a> contain some
|
87
|
+
useful meta-information. This module is mixed into Exceptions that provide
|
88
|
+
such information.
|
89
|
+
</p>
|
90
|
+
|
91
|
+
</div>
|
92
|
+
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
<!-- if includes -->
|
101
|
+
|
102
|
+
<div id="section">
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
<div id="attribute-list">
|
109
|
+
<h3 class="section-bar">Attributes</h3>
|
110
|
+
|
111
|
+
<div class="name-list">
|
112
|
+
<table>
|
113
|
+
<tr class="top-aligned-row context-row">
|
114
|
+
<td class="context-item-name">original_message</td>
|
115
|
+
<td class="context-item-value"> [R] </td>
|
116
|
+
<td class="context-item-desc">
|
117
|
+
The original, unfiltered exception message.
|
118
|
+
|
119
|
+
</td>
|
120
|
+
</tr>
|
121
|
+
<tr class="top-aligned-row context-row">
|
122
|
+
<td class="context-item-name">test_contract</td>
|
123
|
+
<td class="context-item-value"> [R] </td>
|
124
|
+
<td class="context-item-desc">
|
125
|
+
What contract was that method part of?
|
126
|
+
|
127
|
+
</td>
|
128
|
+
</tr>
|
129
|
+
<tr class="top-aligned-row context-row">
|
130
|
+
<td class="context-item-name">test_method</td>
|
131
|
+
<td class="context-item-value"> [R] </td>
|
132
|
+
<td class="context-item-desc">
|
133
|
+
What method implemented that test?
|
134
|
+
|
135
|
+
</td>
|
136
|
+
</tr>
|
137
|
+
<tr class="top-aligned-row context-row">
|
138
|
+
<td class="context-item-name">test_object</td>
|
139
|
+
<td class="context-item-value"> [R] </td>
|
140
|
+
<td class="context-item-desc">
|
141
|
+
What object was tested when this Exception was raised?
|
142
|
+
|
143
|
+
</td>
|
144
|
+
</tr>
|
145
|
+
</table>
|
146
|
+
</div>
|
147
|
+
</div>
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<!-- if method_list -->
|
152
|
+
|
153
|
+
|
154
|
+
</div>
|
155
|
+
|
156
|
+
|
157
|
+
<div id="validator-badges">
|
158
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
159
|
+
</div>
|
160
|
+
|
161
|
+
</body>
|
162
|
+
</html>
|
@@ -0,0 +1,134 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Contract::ContractMismatch</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Contract::ContractMismatch</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/contract/exception_rb.html">
|
59
|
+
lib/contract/exception.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
TypeError
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
<div id="diagram">
|
81
|
+
<map id="map" name="map">
|
82
|
+
<area shape="RECT" coords="32,113,104,161" href="../Contract.html" alt="Contract" title="Contract">
|
83
|
+
<area shape="RECT" coords="187,113,328,161" href="ContractError.html" alt="Contract::ContractError" title="Contract::ContractError">
|
84
|
+
<area shape="RECT" coords="380,113,543,161" href="ContractMismatch.html" alt="Contract::ContractMismatch" title="Contract::ContractMismatch">
|
85
|
+
<area shape="RECT" coords="273,17,428,65" href="ContractException.html" alt="Contract::ContractException" title="Contract::ContractException">
|
86
|
+
</map>
|
87
|
+
<img src="../../dot/f_3.png" usemap="#map" border=0 alt="lib/contract/exception.rb">
|
88
|
+
</div>
|
89
|
+
|
90
|
+
<div id="description">
|
91
|
+
<p>
|
92
|
+
Represents a failed test in a contract. This means that an object simply
|
93
|
+
does not fulfill one of the parts of a contract. Subclass of TypeError.
|
94
|
+
</p>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
|
98
|
+
|
99
|
+
</div>
|
100
|
+
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
|
105
|
+
<!-- if includes -->
|
106
|
+
<div id="includes">
|
107
|
+
<h3 class="section-bar">Included Modules</h3>
|
108
|
+
|
109
|
+
<div id="includes-list">
|
110
|
+
<span class="include-name"><a href="ContractException.html">ContractException</a></span>
|
111
|
+
</div>
|
112
|
+
</div>
|
113
|
+
|
114
|
+
<div id="section">
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<!-- if method_list -->
|
124
|
+
|
125
|
+
|
126
|
+
</div>
|
127
|
+
|
128
|
+
|
129
|
+
<div id="validator-badges">
|
130
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
131
|
+
</div>
|
132
|
+
|
133
|
+
</body>
|
134
|
+
</html>
|
@@ -0,0 +1,256 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Kernel</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Kernel</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/contract/integration_rb.html">
|
59
|
+
lib/contract/integration.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
<div id="diagram">
|
75
|
+
<map id="map" name="map">
|
76
|
+
<area shape="RECT" coords="33,117,105,165" href="Method.html" alt="Method" title="Method">
|
77
|
+
<area shape="RECT" coords="259,117,331,165" href="Contract.html" alt="Contract" title="Contract">
|
78
|
+
<area shape="RECT" coords="393,21,465,69" href="Module.html" alt="Module" title="Module">
|
79
|
+
<area shape="RECT" coords="515,21,621,69" href="UnboundMethod.html" alt="UnboundMethod" title="UnboundMethod">
|
80
|
+
<area shape="RECT" coords="355,117,488,165" href="Contract/Check/Any.html" alt="Contract::Check::Any" title="Contract::Check::Any">
|
81
|
+
<area shape="RECT" coords="512,117,635,165" href="Contract/Check/All.html" alt="Contract::Check::All" title="Contract::Check::All">
|
82
|
+
<area shape="RECT" coords="659,117,795,165" href="Contract/Check/None.html" alt="Contract::Check::None" title="Contract::Check::None">
|
83
|
+
<area shape="RECT" coords="819,117,957,165" href="Contract/Check/Block.html" alt="Contract::Check::Block" title="Contract::Check::Block">
|
84
|
+
<area shape="RECT" coords="659,21,795,69" href="Contract/Check/Base.html" alt="Contract::Check::Base" title="Contract::Check::Base">
|
85
|
+
<area shape="RECT" coords="981,117,1123,165" href="Contract/Check/Quack.html" alt="Contract::Check::Quack" title="Contract::Check::Quack">
|
86
|
+
<area shape="RECT" coords="7,17,132,61" href="MethodSignatureMixin.html" alt="MethodSignatureMixin" title="MethodSignatureMixin">
|
87
|
+
<area shape="RECT" coords="127,17,220,61" href="Kernel.html" alt="Kernel" title="Kernel">
|
88
|
+
</map>
|
89
|
+
<img src="../dot/f_6.png" usemap="#map" border=0 alt="lib/contract/integration.rb">
|
90
|
+
</div>
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
<div id="method-list">
|
97
|
+
<h3 class="section-bar">Methods</h3>
|
98
|
+
|
99
|
+
<div class="name-list">
|
100
|
+
<a href="#M000019">adaption</a>
|
101
|
+
</div>
|
102
|
+
</div>
|
103
|
+
|
104
|
+
</div>
|
105
|
+
|
106
|
+
|
107
|
+
<!-- if includes -->
|
108
|
+
|
109
|
+
<div id="section">
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
<!-- if method_list -->
|
119
|
+
<div id="methods">
|
120
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
121
|
+
|
122
|
+
<div id="method-M000019" class="method-detail">
|
123
|
+
<a name="M000019"></a>
|
124
|
+
|
125
|
+
<div class="method-heading">
|
126
|
+
<a href="#M000019" class="method-signature">
|
127
|
+
<span class="method-name">adaption</span><span class="method-args">(options = {}) {|source_object| ...}</span>
|
128
|
+
</a>
|
129
|
+
</div>
|
130
|
+
|
131
|
+
<div class="method-description">
|
132
|
+
<p>
|
133
|
+
Adds an adaption route from the specified type to the specified type. Basic
|
134
|
+
usage looks like this:
|
135
|
+
</p>
|
136
|
+
<pre>
|
137
|
+
adaption :from => StringIO, :to => String, :via => :read
|
138
|
+
</pre>
|
139
|
+
<p>
|
140
|
+
This method takes various options. Here’s a complete list:
|
141
|
+
</p>
|
142
|
+
<table>
|
143
|
+
<tr><td valign="top"><tt>:from</tt>:</td><td>The type that can be converted from. Defaults to <tt>self</tt> meaning you
|
144
|
+
can safely omit it in Class, <a href="Module.html">Module</a> or <a
|
145
|
+
href="Contract.html">Contract</a> context.
|
146
|
+
|
147
|
+
</td></tr>
|
148
|
+
<tr><td valign="top"><tt>:to</tt>:</td><td>The type that can be converted to. Defaults to <tt>self</tt> meaning you
|
149
|
+
can safely omit it in Class, <a href="Module.html">Module</a> or <a
|
150
|
+
href="Contract.html">Contract</a> context.
|
151
|
+
|
152
|
+
<p>
|
153
|
+
Note that you need to specify either <tt>:from</tt> or <tt>:to</tt>.
|
154
|
+
</p>
|
155
|
+
</td></tr>
|
156
|
+
<tr><td valign="top"><tt>:via</tt>:</td><td>How the <tt>:from</tt> type will be converted to the <tt>:to</tt> type. If
|
157
|
+
this is a Symbol the conversion will be done by invoking the method
|
158
|
+
identified by that Symbol on the source object. Otherwise this should be
|
159
|
+
something that responds to the <tt>call</tt> method (for example Methods
|
160
|
+
and Procs) which will get the source object as its argument and which
|
161
|
+
should return the target object.
|
162
|
+
|
163
|
+
</td></tr>
|
164
|
+
<tr><td valign="top"><tt>:if</tt>:</td><td>The conversion can only be performed if this condition is met. This can
|
165
|
+
either be something that implements the === case equivalence operator or
|
166
|
+
something that implements the <tt>call</tt> method. So Methods, Procs,
|
167
|
+
Modules, Classes and Contracts all make sense in this context. You can also
|
168
|
+
specify a Symbol in which case the conversion can only be performed if the
|
169
|
+
source object responds to the method identified by that Symbol.
|
170
|
+
|
171
|
+
<p>
|
172
|
+
Note that the <tt>:if</tt> option will default to the same value as the
|
173
|
+
<tt>:via</tt> option if the <tt>:via</tt> option is a Symbol.
|
174
|
+
</p>
|
175
|
+
</td></tr>
|
176
|
+
</table>
|
177
|
+
<p>
|
178
|
+
If you invoke this method with a block it will be used instead of the
|
179
|
+
<tt>:via</tt> option.
|
180
|
+
</p>
|
181
|
+
<p>
|
182
|
+
See <a href="Contract.html#M000002">Contract.adapt</a> for how conversion
|
183
|
+
look-ups are performed.
|
184
|
+
</p>
|
185
|
+
<p><a class="source-toggle" href="#"
|
186
|
+
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
187
|
+
<div class="method-source-code" id="M000019-source">
|
188
|
+
<pre>
|
189
|
+
<span class="ruby-comment cmt"># File lib/contract/integration.rb, line 512</span>
|
190
|
+
512: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">adaption</span>(<span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-comment cmt"># :yield: source_object</span>
|
191
|
+
513: <span class="ruby-identifier">options</span> = {
|
192
|
+
514: <span class="ruby-identifier">:from</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">self</span>,
|
193
|
+
515: <span class="ruby-identifier">:to</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">self</span>
|
194
|
+
516: }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
|
195
|
+
517:
|
196
|
+
518: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">then</span>
|
197
|
+
519: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:via</span>) <span class="ruby-keyword kw">then</span>
|
198
|
+
520: <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Can't use both block and :via"</span>)
|
199
|
+
521: <span class="ruby-keyword kw">else</span>
|
200
|
+
522: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>] = <span class="ruby-identifier">block</span>
|
201
|
+
523: <span class="ruby-keyword kw">end</span>
|
202
|
+
524: <span class="ruby-keyword kw">end</span>
|
203
|
+
525:
|
204
|
+
526: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>].<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_sym</span>) <span class="ruby-keyword kw">then</span>
|
205
|
+
527: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>].<span class="ruby-identifier">to_sym</span>
|
206
|
+
528: <span class="ruby-keyword kw">end</span>
|
207
|
+
529:
|
208
|
+
530: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
|
209
|
+
531:
|
210
|
+
532: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-keyword kw">then</span>
|
211
|
+
533: <span class="ruby-identifier">symbol</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>]
|
212
|
+
534: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>] = <span class="ruby-identifier">lambda</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">symbol</span>) }
|
213
|
+
535: <span class="ruby-keyword kw">end</span>
|
214
|
+
536:
|
215
|
+
537: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>].<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_sym</span>) <span class="ruby-keyword kw">then</span>
|
216
|
+
538: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>].<span class="ruby-identifier">to_sym</span>
|
217
|
+
539: <span class="ruby-keyword kw">end</span>
|
218
|
+
540:
|
219
|
+
541: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-keyword kw">then</span>
|
220
|
+
542: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>] = <span class="ruby-constant">Contract</span><span class="ruby-operator">::</span><span class="ruby-constant">Check</span><span class="ruby-operator">::</span><span class="ruby-constant">Quack</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>]]
|
221
|
+
543: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>].<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:call</span>) <span class="ruby-keyword kw">then</span>
|
222
|
+
544: <span class="ruby-identifier">callable</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>]
|
223
|
+
545: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:if</span>] = <span class="ruby-constant">Contract</span><span class="ruby-operator">::</span><span class="ruby-constant">Check</span>.<span class="ruby-identifier">block</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">callable</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">obj</span>) }
|
224
|
+
546: <span class="ruby-keyword kw">end</span>
|
225
|
+
547:
|
226
|
+
548: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:from</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:to</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">then</span>
|
227
|
+
549: <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Need to specify either :from or :to"</span>)
|
228
|
+
550: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:from</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:to</span>] <span class="ruby-keyword kw">then</span>
|
229
|
+
551: <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Self-adaption: :from and :to both are "</span> <span class="ruby-operator">+</span>
|
230
|
+
552: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:to</span>].<span class="ruby-identifier">inspect</span>)
|
231
|
+
553: <span class="ruby-keyword kw">end</span>
|
232
|
+
554:
|
233
|
+
555: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:via</span>]
|
234
|
+
556: <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"Need to specify how to adapt (use :via or block)"</span>)
|
235
|
+
557: <span class="ruby-keyword kw">end</span>
|
236
|
+
558:
|
237
|
+
559: <span class="ruby-constant">Contract</span>.<span class="ruby-identifier">adaptions</span>[<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:to</span>]] <span class="ruby-operator"><<</span> <span class="ruby-identifier">options</span>
|
238
|
+
560: <span class="ruby-keyword kw">end</span>
|
239
|
+
</pre>
|
240
|
+
</div>
|
241
|
+
</div>
|
242
|
+
</div>
|
243
|
+
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
|
248
|
+
</div>
|
249
|
+
|
250
|
+
|
251
|
+
<div id="validator-badges">
|
252
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
253
|
+
</div>
|
254
|
+
|
255
|
+
</body>
|
256
|
+
</html>
|