switches.rb 0.9.15 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f576247bc19561658a5bef4cda1a46f90e62b569fa15a6800507e5aeb05e7601
4
- data.tar.gz: c5c805d86f2c5fa6d3cb757118d6024c9dea9261b6ec0172e4c8c0c73018d7c8
3
+ metadata.gz: 30d6b5c6bbad8c0a585b418ff83ad25394c9de5cbe1a37089484d8c5ca16ad2a
4
+ data.tar.gz: a5a3bda6bf97e2c8355c12e8113947a94523abe9f9e8d344f81fa3f6e4947d6f
5
5
  SHA512:
6
- metadata.gz: e355d5bbb5bf7ee88fd4dabd45761d7eeb4ea2d20bc443228cf9881929411d605ab92c594d0d66c4d081bd16f1d4c896caf597f938f1a1d92cf4877531b6658b
7
- data.tar.gz: 1f8f0162b5eb238df5e8e6143fe69348754fcfab16d31cb9480e378e31459fc974472916dab1cf00910c1adfa3a1422eb776ce9f93adf6c637a94d0faf5ade16
6
+ metadata.gz: fdb9781dc62a69ec53edb7e2d95ed7f83edc62079512e632af30a49a258831e1b35be02d8e81b74372664cf99d1e724f5f7b3747946dbdd76e5014bd863fae47
7
+ data.tar.gz: 5e7bca50700640d86c65c65355ffefa83480641fc7492141046f83d923403b0ac82efcb9da347db19ae0ea2a89ef36d44d195251341fc2ef688561b18f3e15d9
data/CHANGELOG ADDED
@@ -0,0 +1,22 @@
1
+ # CHANGELOG
2
+
3
+ ## 20260809
4
+
5
+ 0.10.0: Restore loading and building under Ruby 4.0, and bring the repo up to standard.
6
+
7
+ 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.
8
+ 2. ~ switches.rb.gemspec: - has_rdoc=, which RubyGems has removed and which now raises when the gemspec is loaded.
9
+ 3. ~ switches.rb.gemspec: + s.license, + s.required_ruby_version (>= 2.7.0), + s.metadata, + rspec as a development dependency, and + Gemfile, LICENSE.txt and CHANGELOG to the file list.
10
+ 4. - Gemfile.lock, which a library should not track, and + .gitignore to keep it out.
11
+ 5. + LICENSE.txt: the MIT licence.
12
+ 6. + CHANGELOG: this file.
13
+
14
+ ## 20180404
15
+
16
+ 0.9.16: Add a Gemfile.
17
+
18
+ 0.9.15: Rename the gem to switches.rb, since the switches name was taken, and tidy the specs.
19
+
20
+ 0.9.14: Turn switches into a gem, convert the README to markdown, and remove the examples directory.
21
+
22
+ Nothing before 0.9.14 is recorded here: switches began in 2009, and its pre-gem history — the 0.4.0 to 0.9.13 series noted in the source header — carries no reliable per-version dates.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2009-2026 thoran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -8,7 +8,7 @@ Switches provides for a nice wrapper to OptionParser to also act as a store for
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'switches'
11
+ gem 'switches.rb'
12
12
 
13
13
  And then execute:
14
14
 
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install switches
19
+ $ gem install switches.rb
20
20
 
21
21
 
22
22
  ## Usage
@@ -24,7 +24,6 @@ Or install it yourself as:
24
24
  ```Ruby
25
25
 
26
26
  # With optional switch
27
-
28
27
  switches = Switches.new do |s|
29
28
  s.set(:a)
30
29
  # OR
@@ -33,7 +32,6 @@ end
33
32
  switches.a
34
33
 
35
34
  # With argument required
36
-
37
35
  switches = Switches.new do |s|
38
36
  s.set!(:a)
39
37
  # OR
@@ -42,7 +40,6 @@ end
42
40
  switches.a
43
41
 
44
42
  # With switch required
45
-
46
43
  switches = Switches.new do |s|
47
44
  s.set(:a, required: true)
48
45
  # OR
@@ -51,7 +48,6 @@ end
51
48
  switches.a
52
49
 
53
50
  # With switch and argument required
54
-
55
51
  switches = Switches.new do |s|
56
52
  s.set!(:a, required: true)
57
53
  # OR
@@ -60,7 +56,6 @@ end
60
56
  switches.a
61
57
 
62
58
  # With boolean switch
63
-
64
59
  switches = Switches.new do |s|
65
60
  s.set(:a?)
66
61
  # OR
@@ -69,14 +64,12 @@ end
69
64
  switches.a?
70
65
 
71
66
  # With a default value
72
-
73
67
  switches = Switches.new do |s|
74
68
  s.set(:a, default: 31)
75
69
  end
76
70
  switches.a # => 31
77
71
 
78
72
  # With switch cast to an integer
79
-
80
73
  switches = Switches.new(include_casting_interface_methods: true) do |s|
81
74
  s.set(:a, cast: Integer)
82
75
  # OR
@@ -89,7 +82,6 @@ end
89
82
  switches.a.class # => Integer
90
83
 
91
84
  # With switch cast to a float
92
-
93
85
  switches = Switches.new(include_casting_interface_methods: true) do |s|
94
86
  s.set(:a, cast: Float)
95
87
  # OR
@@ -102,7 +94,6 @@ end
102
94
  switches.a.class # => Float
103
95
 
104
96
  # With switch cast to an array
105
-
106
97
  switches = Switches.new(include_casting_interface_methods: true) do |s|
107
98
  s.set(:a, cast: Array)
108
99
  # OR
@@ -115,7 +106,6 @@ end
115
106
  switches.a.class # => Array
116
107
 
117
108
  # With switch cast to a regex
118
-
119
109
  switches = Switches.new(include_casting_interface_methods: true) do |s|
120
110
  s.set(:a, cast: Regexp)
121
111
  # OR
@@ -128,7 +118,6 @@ end
128
118
  switches.a.class # => Regexp
129
119
 
130
120
  # With a default value and cast to an integer
131
-
132
121
  switches = Switches.new(include_casting_interface_methods: true) do |s|
133
122
  s.set(:a, default: 31, cast: Integer)
134
123
  # OR
@@ -142,19 +131,16 @@ switches.a # => 31 if no argument supplied
142
131
  switches.a.class # => Integer
143
132
 
144
133
  # With a description of the switch
145
-
146
134
  switches = Switches.new do |s|
147
135
  s.set(:a){'This is the -a switch.'}
148
136
  end
149
137
 
150
138
  # With a banner
151
-
152
139
  switches = Switches.new do |s|
153
140
  s.banner = 'Here is a banner for the switches.'
154
141
  end
155
142
 
156
143
  # Return a hash instead of an object of class Switches
157
-
158
144
  switches = Switches.new(to_h: true) do |s|
159
145
  s.set(:a)
160
146
  end
@@ -162,31 +148,26 @@ end
162
148
  switches = Switches.as_h do |s|
163
149
  s.set(:a)
164
150
  end
165
-
166
151
  switches[:a]
167
152
  switches.class # => Hash
168
153
 
169
154
  # Without a block
170
-
171
155
  switches = Switches.new
172
156
  switches.set(:a)
173
157
  switches.parse!
174
158
  switches.a
175
159
 
176
160
  # With an action
177
-
178
161
  switches = Switches.new do |s|
179
162
  switches.perform(:a){puts 'a'}
180
163
  switches.parse! # => a
181
164
 
182
- # With an action uses the argument
183
-
165
+ # With an action which uses an argument
184
166
  switches = Switches.new do |s|
185
167
  switches.perform(:a){|block_arg| puts block_arg.upcase}
186
168
  switches.parse! # => A
187
169
 
188
170
  # With multiple features combined
189
-
190
171
  switches = Switches.new(include_casting_interface_methods: true, to_h: true) do |s|
191
172
  s.set(:a, default: 31, cast: Integer){'This is the switch -a. It has a default of 31.'}
192
173
  # OR
@@ -0,0 +1,7 @@
1
+ # Kernel/require_gem.rb
2
+ # Kernel#require_gem
3
+
4
+ # 20240613
5
+ # 0.0.0
6
+
7
+ require 'Thoran/Kernel/RequireGem/require_gem'
data/lib/Switches.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # Switches.rb
2
2
  # Switches
3
3
 
4
- # 20180403
5
- # 0.9.15
4
+ # 20260809
5
+ # 0.10.0
6
6
 
7
7
  # Description: Switches provides for a nice wrapper to OptionParser to also act as a store for switches supplied.
8
8
 
@@ -136,9 +136,13 @@
136
136
  # 92. switches gem name taken, so renamed the gem to switches.rb.
137
137
  # 93. Version number bump to 0.9.15.
138
138
  # 94. Tidied some comments in spec/all.rb.
139
+ # 15/16
140
+ # 95. + Gemfile
139
141
 
140
142
  require 'optparse'
141
- require 'ostruct'
143
+ require 'Kernel/require_gem'
144
+
145
+ require_gem 'ostruct'
142
146
 
143
147
  class OpenStruct
144
148
 
@@ -0,0 +1,27 @@
1
+ # Thoran/Kernel/RequireGem/require_gem.rb
2
+ # Thoran::Kernel::RequireGem#require_gem.rb
3
+
4
+ # 20240613
5
+ # 0.0.0
6
+
7
+ module Thoran
8
+ module Kernel
9
+ module RequireGem
10
+
11
+ def require_gem(load_string, gem_name: nil)
12
+ require load_string
13
+ rescue LoadError
14
+ if gem_name
15
+ system("gem install #{gem_name}")
16
+ else
17
+ system("gem install #{load_string}")
18
+ end
19
+ Gem.clear_paths
20
+ require load_string
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ Kernel.include(Thoran::Kernel::RequireGem)
data/switches.rb.gemspec CHANGED
@@ -1,16 +1,23 @@
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.9.15'
5
- s.date = '2018-04-03'
4
+ s.version = '0.10.0'
5
+ s.date = '2026-08-09'
6
6
 
7
7
  s.summary = "The easiest way to provide switches to a Ruby program."
8
8
  s.description = "Switches provides for a nice wrapper to OptionParser to also act as a store for switches supplied."
9
9
  s.author = 'thoran'
10
10
  s.email = 'code@thoran.com'
11
- s.homepage = "http://github.com/thoran/switches"
11
+ s.homepage = "https://github.com/thoran/switches"
12
+ s.license = 'MIT'
13
+ s.required_ruby_version = ">= 2.7.0"
14
+
15
+ s.add_development_dependency('rspec')
12
16
 
13
17
  s.files = [
18
+ 'CHANGELOG',
19
+ 'Gemfile',
20
+ 'LICENSE.txt',
14
21
  'README.md',
15
22
  'switches.rb.gemspec',
16
23
  Dir['lib/**/*.rb'],
@@ -19,5 +26,10 @@ Gem::Specification.new do |s|
19
26
 
20
27
  s.require_paths = ['lib']
21
28
 
22
- s.has_rdoc = false
29
+ s.metadata = {
30
+ "bug_tracker_uri" => "https://github.com/thoran/switches/issues",
31
+ "changelog_uri" => "https://github.com/thoran/switches/blob/master/CHANGELOG",
32
+ "source_code_uri" => "https://github.com/thoran/switches",
33
+ "documentation_uri" => "https://github.com/thoran/switches/blob/master/README.md"
34
+ }
23
35
  end
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switches.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.15
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
12
- dependencies: []
10
+ date: 2026-08-09 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rspec
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'
13
26
  description: Switches provides for a nice wrapper to OptionParser to also act as a
14
27
  store for switches supplied.
15
28
  email: code@thoran.com
@@ -17,14 +30,23 @@ executables: []
17
30
  extensions: []
18
31
  extra_rdoc_files: []
19
32
  files:
33
+ - CHANGELOG
34
+ - Gemfile
35
+ - LICENSE.txt
20
36
  - README.md
37
+ - lib/Kernel/require_gem.rb
21
38
  - lib/Switches.rb
39
+ - lib/Thoran/Kernel/RequireGem/require_gem.rb
22
40
  - spec/all.rb
23
41
  - switches.rb.gemspec
24
- homepage: http://github.com/thoran/switches
25
- licenses: []
26
- metadata: {}
27
- post_install_message:
42
+ homepage: https://github.com/thoran/switches
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ bug_tracker_uri: https://github.com/thoran/switches/issues
47
+ changelog_uri: https://github.com/thoran/switches/blob/master/CHANGELOG
48
+ source_code_uri: https://github.com/thoran/switches
49
+ documentation_uri: https://github.com/thoran/switches/blob/master/README.md
28
50
  rdoc_options: []
29
51
  require_paths:
30
52
  - lib
@@ -32,16 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
54
  requirements:
33
55
  - - ">="
34
56
  - !ruby/object:Gem::Version
35
- version: '0'
57
+ version: 2.7.0
36
58
  required_rubygems_version: !ruby/object:Gem::Requirement
37
59
  requirements:
38
60
  - - ">="
39
61
  - !ruby/object:Gem::Version
40
62
  version: '0'
41
63
  requirements: []
42
- rubyforge_project:
43
- rubygems_version: 2.7.4
44
- signing_key:
64
+ rubygems_version: 4.0.17
45
65
  specification_version: 4
46
66
  summary: The easiest way to provide switches to a Ruby program.
47
67
  test_files: []