optiflag 0.6 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ReleaseNotes.txt +35 -0
- data/doc/classes/OptiFlag.html +439 -0
- data/doc/classes/OptiFlag.src/M000001.html +49 -0
- data/doc/classes/OptiFlag.src/M000002.html +49 -0
- data/doc/classes/OptiFlag.src/M000003.html +30 -0
- data/doc/classes/OptiFlag/Flagset.html +459 -0
- data/doc/classes/OptiFlag/Flagset.src/M000003.html +45 -0
- data/doc/classes/OptiFlag/Flagset.src/M000004.html +45 -0
- data/doc/classes/OptiFlag/Flagset.src/M000005.html +18 -0
- data/doc/classes/OptiFlag/Flagset.src/M000006.html +20 -0
- data/doc/classes/OptiFlag/Flagset.src/M000007.html +35 -0
- data/doc/classes/OptiFlag/Flagset.src/M000008.html +23 -0
- data/doc/classes/OptiFlag/Flagset.src/M000009.html +24 -0
- data/doc/classes/OptiFlag/Flagset.src/M000010.html +28 -0
- data/doc/classes/OptiFlag/Flagset.src/M000011.html +20 -0
- data/doc/classes/OptiFlag/Flagset.src/M000012.html +24 -0
- data/doc/classes/OptiFlag/Flagset.src/M000013.html +24 -0
- data/doc/classes/OptiFlag/Flagset.src/M000014.html +32 -0
- data/doc/classes/OptiFlag/Flagset.src/M000015.html +25 -0
- data/doc/classes/OptiFlag/Flagset.src/M000016.html +53 -0
- data/doc/classes/OptiFlag/Flagset.src/M000017.html +53 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.html +930 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000024.html +36 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000025.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000026.html +36 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000027.html +36 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000028.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000029.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000030.html +19 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000031.html +19 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000032.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000033.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000034.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000035.html +22 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000036.html +19 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000037.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000038.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000039.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000040.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000041.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000042.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000043.html +19 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000044.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000045.html +19 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000046.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000047.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000048.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000049.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000050.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000051.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000052.html +20 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000053.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000054.html +18 -0
- data/doc/classes/OptiFlag/Flagset/EachFlag.src/M000055.html +22 -0
- data/doc/classes/OptiFlag/Flagset/Errors.html +192 -0
- data/doc/classes/OptiFlag/Flagset/Errors.src/M000021.html +18 -0
- data/doc/classes/OptiFlag/Flagset/Errors.src/M000022.html +19 -0
- data/doc/classes/OptiFlag/Flagset/Errors.src/M000023.html +18 -0
- data/doc/classes/OptiFlag/Flagset/Errors.src/M000024.html +18 -0
- data/doc/classes/OptiFlag/Flagset/Errors.src/M000025.html +19 -0
- data/doc/classes/OptiFlag/Flagset/Errors.src/M000026.html +36 -0
- data/doc/classes/OptiFlag/Flagset/Help.html +125 -0
- data/doc/classes/OptiFlag/Flagset/Help/Bundle.html +160 -0
- data/doc/classes/OptiFlag/Flagset/Help/Bundle.src/M000018.html +18 -0
- data/doc/classes/OptiFlag/Flagset/Help/Bundle.src/M000019.html +18 -0
- data/doc/classes/OptiFlag/Flagset/Help/StandardHelpBundle.html +118 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.html +296 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000017.html +18 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000018.html +18 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000019.html +18 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000020.html +18 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000021.html +18 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000022.html +18 -0
- data/doc/classes/OptiFlag/Flagset/NewInterface.src/M000023.html +18 -0
- data/doc/created.rid +1 -0
- data/doc/files/optiflag-help_rb.html +101 -0
- data/doc/files/optiflag-parse_rb.html +101 -0
- data/doc/files/optiflag_rb.html +167 -0
- data/doc/files/optiflag_rb.src/M000001.html +18 -0
- data/doc/fr_class_index.html +34 -0
- data/doc/fr_file_index.html +29 -0
- data/doc/fr_method_index.html +82 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/examples/example_1.rb +21 -0
- data/examples/example_1_1.rb +21 -0
- data/{doc/example → examples}/example_1_2.rb +8 -8
- data/examples/example_2.rb +31 -0
- data/{doc/example → examples}/example_2_1.rb +4 -4
- data/{doc/example → examples}/example_2_2.rb +7 -5
- data/{doc/example → examples}/example_2_3.rb +9 -9
- data/{doc/example → examples}/example_2_4.rb +4 -4
- data/{doc/example → examples}/example_2_5.rb +4 -4
- data/{doc/example → examples}/example_2_6.rb +6 -6
- data/{doc/example → examples}/example_3.rb +7 -6
- data/examples/example_6.rb +20 -0
- data/{doc/example → examples}/example_7.rb +5 -4
- data/examples/example_8.rb +26 -0
- data/optiflag-help.rb +42 -0
- data/optiflag-parse.rb +281 -0
- data/optiflag.gemspec +4 -3
- data/optiflag.rb +972 -0
- data/quick.rb +12 -0
- data/{test → testcases}/tc_advanced_usage_helping.rb +4 -0
- data/{test → testcases}/tc_basic_alternate_forms.rb +0 -0
- data/{test → testcases}/tc_basic_char_flags.rb +12 -12
- data/{test → testcases}/tc_basic_optional_flag.rb +0 -0
- data/{test → testcases}/tc_basic_parsing.rb +0 -0
- data/{test → testcases}/tc_basic_usage_helping.rb +0 -0
- data/{test → testcases}/tc_basic_value_validation.rb +0 -0
- data/{test → testcases}/tc_bug_one.rb +0 -0
- data/{test → testcases}/tc_bug_two.rb +0 -0
- data/{test → testcases}/tc_change_symbols.rb +0 -0
- data/{test → testcases}/tc_enumerated_value_validation.rb +0 -0
- data/{test → testcases}/tc_flagall.rb +4 -0
- data/{test → testcases}/tc_flagless_arg.rb +0 -0
- data/{test → testcases}/tc_keyword.rb +0 -0
- data/testcases/tc_new_basic_parsing.rb +51 -0
- data/testcases/tc_poro_tester.rb +30 -0
- data/{test → testcases}/tc_values_as_hash.rb +0 -0
- metadata +152 -52
- data/doc/example/example_1.rb +0 -30
- data/doc/example/example_1_1.rb +0 -27
- data/doc/example/example_2.rb +0 -28
- data/doc/example/example_4.rb +0 -12
- data/doc/example/example_5.rb +0 -26
- data/doc/example/example_6.rb +0 -17
- data/lib/optiflag.rb +0 -860
data/ReleaseNotes.txt
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
---------------------------------------------------------------------------------
|
2
|
+
RELEASE 0.6.5 (Reuse PORO (Plain Old Ruby Object))
|
3
|
+
---------------------------------------------------------------------------------
|
4
|
+
* added module convenience funtionality Optiflag.using_object()
|
5
|
+
-- made sure that this will travel up the inheritance
|
6
|
+
hierarchy up to but not including Object looking for
|
7
|
+
getter/setter pairs
|
8
|
+
* added alias :and_process! for :handle_errors_and_help (which is unweildy)
|
9
|
+
* started significant RDoc-ing of modules, classes and methods
|
10
|
+
* created alias :flags for :flag_value
|
11
|
+
(ARGV.flags.d is easier than ARGV.flag_value.d)
|
12
|
+
* re-arranged directory structure and created darcs repository
|
13
|
+
* read darcs repository now available at
|
14
|
+
http://daniel-eklund.com/repos/optiflag
|
15
|
+
* added a new convenience Constant called OptiFlagSet which makes
|
16
|
+
the standard rote extension a bit easier
|
17
|
+
* refactored the help bundle system
|
18
|
+
* changed the look and feel for the help messages
|
19
|
+
* changed the parse() function so that the module constant also now
|
20
|
+
has the flag values augmented onto the object
|
21
|
+
module MyArgs extend OptiFlagSet
|
22
|
+
...
|
23
|
+
end
|
24
|
+
MyArgs.flags.dir?
|
25
|
+
* broke out a lot of functionality into separate files to make
|
26
|
+
maintenance a bit easier.. (first time optiflag.rb is no longer
|
27
|
+
the only source file)
|
28
|
+
* refactored the validation functionality to create a generic
|
29
|
+
'validate_against' methods which takes a lambda. Old validation
|
30
|
+
methods value_in_set and value_matching use this method
|
31
|
+
* fixed a subtle bug with the help usage_flag not picking up
|
32
|
+
individual help when it was an alternate form and usage_flag
|
33
|
+
is called more than once
|
34
|
+
|
35
|
+
|
1
36
|
---------------------------------------------------------------------------------
|
2
37
|
RELEASE 0.6 (Character Flags FINALLY)
|
3
38
|
---------------------------------------------------------------------------------
|
@@ -0,0 +1,439 @@
|
|
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: OptiFlag</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">OptiFlag</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/optiflag-help_rb.html">
|
59
|
+
optiflag-help.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/optiflag-parse_rb.html">
|
63
|
+
optiflag-parse.rb
|
64
|
+
</a>
|
65
|
+
<br />
|
66
|
+
<a href="../files/optiflag_rb.html">
|
67
|
+
optiflag.rb
|
68
|
+
</a>
|
69
|
+
<br />
|
70
|
+
</td>
|
71
|
+
</tr>
|
72
|
+
|
73
|
+
</table>
|
74
|
+
</div>
|
75
|
+
<!-- banner header -->
|
76
|
+
|
77
|
+
<div id="bodyContent">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<div id="contextContent">
|
82
|
+
|
83
|
+
<div id="description">
|
84
|
+
<p>
|
85
|
+
<a href="OptiFlag.html">OptiFlag</a> is the module that provides
|
86
|
+
namespacing for the entire optiflag functionality. For usage and examples,
|
87
|
+
see <a href="http://optiflag.rubyforge.org">optiflag.rubyforge.org</a>
|
88
|
+
</p>
|
89
|
+
<h1>Terminology</h1>
|
90
|
+
<p>
|
91
|
+
Please treat the following terminology as specific only to the <a
|
92
|
+
href="OptiFlag.html">OptiFlag</a> code suite. In the remaining RDoc, we
|
93
|
+
shall try to emphasize this consistent terminology with italics. If you see
|
94
|
+
an italicized phrase, chances are that it is defined here.
|
95
|
+
</p>
|
96
|
+
<h2>Flag Set Declaration</h2>
|
97
|
+
<p>
|
98
|
+
A <em>flag set declaration</em> is a set of flag declarations created by
|
99
|
+
the user of the <a href="OptiFlag.html">OptiFlag</a> suite and corresponds
|
100
|
+
to the following code snippet:
|
101
|
+
</p>
|
102
|
+
<pre>
|
103
|
+
module AppArgs extend OptiFlagSet
|
104
|
+
# individual flag declaration goes here ...
|
105
|
+
# ... and here
|
106
|
+
end
|
107
|
+
</pre>
|
108
|
+
<p>
|
109
|
+
In this case, the module <b>AppArgs</b> is a <em>flag set declaration</em>,
|
110
|
+
and all code within the module definition (i.e. up to the end of <b>end</b>
|
111
|
+
of the module) is either a <em>flag declaration</em> or a special command.
|
112
|
+
</p>
|
113
|
+
<p>
|
114
|
+
Another way to treat this declaration is as a demarcation between the
|
115
|
+
normal Ruby world and the mini-DSL (Domain Specific Language) that <a
|
116
|
+
href="OptiFlag.html">OptiFlag</a> offers. In this view, the declaration
|
117
|
+
provides a DSL-zone in which the DSL is allowed.
|
118
|
+
</p>
|
119
|
+
<pre>
|
120
|
+
module AppArgs extend OptiFlagSet
|
121
|
+
# DSL-zone
|
122
|
+
# DSL-zone (for declaring and modifying flags)
|
123
|
+
# DSL-zone
|
124
|
+
end
|
125
|
+
</pre>
|
126
|
+
<p>
|
127
|
+
the first line
|
128
|
+
</p>
|
129
|
+
<pre>
|
130
|
+
module AppArgs extend OptiFlagSet
|
131
|
+
</pre>
|
132
|
+
<p>
|
133
|
+
is really just rote.
|
134
|
+
</p>
|
135
|
+
<p>
|
136
|
+
Supply your own module argument name and make sure it extends this <a
|
137
|
+
href="OptiFlag/Flagset.html">OptiFlag::Flagset</a> as is written. You will
|
138
|
+
then have a scoped space to write in a command line DSL.
|
139
|
+
</p>
|
140
|
+
<h2>Flag Declaration</h2>
|
141
|
+
<p>
|
142
|
+
A <em>flag declaration</em> is placed within a <em>flag set
|
143
|
+
declaration</em> to indicate that one input parameter per declaration is
|
144
|
+
requested from the command line. A <em>flag declaration</em> is the
|
145
|
+
mini-DSL‘s main programming construct. In the following code, four
|
146
|
+
<em>flag declarations</em> are placed within the overall <em>flag
|
147
|
+
<b>set</b> declaration</em> named AppArgs:
|
148
|
+
</p>
|
149
|
+
<pre>
|
150
|
+
module AppArgs extend OptiFlagSet
|
151
|
+
flag "dir"
|
152
|
+
flag "log"
|
153
|
+
flag "username"
|
154
|
+
flag "password"
|
155
|
+
end
|
156
|
+
</pre>
|
157
|
+
<p>
|
158
|
+
Please note that there are other <em>flag set declaration</em> nouns other
|
159
|
+
than flag. For instance in the following snippet:
|
160
|
+
</p>
|
161
|
+
<pre>
|
162
|
+
module Example extend OptiFlagSet
|
163
|
+
flag "dir" do
|
164
|
+
alternate_forms "directory","D","d"
|
165
|
+
description "The Appliction Directory"
|
166
|
+
end
|
167
|
+
optional_flag "log" do
|
168
|
+
description "The directory in which to find the log files"
|
169
|
+
long_form "logging-directory" # long form is keyed after the '--' symbol
|
170
|
+
end
|
171
|
+
flag "username", :description => "Database username." # alternate form
|
172
|
+
flag "password" do
|
173
|
+
description "Database password."
|
174
|
+
end
|
175
|
+
usage_flag "h","help","?"
|
176
|
+
extended_help_flag "superhelp"
|
177
|
+
|
178
|
+
and_process!
|
179
|
+
end
|
180
|
+
</pre>
|
181
|
+
<p>
|
182
|
+
there are six <em>flag declarations</em> in total:
|
183
|
+
</p>
|
184
|
+
<ul>
|
185
|
+
<li>a flag named "dir"
|
186
|
+
|
187
|
+
</li>
|
188
|
+
<li>an optional flag named "log"
|
189
|
+
|
190
|
+
</li>
|
191
|
+
<li>a flag named "username"
|
192
|
+
|
193
|
+
</li>
|
194
|
+
<li>a flag named "password"
|
195
|
+
|
196
|
+
</li>
|
197
|
+
<li>a usage flag for summoning help on how to use the flags
|
198
|
+
|
199
|
+
</li>
|
200
|
+
<li>an extended help flag for summoning detailed usage for the flags
|
201
|
+
|
202
|
+
</li>
|
203
|
+
</ul>
|
204
|
+
<p>
|
205
|
+
Everything else is either a <em>clause level modifier</em> (e.g.
|
206
|
+
alternate_forms, description, etc.) or a <em>special command</em>.
|
207
|
+
</p>
|
208
|
+
<p>
|
209
|
+
<b>For a list of all <em>flag set declarations</em> and how to use them,
|
210
|
+
see the RDoc for the <a href="OptiFlag/Flagset.html">OptiFlag::Flagset</a>
|
211
|
+
module.</b>
|
212
|
+
</p>
|
213
|
+
<h2>Clause Level Modifier</h2>
|
214
|
+
<p>
|
215
|
+
As seen above, a <em>clause level modifier</em> is a word used to modify
|
216
|
+
the basic flag, usually within a nested do block. It it this nesting which
|
217
|
+
has inspired the use of the word clause. For instance:
|
218
|
+
</p>
|
219
|
+
<pre>
|
220
|
+
module Example extend OptiFlagSet
|
221
|
+
flag "dir" do
|
222
|
+
alternate_forms "directory","D","d"
|
223
|
+
description "The Appliction Directory"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
</pre>
|
227
|
+
<p>
|
228
|
+
We could read this as a sentence: ‘Create a flag "dir"
|
229
|
+
which has three alternate forms "directory", "D", and
|
230
|
+
"d" and which has a description that reads "The Application
|
231
|
+
Directory’.
|
232
|
+
</p>
|
233
|
+
<p>
|
234
|
+
For the most part, these <em>clause level modifiers</em> are nested within
|
235
|
+
a do-block, though <a href="OptiFlag.html">OptiFlag</a> allows us to
|
236
|
+
conserve vertical space by using symbol hashes. (It is recommended that one
|
237
|
+
only uses these in simple cases). For instance, the following two <em>flag
|
238
|
+
set declarations</em> are equivalent:
|
239
|
+
</p>
|
240
|
+
<pre>
|
241
|
+
module Example extend OptiFlagSet
|
242
|
+
flag "username", :description => "Database username." # alternate form
|
243
|
+
|
244
|
+
and_process!
|
245
|
+
end
|
246
|
+
</pre>
|
247
|
+
<p>
|
248
|
+
and
|
249
|
+
</p>
|
250
|
+
<pre>
|
251
|
+
module Example extend OptiFlagSet
|
252
|
+
flag "username" do
|
253
|
+
description "Database username."
|
254
|
+
end
|
255
|
+
|
256
|
+
and_process!
|
257
|
+
end
|
258
|
+
</pre>
|
259
|
+
<p>
|
260
|
+
with the first being a syntactically friendly hash of the <em>clause level
|
261
|
+
modifier</em> as a symbol pointing to the value of the modification.
|
262
|
+
</p>
|
263
|
+
<p>
|
264
|
+
For a complete list of <em>clause level modifiers</em> see the RDoc for <a
|
265
|
+
href="OptiFlag/Flagset/EachFlag.html">OptiFlag::Flagset::EachFlag</a>
|
266
|
+
</p>
|
267
|
+
|
268
|
+
</div>
|
269
|
+
|
270
|
+
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<div id="method-list">
|
274
|
+
<h3 class="section-bar">Methods</h3>
|
275
|
+
|
276
|
+
<div class="name-list">
|
277
|
+
<a href="#M000003">Flagset</a>
|
278
|
+
<a href="#M000002">using_object</a>
|
279
|
+
</div>
|
280
|
+
</div>
|
281
|
+
|
282
|
+
</div>
|
283
|
+
|
284
|
+
|
285
|
+
<!-- if includes -->
|
286
|
+
|
287
|
+
<div id="section">
|
288
|
+
|
289
|
+
<div id="class-list">
|
290
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
291
|
+
|
292
|
+
Module <a href="OptiFlag/Flagset.html" class="link">OptiFlag::Flagset</a><br />
|
293
|
+
|
294
|
+
</div>
|
295
|
+
|
296
|
+
<div id="constants-list">
|
297
|
+
<h3 class="section-bar">Constants</h3>
|
298
|
+
|
299
|
+
<div class="name-list">
|
300
|
+
<table summary="Constants">
|
301
|
+
<tr class="top-aligned-row context-row">
|
302
|
+
<td class="context-item-name">VERSION</td>
|
303
|
+
<td>=</td>
|
304
|
+
<td class="context-item-value">"0.7"</td>
|
305
|
+
</tr>
|
306
|
+
</table>
|
307
|
+
</div>
|
308
|
+
</div>
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
<!-- if method_list -->
|
316
|
+
<div id="methods">
|
317
|
+
<h3 class="section-bar">Public Class methods</h3>
|
318
|
+
|
319
|
+
<div id="method-M000003" class="method-detail">
|
320
|
+
<a name="M000003"></a>
|
321
|
+
|
322
|
+
<div class="method-heading">
|
323
|
+
<a href="OptiFlag.src/M000003.html" target="Code" class="method-signature"
|
324
|
+
onclick="popupCode('OptiFlag.src/M000003.html');return false;">
|
325
|
+
<span class="method-name">Flagset</span><span class="method-args">(hash)</span>
|
326
|
+
</a>
|
327
|
+
</div>
|
328
|
+
|
329
|
+
<div class="method-description">
|
330
|
+
<p>
|
331
|
+
This is a method that looks like a module. It is an excellent example of
|
332
|
+
the syntactic tricks that ruby permits us. This method allows us to provide
|
333
|
+
code like the following:
|
334
|
+
</p>
|
335
|
+
<pre>
|
336
|
+
module Example extend OptiFlagSet(:flag_symbol => "/")
|
337
|
+
flag "dir"
|
338
|
+
flag "log"
|
339
|
+
flag "username"
|
340
|
+
flag "password"
|
341
|
+
|
342
|
+
and_process!
|
343
|
+
end
|
344
|
+
</pre>
|
345
|
+
<p>
|
346
|
+
You will note that the top line looks a lot like the standard top line
|
347
|
+
</p>
|
348
|
+
<pre>
|
349
|
+
# our top line
|
350
|
+
module Example extend OptiFlagSet(:flag_symbol => "/")
|
351
|
+
</pre>
|
352
|
+
<p>
|
353
|
+
versus
|
354
|
+
</p>
|
355
|
+
<pre>
|
356
|
+
# standard top line
|
357
|
+
module Example extend OptiFlagSet
|
358
|
+
</pre>
|
359
|
+
<p>
|
360
|
+
The difference is that while the latter (a standard top line) is a
|
361
|
+
reference to a module, the former is a call to this method, that
|
362
|
+
<b>returns</b> the <a href="OptiFlag/Flagset.html">OptiFlag::Flagset</a>
|
363
|
+
module with some defaults changed.
|
364
|
+
</p>
|
365
|
+
<p>
|
366
|
+
As of now the only symbol/method supported by this method that looks like a
|
367
|
+
module, is the ‘<a
|
368
|
+
href="OptiFlag/Flagset.html#M000005">OptiFlag::Flagset.flag_symbol</a>’
|
369
|
+
class method.
|
370
|
+
</p>
|
371
|
+
<p>
|
372
|
+
For those still not understanding the syntactic trick, or who find it odd,
|
373
|
+
consider that something similar to this is done in the ruby core language
|
374
|
+
using the proxy/delegate pattern. (See delegate.rb in the Ruby core
|
375
|
+
library)
|
376
|
+
</p>
|
377
|
+
<pre>
|
378
|
+
class Tempfile < DelegateClass(File)
|
379
|
+
# ...
|
380
|
+
# ...
|
381
|
+
end
|
382
|
+
</pre>
|
383
|
+
<p>
|
384
|
+
You will note that the DelegateClass() is also a method that superficially
|
385
|
+
resembles a class that parameterizes itself. This can be done because Ruby
|
386
|
+
expects:
|
387
|
+
</p>
|
388
|
+
<pre>
|
389
|
+
class <identifier> < <expression>
|
390
|
+
</pre>
|
391
|
+
<p>
|
392
|
+
and not
|
393
|
+
</p>
|
394
|
+
<pre>
|
395
|
+
class <identifier> < <identifier>
|
396
|
+
</pre>
|
397
|
+
<p>
|
398
|
+
like some other languages. And likewise
|
399
|
+
</p>
|
400
|
+
<pre>
|
401
|
+
module <identifier> extend <expression>
|
402
|
+
</pre>
|
403
|
+
<p>
|
404
|
+
which allows us to create this method which has the exact same name as the
|
405
|
+
module. Clever ruby.
|
406
|
+
</p>
|
407
|
+
</div>
|
408
|
+
</div>
|
409
|
+
|
410
|
+
<div id="method-M000002" class="method-detail">
|
411
|
+
<a name="M000002"></a>
|
412
|
+
|
413
|
+
<div class="method-heading">
|
414
|
+
<a href="OptiFlag.src/M000002.html" target="Code" class="method-signature"
|
415
|
+
onclick="popupCode('OptiFlag.src/M000002.html');return false;">
|
416
|
+
<span class="method-name">using_object</span><span class="method-args">(a_single_object,&the_block)</span>
|
417
|
+
</a>
|
418
|
+
</div>
|
419
|
+
|
420
|
+
<div class="method-description">
|
421
|
+
<p>
|
422
|
+
Special command (at the same level as a <em>flag declaration</em>)
|
423
|
+
</p>
|
424
|
+
</div>
|
425
|
+
</div>
|
426
|
+
|
427
|
+
|
428
|
+
</div>
|
429
|
+
|
430
|
+
|
431
|
+
</div>
|
432
|
+
|
433
|
+
|
434
|
+
<div id="validator-badges">
|
435
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
436
|
+
</div>
|
437
|
+
|
438
|
+
</body>
|
439
|
+
</html>
|