switches.rb 0.12.0 → 0.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60984de78f4a7074bd1f41f4293bcf5c4fb4d837c138bb59f2b7d3519cf17372
4
- data.tar.gz: ed1fd8d58a77fd2335d047dea552326759291b7f985cc027004b0bde774e603b
3
+ metadata.gz: 43cb8cbe7416baef56a0b3da428ad241fcd8b4622d926e6c64e0db0aa311d439
4
+ data.tar.gz: cbd74c3f9d883474c4e207ae1974f9f8271d2fb25865cf606c48794bc1498a61
5
5
  SHA512:
6
- metadata.gz: '080a361c32b9e9db115abe54e677cbd4ceff39d8f895c8a2d4e4819bf27b81393e5f3636550f12b52e547d9aa58398302d29506fe67c0ff9e2215a27f78f6aa9'
7
- data.tar.gz: 4dc836fb4dc0195323b31013af2367657eb1d8ac21cb87a1ec09d0dc7b2d0e6aebe164ae49475a866053765ec5b9047734d64e580076fcf78f75c802107dc569
6
+ metadata.gz: 06ab95f84758ab089a5ce0665ed43e5177b9fd638a0a663ade5ab52c94d587447ccd25fa890c26cd126a44b9da801bbb4aa0d1b647cc3d3423d6095cebdd64e8
7
+ data.tar.gz: bdc919b1bb6d903752337f606c91cd8cde56df35185c5b3b22a54aa5e7ef69bc30ac4553a03de60ff65773f4460bc905e6f5324c8ddf01d0deec0a8a7b55a29c
data/CHANGELOG CHANGED
@@ -2,30 +2,33 @@
2
2
 
3
3
  ## 20260816
4
4
 
5
+ 0.12.1: Move the reasoning out of the CHANGELOG and the header into a ROADMAP.
6
+
7
+ 1. + ROADMAP.md: the design philosophy, a section per shipped version carrying why it went the way it did, the open questions, and the settled items. Not listed in the gemspec, so it does not ship. Follows namo's ROADMAP.md.
8
+ 2. - lib/Switches.rb: the # Todo: and # Ideas: header sections, now in ROADMAP.md, finishing what 0.10.2 began.
9
+ 3. ~ CHANGELOG: the 0.10.5 and 0.11.0 entries carried reasoning, measurement and outstanding work in prose between their numbered items; that is now in ROADMAP.md, and the entries record what changed.
10
+
5
11
  0.12.0: Refuse a switch whose accessor is a method the instance already has, rather than losing it.
6
12
 
7
13
  1. + lib/Switches.rb: Switches#check_switch_names, called first in #do_set and #do_action, which raises where respond_to?(accessor) is true, #method_missing firing only where no method exists.
8
14
  2. + lib/Switches.rb: SwitchNameCollision < ArgumentError.
9
15
  3. ~ README.md: + a Notes entry for the refusal, and for the booleans and OptionParser names it does not cover.
10
16
  4. + spec/all.rb: the refusal through #set and #perform, the message, that nothing reaches the parser first, and the two legal cases.
17
+ 5. + ROADMAP.md, and - the # Todo: and # Ideas: sections from the lib/Switches.rb header, which is where they were. Not listed in the gemspec, so it does not ship.
11
18
 
12
19
  0.11.0: Forward to OptionParser, which #method_missing has never actually done.
13
20
 
14
- 1. ~ lib/Switches.rb: #method_missing tested (@op.methods - Switches.instance_methods).include?(method_name.to_s), which compares a String against an array of Symbols and so was never true. Every call fell through to the settings OpenStruct, which accepts anything, so s.banner = '...' — documented in the README's "With a banner" example — silently became a setting named banner while the parser kept its default of "Usage: <program_name> [options]". The comparison is now made in symbols, and the forwarding works: #banner=, #separator, #program_name= and the other 58 OptionParser methods reach the parser.
15
- 2. ~ lib/Switches.rb: a declared switch takes precedence over an OptionParser method of the same name, + Switches#declared_switch?. Making the forwarding work otherwise shadows any switch sharing a name with the parser, and OptionParser has version, help, release, load, order, top, base, parse, warn, abort and banner among its 61, several of which are switches a program would reasonably want. The rule is that the program's own declarations beat the wrapper's interface, which also leaves any existing program's switches reading as they did.
16
- 3. ~ lib/Switches.rb: + Switches::NEVER_FORWARDED, the names Ruby may call implicitly, which are excluded from the forwarded set. The set has always been built by subtraction — everything the parser responds to, less everything Switches defines — which admits any such name Switches does not happen to define. OptionParser#to_a is `summarize("#{banner}".split(/^/))`, so without the exclusion Array(switches) and [*switches] answer with the parser's help. That was latent for as long as the branch was dead and became reachable the moment it was not, so it is part of this fix rather than a consequence of it. to_h was never at risk, but only because Switches happens to define it; the constant makes the exclusion deliberate rather than incidental.
17
- 4. ~ lib/Switches.rb: + Switches#option_parser_methods, memoised, since the difference was recomputed upon every settings read, and + Switches#option_parser_method?.
18
- 5. + spec/all.rb: forwarding of a writer, of a method taking an argument, and of a reader, each checked through the parser's own help output rather than by reading back what was written; that a declared switch wins over the OptionParser method of the same name, read and written; that a name which is neither still reaches the settings; and that #to_a, Array() and the splat are answered by the switches rather than the parser.
19
- 6. ~ README.md: the Notes entry claiming a Switches instance can't define a method whose name matches an OptionParser method now describes what happens, which is the reverse: the switch wins.
20
-
21
- Not done: #respond_to_missing?, which ordinarily accompanies #method_missing. Note that it would not have prevented the to_a case above — Ruby's conversion check falls back to calling #method_missing directly when the ordinary dispatch fails, so Array() reaches #to_a whatever respond_to? answers. It wants deciding alongside the collision question below, both being about which names the object should own.
22
-
23
- Still outstanding: the converse fault, where #method_missing does not fire at all because the method exists. A switch named after a method Object already has — :tap, :class, :display, :hash, :method, :type — never reaches the settings, and Kernel#tap without a block raises LocalJumpError nowhere near the declaration.
21
+ 1. ~ lib/Switches.rb: #method_missing compared method_name.to_s against @op.methods, an array of Symbols, so the forwarding branch was never true; now compared in symbols.
22
+ 2. ~ lib/Switches.rb: + Switches#declared_switch?, giving a declared switch precedence over the OptionParser method of the same name.
23
+ 3. + lib/Switches.rb: Switches::NEVER_FORWARDED, the names Ruby may call implicitly, excluded from the forwarded set, OptionParser#to_a otherwise answering Array() with the help.
24
+ 4. ~ lib/Switches.rb: + Switches#option_parser_methods, memoised, and + Switches#option_parser_method?.
25
+ 5. + spec/all.rb: the forwarding, the precedence rule, the fall-through, and #to_a.
26
+ 6. ~ README.md: the Notes entry describing forwarding, which had it backwards.
24
27
 
25
28
  0.10.5: Specify and document that a multi-word switch may be supplied hyphenated, and name that form when it is missing.
26
29
 
27
- 1. + spec/all.rb: multi-word switches, in both their underscored and their hyphenated form, for a boolean, an optional argument (#set), a required argument (#set!) and a required switch (#required); that either form counts as supplied for a required switch; and that the setting is named for the symbol declared whichever form was supplied. This behaviour is OptionParser's rather than this library's — a long switch is filed under a lookup key with its underscores turned to hyphens, and whatever is supplied is converted the same way before the lookup, so --update_template and --update-template have always been the one switch. It went untested and undocumented here, which left it resting upon an implementation detail of a library this one only wraps. The specs now pin it, and would fail here rather than in a caller's script were it ever to change.
28
- 2. ~ lib/Switches.rb: the missing-switch message names the hyphenated form, so a switch declared :access_token is reported as --access-token, in place of the --access_token built from the symbol verbatim. Cosmetic, and it says the form to prefer at a command line.
30
+ 1. + spec/all.rb: multi-word switches in both their underscored and their hyphenated form, for a boolean, an optional argument (#set), a required argument (#set!) and a required switch (#required); that either form counts as supplied; and that the setting is named for the symbol declared. The behaviour is OptionParser's, a long switch being filed under a lookup key with its underscores turned to hyphens.
31
+ 2. ~ lib/Switches.rb: the missing-switch message names the hyphenated form, so a switch declared :access_token is reported as --access-token, in place of the --access_token built from the symbol verbatim.
29
32
  3. ~ lib/Switches.rb: + Switches#switch_string, which builds the switch string for an attribute, in place of the identical construction #on_args and #check_required_switches each carried.
30
33
  4. ~ README.md: + a multi-word switch to the Usage section, and + a note recording where the behaviour comes from, that the setting is named for the symbol declared, and that declaring the attribute hyphenated buys nothing and costs the accessor.
31
34
 
@@ -2,5 +2,5 @@
2
2
  # Switches::VERSION
3
3
 
4
4
  class Switches
5
- VERSION = '0.12.0'
5
+ VERSION = '0.12.1'
6
6
  end
data/lib/Switches.rb CHANGED
@@ -3,15 +3,6 @@
3
3
 
4
4
  # Description: Switches provides for a nice wrapper to OptionParser to also act as a store for switches supplied.
5
5
 
6
- # Todo:
7
- # 1. Clean up #set. Done as of 0.4.0.
8
- # 2. Reinstitute some specs. Done as of 0.9.8.
9
-
10
- # Ideas:
11
- # 1. Use ! for options with required switches? Done as of 0.6.0. (Changed to being for required arguments in 0.9.0 however.)
12
- # 2. Do away with optional arguments entirely. Since when does anyone want to specify a non-boolean switch and then supply no arguments anyway?... OK, maybe sometimes, but this is pretty obscure IMO. OK, bad idea. These can be used as action oriented sub-commands.
13
- # 3. Allow for any one of the switches OpenStruct methods to assign values for any of the other associated methods, so as it is more than a read once switch and can be used for storage through out the application; although this might be stepping on Attributes.rb's toes?...
14
-
15
6
  # Dependencies:
16
7
  # 1. Standard Ruby Library.
17
8
  # 2. ostruct, which ceased to be a default gem as of Ruby 4.0 and so is declared in the gemspec.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switches.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran