switches.rb 0.10.0 → 0.10.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: 30d6b5c6bbad8c0a585b418ff83ad25394c9de5cbe1a37089484d8c5ca16ad2a
4
- data.tar.gz: a5a3bda6bf97e2c8355c12e8113947a94523abe9f9e8d344f81fa3f6e4947d6f
3
+ metadata.gz: 8e900150793418981ab52b35828a2fc696a5e7b826d4eba77047d96cc7532dfe
4
+ data.tar.gz: f4e598c29f7dbaf2c61b8e685151732afba5770b94085cbe06a413f85151b692
5
5
  SHA512:
6
- metadata.gz: fdb9781dc62a69ec53edb7e2d95ed7f83edc62079512e632af30a49a258831e1b35be02d8e81b74372664cf99d1e724f5f7b3747946dbdd76e5014bd863fae47
7
- data.tar.gz: 5e7bca50700640d86c65c65355ffefa83480641fc7492141046f83d923403b0ac82efcb9da347db19ae0ea2a89ef36d44d195251341fc2ef688561b18f3e15d9
6
+ metadata.gz: fe23cc64afe81e073164650ef50b64ae208cfc57cc82a9e6e57efc4925f8cd87853b0b5726f2dea6cbe528cf9348fc1499e9e5fe6febf2e9f4348eb96a1b2e9e
7
+ data.tar.gz: 4ab5f810b80fc2716684aaa46481a2e83db7bf628a6a81bdfe25c4f1ed588eaf3fb090fd011e92df3592ec93962e2915b2ec3f0821c4d93081f04624e207a7cc
data/CHANGELOG CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## 20260809
4
4
 
5
+ 0.10.1: Get the specs running again, under rspec 3 and rake.
6
+
7
+ 1. ~ spec/all.rb: rspec 3 syntax throughout, in place of the pre-rspec-3 #should ==, so the specs run at all.
8
+ 2. ~ spec/all.rb: the six raise expectations were written as switches.should{raise MissingArgument}, which asserts nothing and names a constant which doesn't exist; they now expect OptionParser::MissingArgument and RequiredSwitchMissing for real.
9
+ 3. ~ spec/all.rb: + specs for #perform and #perform!, which had been left pending, and - the Array#empty! alias, since ARGV.clear says it without patching Array.
10
+ 4. + Rakefile: an rspec task pointed at spec/all.rb, since the specs live in the one file rather than under the default spec/**/*_spec.rb, + a version task, and spec as the default task.
11
+ 5. ~ Gemfile: use gemspec rather than restate rspec, and + ostruct, which the bundle must provide for require_gem to find under Ruby 4.0.
12
+ 6. ~ switches.rb.gemspec: + rake as a development dependency and + Rakefile to the file list.
13
+
5
14
  0.10.0: Restore loading and building under Ruby 4.0, and bring the repo up to standard.
6
15
 
7
16
  1. ~ lib/Switches.rb: require ostruct through a vendored require_gem (+ lib/Kernel/require_gem.rb, + lib/Thoran/Kernel/RequireGem/require_gem.rb), so it no longer needs ostruct to be a default gem — which it stopped being as of Ruby 4.0 — nor require_gem to be found on RUBYLIB.
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rspec'
3
+ gemspec
4
+
5
+ # ostruct is no longer a default gem as of Ruby 4.0, so it must be provided
6
+ # explicitly under bundler.
7
+ gem 'ostruct'
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # Rakefile
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = 'spec/all.rb'
7
+ end
8
+
9
+ task default: :spec
10
+
11
+ desc "Show version"
12
+ task :version do
13
+ puts "switches.rb #{Gem::Specification.load('switches.rb.gemspec').version}"
14
+ end
data/lib/Switches.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Switches
3
3
 
4
4
  # 20260809
5
- # 0.10.0
5
+ # 0.10.1
6
6
 
7
7
  # Description: Switches provides for a nice wrapper to OptionParser to also act as a store for switches supplied.
8
8
 
data/spec/all.rb CHANGED
@@ -1,25 +1,17 @@
1
- require "#{File.dirname(__FILE__)}/../lib/Switches"
1
+ # spec/all.rb
2
2
 
3
- class Array
4
-
5
- alias_method :empty!, :clear
6
-
7
- end
3
+ require_relative '../lib/Switches'
8
4
 
9
5
  describe Switches do
10
-
11
6
  describe ".new" do
12
-
13
- it "should return an object of class Switches" do
14
- Switches.new.class.should == Switches
7
+ it "returns an object of class Switches" do
8
+ expect(Switches.new.class).to eq(Switches)
15
9
  end
16
-
17
10
  end
18
-
11
+
19
12
  describe "#set" do
20
-
21
- def setup(switches_string = '')
22
- ARGV.empty!
13
+ def build(switches_string = '')
14
+ ARGV.clear
23
15
  switches_string.split.each{|a| ARGV << a}
24
16
  Switches.new do |s|
25
17
  s.set :v?, :verbose?
@@ -27,196 +19,208 @@ describe Switches do
27
19
  s.set :host, :h
28
20
  end
29
21
  end
30
-
31
- it "should set a short boolean switch or flag to true when supplied with a short switch" do
32
- setup('-v').v?.should == true
22
+
23
+ it "sets a short boolean switch to true when supplied with a short switch" do
24
+ expect(build('-v').v?).to eq(true)
33
25
  end
34
-
35
- it "should set a long boolean switch value to true when supplied with a short switch" do
36
- setup('-v').verbose?.should == true
26
+
27
+ it "sets a long boolean switch to true when supplied with a short switch" do
28
+ expect(build('-v').verbose?).to eq(true)
37
29
  end
38
-
39
- it "should set a short boolean switch or flag to true when supplied with a long switch" do
40
- setup('--verbose').v?.should == true
30
+
31
+ it "sets a short boolean switch to true when supplied with a long switch" do
32
+ expect(build('--verbose').v?).to eq(true)
41
33
  end
42
-
43
- it "should set a long boolean switch or flag to true when supplied with a long switch" do
44
- setup('--verbose').verbose?.should == true
34
+
35
+ it "sets a long boolean switch to true when supplied with a long switch" do
36
+ expect(build('--verbose').verbose?).to eq(true)
45
37
  end
46
-
47
- it "should set a short switch value to the value supplied when supplied with a short switch" do
48
- setup('-p 22').p.should == '22'
38
+
39
+ it "sets a short switch to the value supplied when supplied with a short switch" do
40
+ expect(build('-p 22').p).to eq('22')
49
41
  end
50
-
51
- it "should set a long switch value to the value supplied when supplied with a short switch" do
52
- setup('-p 22').port.should == '22'
42
+
43
+ it "sets a long switch to the value supplied when supplied with a short switch" do
44
+ expect(build('-p 22').port).to eq('22')
53
45
  end
54
-
55
- it "should set a short switch value to the value supplied when supplied with a long switch" do
56
- setup('--port 22').p.should == '22'
46
+
47
+ it "sets a short switch to the value supplied when supplied with a long switch" do
48
+ expect(build('--port 22').p).to eq('22')
57
49
  end
58
-
59
- it "should set a long switch value to the value supplied when supplied with a long switch" do
60
- setup('--port 22').port.should == '22'
50
+
51
+ it "sets a long switch to the value supplied when supplied with a long switch" do
52
+ expect(build('--port 22').port).to eq('22')
61
53
  end
62
-
63
- it "shouldn't matter in which order the short and long switches are given" do
64
- setup('-h example.com').h.should == 'example.com'
65
- setup('--host example.com').h.should == 'example.com'
54
+
55
+ it "doesn't matter in which order the short and long switches are given" do
56
+ expect(build('-h example.com').h).to eq('example.com')
57
+ expect(build('--host example.com').h).to eq('example.com')
66
58
  end
67
-
68
- end # describe "#set"
69
-
59
+ end
60
+
70
61
  describe "#set!" do
71
-
72
- def setup(switches_string = '')
73
- ARGV.empty!
62
+ def build(switches_string = '')
63
+ ARGV.clear
74
64
  switches_string.split.each{|a| ARGV << a}
75
65
  Switches.new do |s|
76
66
  s.set! :p, :port
77
67
  end
78
68
  end
79
-
80
- it "should set a short switch value to the argument supplied with a short switch" do
81
- setup('-p 22').p.should == '22'
69
+
70
+ it "sets a short switch to the argument supplied with a short switch" do
71
+ expect(build('-p 22').p).to eq('22')
82
72
  end
83
-
84
- it "should set a long switch value to the argument supplied with a short switch" do
85
- setup('-p 22').port.should == '22'
73
+
74
+ it "sets a long switch to the argument supplied with a short switch" do
75
+ expect(build('-p 22').port).to eq('22')
86
76
  end
87
-
88
- it "should set a short switch value to the argument supplied with a long switch" do
89
- setup('--port 22').p.should == '22'
77
+
78
+ it "sets a short switch to the argument supplied with a long switch" do
79
+ expect(build('--port 22').p).to eq('22')
90
80
  end
91
-
92
- it "should set a long switch value to the argument supplied with a long switch" do
93
- setup('--port 22').port.should == '22'
81
+
82
+ it "sets a long switch to the argument supplied with a long switch" do
83
+ expect(build('--port 22').port).to eq('22')
94
84
  end
95
-
96
- it "should raise a MissingArgument error when no argument is supplied to a short switch" do
97
- switches = lambda{setup('-p')}
98
- switches.should{raise MissingArgument}
85
+
86
+ it "raises OptionParser::MissingArgument when no argument is supplied to a short switch" do
87
+ expect{build('-p')}.to raise_error(OptionParser::MissingArgument)
99
88
  end
100
-
101
- it "should raise a MissingArgument error when no argument is supplied to a long switch" do
102
- switches = lambda{setup('--port')}
103
- switches.should{raise MissingArgument}
89
+
90
+ it "raises OptionParser::MissingArgument when no argument is supplied to a long switch" do
91
+ expect{build('--port')}.to raise_error(OptionParser::MissingArgument)
104
92
  end
105
-
106
- end # describe "#set!"
107
-
93
+ end
94
+
108
95
  describe "#required" do
109
-
110
- def setup(switches_string = '')
111
- ARGV.empty!
96
+ def build(switches_string = '')
97
+ ARGV.clear
112
98
  switches_string.split.each{|a| ARGV << a}
113
99
  Switches.new do |s|
114
100
  s.required :p, :port
115
101
  end
116
102
  end
117
-
118
- it "should set a short switch value to the argument supplied with a short switch" do
119
- setup('-p 22').p.should == '22'
103
+
104
+ it "sets a short switch to the argument supplied with a short switch" do
105
+ expect(build('-p 22').p).to eq('22')
120
106
  end
121
-
122
- it "should set a long switch value to the argument supplied with a short switch" do
123
- setup('-p 22').port.should == '22'
107
+
108
+ it "sets a long switch to the argument supplied with a short switch" do
109
+ expect(build('-p 22').port).to eq('22')
124
110
  end
125
-
126
- it "should set a short switch value to the argument supplied with a long switch" do
127
- setup('--port 22').p.should == '22'
111
+
112
+ it "sets a short switch to the argument supplied with a long switch" do
113
+ expect(build('--port 22').p).to eq('22')
128
114
  end
129
-
130
- it "should set a long switch value to the argument supplied with a long switch" do
131
- setup('--port 22').port.should == '22'
115
+
116
+ it "sets a long switch to the argument supplied with a long switch" do
117
+ expect(build('--port 22').port).to eq('22')
118
+ end
119
+
120
+ it "raises RequiredSwitchMissing when no switch is supplied" do
121
+ expect{build}.to raise_error(RequiredSwitchMissing)
132
122
  end
133
-
134
- it "should raise a RequiredSwitchMissing error no switch is supplied" do
135
- switches = lambda{setup}
136
- switches.should{raise RequiredSwitchMissing}
123
+
124
+ it "names every missing switch in the RequiredSwitchMissing message" do
125
+ expect{build}.to raise_error(RequiredSwitchMissing, /-p.*--port/m)
137
126
  end
138
-
139
- end # describe "#required"
140
-
127
+ end
128
+
141
129
  describe "#required!" do
142
-
143
- def setup(switches_string = '')
144
- ARGV.empty!
130
+ def build(switches_string = '')
131
+ ARGV.clear
145
132
  switches_string.split.each{|a| ARGV << a}
146
133
  Switches.new do |s|
147
134
  s.required! :p, :port
148
135
  end
149
136
  end
150
-
151
- it "should set a short switch value to the argument supplied with a short switch" do
152
- setup('-p 22').p.should == '22'
137
+
138
+ it "sets a short switch to the argument supplied with a short switch" do
139
+ expect(build('-p 22').p).to eq('22')
153
140
  end
154
-
155
- it "should set a long switch value to the argument supplied with a short switch" do
156
- setup('-p 22').port.should == '22'
141
+
142
+ it "sets a long switch to the argument supplied with a short switch" do
143
+ expect(build('-p 22').port).to eq('22')
157
144
  end
158
-
159
- it "should set a short switch value to the argument supplied with a long switch" do
160
- setup('--port 22').p.should == '22'
145
+
146
+ it "sets a short switch to the argument supplied with a long switch" do
147
+ expect(build('--port 22').p).to eq('22')
161
148
  end
162
-
163
- it "should set a long switch value to the argument supplied with a long switch" do
164
- setup('--port 22').port.should == '22'
149
+
150
+ it "sets a long switch to the argument supplied with a long switch" do
151
+ expect(build('--port 22').port).to eq('22')
165
152
  end
166
-
167
- it "should raise a MissingArgument error when no argument is supplied to a short switch" do
168
- switches = lambda{setup('-p')}
169
- switches.should{raise MissingArgument}
153
+
154
+ it "raises OptionParser::MissingArgument when no argument is supplied to a short switch" do
155
+ expect{build('-p')}.to raise_error(OptionParser::MissingArgument)
170
156
  end
171
-
172
- it "should raise a MissingArgument error when no argument is supplied to a long switch" do
173
- switches = lambda{setup('-p')}
174
- switches.should{raise MissingArgument}
157
+
158
+ it "raises OptionParser::MissingArgument when no argument is supplied to a long switch" do
159
+ expect{build('--port')}.to raise_error(OptionParser::MissingArgument)
175
160
  end
176
-
177
- it "should raise a RequiredSwitchMissing error no switch is supplied" do
178
- switches = lambda{setup}
179
- switches.should{raise RequiredSwitchMissing}
161
+
162
+ it "raises RequiredSwitchMissing when no switch is supplied" do
163
+ expect{build}.to raise_error(RequiredSwitchMissing)
180
164
  end
181
-
182
- end # describe "#required!"
183
-
165
+ end
166
+
184
167
  describe "#perform" do
185
-
186
- def setup(switches_string = '')
187
- ARGV.empty!
168
+ def build(switches_string = '', &block)
169
+ ARGV.clear
188
170
  switches_string.split.each{|a| ARGV << a}
189
- Switches.new do |s|
190
- s.perform(:action){an_action}
191
- end
171
+ Switches.new{|s| s.perform(:a, :action, &block)}
172
+ end
173
+
174
+ it "calls the block when supplied with a short switch" do
175
+ called = false
176
+ build('-a'){called = true}
177
+ expect(called).to eq(true)
192
178
  end
193
-
194
- def an_action
195
- 'value'
179
+
180
+ it "calls the block when supplied with a long switch" do
181
+ called = false
182
+ build('--action'){called = true}
183
+ expect(called).to eq(true)
184
+ end
185
+
186
+ it "doesn't call the block when the switch isn't supplied" do
187
+ called = false
188
+ build{called = true}
189
+ expect(called).to eq(false)
196
190
  end
197
-
198
- it "should send(:an_action)"
199
-
200
- end # describe "#perform"
201
-
191
+
192
+ it "doesn't require an argument" do
193
+ expect{build('-a'){}}.not_to raise_error
194
+ end
195
+ end
196
+
202
197
  describe "#perform!" do
203
-
204
- def setup(switches_string = '')
205
- ARGV.empty!
198
+ def build(switches_string = '', &block)
199
+ ARGV.clear
206
200
  switches_string.split.each{|a| ARGV << a}
207
- Switches.new do |s|
208
- s.perform(:action){an_action}
209
- end
201
+ Switches.new{|s| s.perform!(:a, :action, &block)}
202
+ end
203
+
204
+ it "passes the argument to the block when supplied with a short switch" do
205
+ argument = nil
206
+ build('-a value'){|o| argument = o}
207
+ expect(argument).to eq('value')
210
208
  end
211
-
212
- def an_action
213
- 'value'
214
- end
215
-
216
- it "should send(:an_action)"
217
-
218
- it "should require a block parameter"
219
-
220
- end # describe "#perform!"
221
-
222
- end # describe Switches
209
+
210
+ it "passes the argument to the block when supplied with a long switch" do
211
+ argument = nil
212
+ build('--action value'){|o| argument = o}
213
+ expect(argument).to eq('value')
214
+ end
215
+
216
+ it "doesn't call the block when the switch isn't supplied" do
217
+ called = false
218
+ build{called = true}
219
+ expect(called).to eq(false)
220
+ end
221
+
222
+ it "raises OptionParser::MissingArgument when no argument is supplied" do
223
+ expect{build('-a'){}}.to raise_error(OptionParser::MissingArgument)
224
+ end
225
+ end
226
+ end
data/switches.rb.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'switches.rb' # I would have preferred 'switches', but there's a gem with the name of switches.
3
3
 
4
- s.version = '0.10.0'
4
+ s.version = '0.10.1'
5
5
  s.date = '2026-08-09'
6
6
 
7
7
  s.summary = "The easiest way to provide switches to a Ruby program."
@@ -12,12 +12,14 @@ Gem::Specification.new do |s|
12
12
  s.license = 'MIT'
13
13
  s.required_ruby_version = ">= 2.7.0"
14
14
 
15
+ s.add_development_dependency('rake')
15
16
  s.add_development_dependency('rspec')
16
17
 
17
18
  s.files = [
18
19
  'CHANGELOG',
19
20
  'Gemfile',
20
21
  'LICENSE.txt',
22
+ 'Rakefile',
21
23
  'README.md',
22
24
  'switches.rb.gemspec',
23
25
  Dir['lib/**/*.rb'],
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.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -9,6 +9,20 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 2026-08-09 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rake
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: rspec
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -34,6 +48,7 @@ files:
34
48
  - Gemfile
35
49
  - LICENSE.txt
36
50
  - README.md
51
+ - Rakefile
37
52
  - lib/Kernel/require_gem.rb
38
53
  - lib/Switches.rb
39
54
  - lib/Thoran/Kernel/RequireGem/require_gem.rb