switches.rb 0.13.0 → 0.14.0
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 +4 -4
- data/CHANGELOG +16 -1
- data/README.md +4 -0
- data/Rakefile +3 -3
- data/lib/Switches/VERSION.rb +1 -1
- data/lib/{Switches.rb → switches.rb} +10 -6
- data/switches.rb.gemspec +6 -4
- data/test/Switches/VERSION_test.rb +22 -0
- data/test/gemspec_test.rb +29 -0
- data/test/loading_test.rb +35 -0
- data/{spec/all.rb → test/switches_test.rb} +29 -33
- metadata +8 -5
- /data/{LICENSE.txt → LICENSE} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3cbd3a1b71b73ff88bff3636515686728e4f7624f24d5f8256b205070099f36c
|
|
4
|
+
data.tar.gz: bcfbeb1a9792d4756ec1b0c1c6956f24a4397955f28a184cd63bd7f1e242d6ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31b869491dc02f0464e872157d130bea31187226536b29cfba18f20a9b5c5fde41fd302b70f5e0eb775893e6ead89faaf482174513b20d90c172f5b7b78b50e4
|
|
7
|
+
data.tar.gz: 7331a051152ada9e4416c124d845a39938534397d4fb7782ca47878534cde203a9cd965451289664aec6c06859eab6022c82fe30448d3afaf3f8c8accb6ccb2c
|
data/CHANGELOG
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
# CHANGELOG
|
|
1
|
+
# switches/CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 20260921
|
|
4
|
+
|
|
5
|
+
0.14.0: ~ lib/Switches.rb --> lib/switches.rb, so that it works on both case sensitive and case insensitive filesystems.
|
|
6
|
+
|
|
7
|
+
1. ~ lib/Switches.rb --> lib/switches.rb.
|
|
8
|
+
2. ~ spec/all.rb --> test/switches_test.rb, - spec/.
|
|
9
|
+
3. + test/Switches/VERSION_test.rb, test/gemspec_test.rb, test/loading_test.rb.
|
|
10
|
+
4. ~ Rakefile: FileList['test/**/*_test.rb'] for ['spec/all.rb'], /:spec/:test/, + a version task.
|
|
11
|
+
5. ~ switches.rb.gemspec: /LICENSE.txt/LICENSE/, /Dir['spec/**\/*.rb']/Dir['test/**\/*_test.rb']/, + the heading comment.
|
|
12
|
+
6. ~ LICENSE.txt --> LICENSE.
|
|
13
|
+
7. ~ set_switches_with_defaults: if casting == Integer for case @castings[switch] when Integer. case/when asks whether the value is an instance of the class, and @castings holds the class itself, so Integer === Integer was false, no branch was taken, and every switch declared with a cast and a default answered nil. integer!, float!, array! and regexp! alike, with or without the bang.
|
|
14
|
+
8. + 6 examples for a default upon a switch which casts, one per cast and two controls. The four cast examples fail against the previous form and the two controls do not, --mailbox having no cast and a supplied value never reaching the default.
|
|
15
|
+
9. ~ README.md: + a License section.
|
|
16
|
+
10. ~ Switches::VERSION: /0.13.0/0.14.0/
|
|
2
17
|
|
|
3
18
|
## 20260817
|
|
4
19
|
|
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
require 'rake/testtask'
|
|
4
4
|
|
|
5
|
-
Rake::TestTask.new(:
|
|
6
|
-
t.test_files = ['
|
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
|
6
|
+
t.test_files = FileList['test/**/*_test.rb']
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
task default: :
|
|
9
|
+
task default: :test
|
|
10
10
|
|
|
11
11
|
desc "Show version"
|
|
12
12
|
task :version do
|
data/lib/Switches/VERSION.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# switches.rb
|
|
2
2
|
# Switches
|
|
3
3
|
|
|
4
4
|
# Description: Switches provides for a nice wrapper to OptionParser to also act as a store for switches supplied.
|
|
@@ -344,12 +344,16 @@ class Switches
|
|
|
344
344
|
switches_with_defaults.each do |switch|
|
|
345
345
|
if @settings.to_h[switch.to_sym].nil?
|
|
346
346
|
if switches_with_castings.include?(switch)
|
|
347
|
+
casting = @castings[switch]
|
|
347
348
|
cast_value = (
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
if casting == Integer
|
|
350
|
+
@defaults[switch].to_i
|
|
351
|
+
elsif casting == Float
|
|
352
|
+
@defaults[switch].to_f
|
|
353
|
+
elsif casting == Array
|
|
354
|
+
@defaults[switch].to_a
|
|
355
|
+
elsif casting == Regexp
|
|
356
|
+
Regexp.new(@defaults[switch])
|
|
353
357
|
end
|
|
354
358
|
)
|
|
355
359
|
@settings.send(switch + '=', cast_value)
|
data/switches.rb.gemspec
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# switches.rb.gemspec
|
|
2
|
+
|
|
1
3
|
require_relative './lib/Switches/VERSION'
|
|
2
4
|
|
|
3
5
|
class Gem::Specification
|
|
@@ -26,14 +28,14 @@ Gem::Specification.new do |s|
|
|
|
26
28
|
s.require_paths = ['lib']
|
|
27
29
|
|
|
28
30
|
s.files = [
|
|
31
|
+
'switches.rb.gemspec',
|
|
32
|
+
Dir['lib/**/*.rb'],
|
|
33
|
+
Dir['test/**/*_test.rb'],
|
|
29
34
|
'CHANGELOG',
|
|
30
35
|
'Gemfile',
|
|
31
|
-
'LICENSE
|
|
36
|
+
'LICENSE',
|
|
32
37
|
'Rakefile',
|
|
33
38
|
'README.md',
|
|
34
|
-
'switches.rb.gemspec',
|
|
35
|
-
Dir['lib/**/*.rb'],
|
|
36
|
-
Dir['spec/**/*.rb'],
|
|
37
39
|
].flatten
|
|
38
40
|
|
|
39
41
|
s.dependencies = [
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# test/Switches/VERSION_test.rb
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
require_relative '../../lib/switches'
|
|
6
|
+
|
|
7
|
+
describe Switches do
|
|
8
|
+
describe "VERSION" do
|
|
9
|
+
it "is a string" do
|
|
10
|
+
_(Switches::VERSION).must_be_kind_of String
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "is three numbers separated by dots" do
|
|
14
|
+
_(Switches::VERSION).must_match(/\A\d+\.\d+\.\d+\z/)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "matches the newest entry in the CHANGELOG" do
|
|
18
|
+
changelog = File.read(File.expand_path('../../CHANGELOG', __dir__))
|
|
19
|
+
_(changelog[/^(\d+\.\d+\.\d+):/, 1]).must_equal Switches::VERSION
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# test/gemspec_test.rb
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/switches'
|
|
6
|
+
|
|
7
|
+
describe 'switches.rb.gemspec' do
|
|
8
|
+
let(:spec){Gem::Specification.load(File.expand_path('../switches.rb.gemspec', __dir__))}
|
|
9
|
+
|
|
10
|
+
it "is a valid specification" do
|
|
11
|
+
_(spec.validate).must_equal true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "does not pin a date" do
|
|
15
|
+
_(spec.date).must_equal Gem::Specification.new.date
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "takes its version from Switches::VERSION" do
|
|
19
|
+
_(spec.version.to_s).must_equal Switches::VERSION
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "declares ostruct as its only runtime dependency" do
|
|
23
|
+
_(spec.runtime_dependencies.map(&:name).sort).must_equal %w{ostruct}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "declares its development dependencies" do
|
|
27
|
+
_(spec.development_dependencies.map(&:name).sort).must_equal %w{minitest rake}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# test/loading_test.rb
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/switches'
|
|
6
|
+
|
|
7
|
+
# In its own process, since this one has loaded the file directly and so could
|
|
8
|
+
# not tell what requiring the gem by its own name would bring.
|
|
9
|
+
describe 'loading' do
|
|
10
|
+
def ruby(source)
|
|
11
|
+
lib = File.expand_path('../lib', __dir__)
|
|
12
|
+
IO.popen(['ruby', "-I#{lib}", '-e', source], err: [:child, :out]){|io| io.read}.strip
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# The gem is switches.rb, so require 'switches.rb' reads lib/switches.rb. A
|
|
16
|
+
# capitalised lib/Switches.rb answers that only on a case-insensitive
|
|
17
|
+
# filesystem, which is to say on the machine it was written on and not on
|
|
18
|
+
# Linux. Dir.entries reports the name as stored, so this asks exactly what a
|
|
19
|
+
# case-sensitive filesystem would ask.
|
|
20
|
+
it "carries the lowercase file the gem's name asks for" do
|
|
21
|
+
_(Dir.entries(File.expand_path('../lib', __dir__))).must_include 'switches.rb'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "defines Switches upon requiring the gem by name" do
|
|
25
|
+
_(ruby('require "switches.rb"; print defined?(Switches)')).must_equal 'constant'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "defines the version too" do
|
|
29
|
+
_(ruby('require "switches.rb"; print Switches::VERSION')).must_equal Switches::VERSION
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "answers to the name without its extension as well" do
|
|
33
|
+
_(ruby('require "switches"; print defined?(Switches)')).must_equal 'constant'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# test/switches_test.rb
|
|
2
2
|
|
|
3
3
|
require 'minitest/autorun'
|
|
4
4
|
|
|
5
|
-
require_relative '../lib/
|
|
5
|
+
require_relative '../lib/switches'
|
|
6
6
|
|
|
7
7
|
describe Switches do
|
|
8
8
|
describe ".new" do
|
|
@@ -409,45 +409,41 @@ describe Switches do
|
|
|
409
409
|
_{build('-a'){}}.must_raise OptionParser::MissingArgument
|
|
410
410
|
end
|
|
411
411
|
end
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
412
|
+
describe "a default upon a switch which casts" do
|
|
413
|
+
def build(switches_string = '')
|
|
414
|
+
ARGV.clear
|
|
415
|
+
switches_string.split.each{|a| ARGV << a}
|
|
416
|
+
Switches.new do |s|
|
|
417
|
+
s.integer!(:lines, default: '10')
|
|
418
|
+
s.float!(:ratio, default: '1.5')
|
|
419
|
+
s.array!(:hosts, default: ['a', 'b'])
|
|
420
|
+
s.regexp!(:pattern, default: 'ab+c')
|
|
421
|
+
s.optional!(:mailbox, default: 'INBOX')
|
|
422
|
+
end
|
|
418
423
|
end
|
|
419
424
|
|
|
420
|
-
it "
|
|
421
|
-
_(
|
|
425
|
+
it "casts an integer default rather than answering nil" do
|
|
426
|
+
_(build.lines).must_equal 10
|
|
422
427
|
end
|
|
423
428
|
|
|
424
|
-
it "
|
|
425
|
-
|
|
426
|
-
_(changelog[/^(\d+\.\d+\.\d+):/, 1]).must_equal Switches::VERSION
|
|
429
|
+
it "casts a float default rather than answering nil" do
|
|
430
|
+
_(build.ratio).must_equal 1.5
|
|
427
431
|
end
|
|
428
|
-
end
|
|
429
|
-
end
|
|
430
432
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
it "is a valid specification" do
|
|
435
|
-
_(spec.validate).must_equal true
|
|
436
|
-
end
|
|
437
|
-
|
|
438
|
-
it "does not pin a date" do
|
|
439
|
-
_(spec.date).must_equal Gem::Specification.new.date
|
|
440
|
-
end
|
|
433
|
+
it "carries an array default rather than answering nil" do
|
|
434
|
+
_(build.hosts).must_equal ['a', 'b']
|
|
435
|
+
end
|
|
441
436
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
437
|
+
it "casts a regexp default rather than answering nil" do
|
|
438
|
+
_(build.pattern).must_equal(/ab+c/)
|
|
439
|
+
end
|
|
445
440
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
441
|
+
it "leaves a default upon a switch which does not cast alone" do
|
|
442
|
+
_(build.mailbox).must_equal 'INBOX'
|
|
443
|
+
end
|
|
449
444
|
|
|
450
|
-
|
|
451
|
-
|
|
445
|
+
it "prefers a supplied value to the default" do
|
|
446
|
+
_(build('--lines 3').lines).must_equal 3
|
|
447
|
+
end
|
|
452
448
|
end
|
|
453
449
|
end
|
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.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -60,13 +60,16 @@ extra_rdoc_files: []
|
|
|
60
60
|
files:
|
|
61
61
|
- CHANGELOG
|
|
62
62
|
- Gemfile
|
|
63
|
-
- LICENSE
|
|
63
|
+
- LICENSE
|
|
64
64
|
- README.md
|
|
65
65
|
- Rakefile
|
|
66
|
-
- lib/Switches.rb
|
|
67
66
|
- lib/Switches/VERSION.rb
|
|
68
|
-
-
|
|
67
|
+
- lib/switches.rb
|
|
69
68
|
- switches.rb.gemspec
|
|
69
|
+
- test/Switches/VERSION_test.rb
|
|
70
|
+
- test/gemspec_test.rb
|
|
71
|
+
- test/loading_test.rb
|
|
72
|
+
- test/switches_test.rb
|
|
70
73
|
homepage: https://github.com/thoran/switches
|
|
71
74
|
licenses:
|
|
72
75
|
- MIT
|
|
@@ -89,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
92
|
- !ruby/object:Gem::Version
|
|
90
93
|
version: '0'
|
|
91
94
|
requirements: []
|
|
92
|
-
rubygems_version: 4.0.
|
|
95
|
+
rubygems_version: 4.0.20
|
|
93
96
|
specification_version: 4
|
|
94
97
|
summary: The easiest way to provide switches to a Ruby program.
|
|
95
98
|
test_files: []
|
/data/{LICENSE.txt → LICENSE}
RENAMED
|
File without changes
|