option_list 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +12 -0
- data/lib/option_list/version.rb +1 -1
- data/option_list.gemspec +1 -2
- data/tests/option_list_test.rb +50 -50
- metadata +7 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3fc80941391b0ec0003d6410fbacab0e5f54726d7ead3e0a30b85b2a1302f865
|
4
|
+
data.tar.gz: 8c13ce0b7069b663805c86f267996794d4a53261c2cf7cce9922284eed3dadaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19e4ce85288187faa5326495572e6b33df72b30792c174e8922aabbcb9e10cd329f8f88e612a704a052f349bd066ae0196f3522b500ddde7bb7bb375000e1c9f
|
7
|
+
data.tar.gz: bac17c293cd014626a1e03f069f89315be0615aea23c3c2943846d3698c0cafda9bf138e8da37e7b555a234e029a80983f9bc52e70e2901ca4012f7171c7e48b
|
data/README.md
CHANGED
@@ -81,3 +81,15 @@ which covers version 1.1.1 which has no material change from 1.1.3
|
|
81
81
|
|
82
82
|
Go to the GitHub repository and raise an issue calling attention to some
|
83
83
|
aspect that could use some TLC or a suggestion or an idea.
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
The gem is available as open source under the terms of the
|
88
|
+
[MIT License](./LICENSE.txt).
|
89
|
+
|
90
|
+
## Code of Conduct
|
91
|
+
|
92
|
+
Everyone interacting in the fully_freeze project’s codebases, issue trackers,
|
93
|
+
chat rooms and mailing lists is expected to follow the
|
94
|
+
[code of conduct](./CODE_OF_CONDUCT.md).
|
95
|
+
|
data/lib/option_list/version.rb
CHANGED
data/option_list.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.platform = Gem::Platform::RUBY
|
18
18
|
s.required_ruby_version = '>=1.9.3'
|
19
19
|
|
20
|
-
s.add_development_dependency "bundler", "
|
20
|
+
s.add_development_dependency "bundler", ">= 2.1.0"
|
21
21
|
s.add_development_dependency 'rake'
|
22
22
|
s.add_development_dependency 'reek', "~> 1.3.8"
|
23
23
|
s.add_development_dependency 'minitest', "~> 4.7.5"
|
@@ -29,7 +29,6 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.extra_rdoc_files = ['license.txt']
|
30
30
|
|
31
31
|
s.license = 'MIT'
|
32
|
-
s.has_rdoc = true
|
33
32
|
s.require_path = 'lib'
|
34
33
|
end
|
35
34
|
|
data/tests/option_list_test.rb
CHANGED
@@ -8,73 +8,73 @@ class OptionTest
|
|
8
8
|
def initialize(opt)
|
9
9
|
@opt = opt
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test(*args)
|
13
|
-
|
13
|
+
@opt.select(args)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class OptionListTester <
|
17
|
+
class OptionListTester < Minitest::Test
|
18
18
|
$do_this_only_one_time = ""
|
19
|
-
|
19
|
+
|
20
20
|
def initialize(*all)
|
21
21
|
if $do_this_only_one_time != __FILE__
|
22
22
|
puts
|
23
|
-
puts "Running test file: #{File.split(__FILE__)[1]}"
|
23
|
+
puts "Running test file: #{File.split(__FILE__)[1]}"
|
24
24
|
$do_this_only_one_time = __FILE__
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
super(*all)
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_that_it_rejects_bad_specs
|
31
31
|
#Reject empty argument lists.
|
32
|
-
assert_raises(ArgumentError) { @x = OptionList.new }
|
32
|
+
assert_raises(ArgumentError) { @x = OptionList.new }
|
33
33
|
assert_raises(ArgumentError) { @x = OptionList.new([])}
|
34
34
|
assert_raises(ArgumentError) { @x = OptionList.new({})}
|
35
|
-
|
35
|
+
|
36
36
|
#Reject if not an array or a hash.
|
37
37
|
assert_raises(ArgumentError) { @x = OptionList.new(4) }
|
38
|
-
assert_raises(ArgumentError) { @x = OptionList.new('foobar') }
|
38
|
+
assert_raises(ArgumentError) { @x = OptionList.new('foobar') }
|
39
39
|
|
40
40
|
#Reject for too few arguments.
|
41
41
|
assert_raises(ArgumentError) { @x = OptionList.new([]) }
|
42
42
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo]) }
|
43
43
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :bar]) }
|
44
|
-
|
44
|
+
|
45
45
|
#Reject for the wrong types of arguments.
|
46
46
|
assert_raises(ArgumentError) { @x = OptionList.new(['foo', :foo, :bar] )}
|
47
47
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, 'foo', :bar] )}
|
48
48
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :foo, 'bar'])}
|
49
49
|
assert_raises(ArgumentError) { @x = OptionList.new({'foo' => 42})}
|
50
|
-
|
50
|
+
|
51
51
|
#Reject for duplicate categories.
|
52
52
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :lala, :bar], [:foo, :kung, :east]) }
|
53
53
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :lala, :bar], {:foo => :kung}) }
|
54
54
|
assert_raises(ArgumentError) { @x = OptionList.new({:foo => :lala}, {:foo => :kung}) }
|
55
55
|
#The following is not detectable since :foo => :kung overwrites :foo => :lala
|
56
56
|
#assert_raises(ArgumentError) { @x = OptionList.new({:foo => :lala, :foo => :kung}) }
|
57
|
-
|
57
|
+
|
58
58
|
#Reject for duplicate options.
|
59
59
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :bar, :bar]) }
|
60
|
-
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :foo, :bar], [:bla, :food, :bar]) }
|
60
|
+
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :foo, :bar], [:bla, :food, :bar]) }
|
61
61
|
|
62
|
-
#Reject for nil in the wrong position.
|
62
|
+
#Reject for nil in the wrong position.
|
63
63
|
assert_raises(ArgumentError) { @x = OptionList.new([:foo, :bar, nil]) }
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def test_that_the_methods_were_added
|
67
67
|
ol1 = OptionList.new([:history, :history, :nohistory], {:pg_len => 42})
|
68
68
|
o = ol1.select
|
69
|
-
|
69
|
+
|
70
70
|
assert_respond_to(o, :history)
|
71
71
|
assert_respond_to(o, :history? )
|
72
72
|
assert_respond_to(o, :nohistory? )
|
73
73
|
assert_respond_to(o, :pg_len)
|
74
74
|
|
75
|
-
ol2 = OptionList.new([:history, nil, :history, :nohistory])
|
75
|
+
ol2 = OptionList.new([:history, nil, :history, :nohistory])
|
76
76
|
o = ol2.select
|
77
|
-
|
77
|
+
|
78
78
|
assert_respond_to(o, :history)
|
79
79
|
assert_respond_to(o, :history? )
|
80
80
|
assert_respond_to(o, :nohistory? )
|
@@ -83,76 +83,76 @@ class OptionListTester < MiniTest::Unit::TestCase
|
|
83
83
|
|
84
84
|
def test_that_it_rejects_bad_selections
|
85
85
|
ol1 = OptionList.new([:history, :history, :nohistory], {:pg_len => 42})
|
86
|
-
|
86
|
+
|
87
87
|
#Reject if options are not an array or a hash.
|
88
88
|
assert_raises(ArgumentError) { ol1.select(45) }
|
89
|
-
|
89
|
+
|
90
90
|
#Reject if the option is not a symbol.
|
91
91
|
assert_raises(ArgumentError) { ol1.select([34]) }
|
92
|
-
|
92
|
+
|
93
93
|
#Reject if the category is not a symbol.
|
94
94
|
assert_raises(ArgumentError) { ol1.select({'page_len'=>77}) }
|
95
|
-
|
95
|
+
|
96
96
|
#Reject if the symbol is not one defined.
|
97
97
|
assert_raises(ArgumentError) { ol1.select([:foobar]) }
|
98
98
|
assert_raises(ArgumentError) { ol1.select({:history=>:foobar}) }
|
99
|
-
|
99
|
+
|
100
100
|
#Reject on duplicate symbol from the same category.
|
101
101
|
assert_raises(ArgumentError) { ol1.select([:history, :history]) }
|
102
|
-
assert_raises(ArgumentError) { ol1.select([:history, :nohistory]) }
|
102
|
+
assert_raises(ArgumentError) { ol1.select([:history, :nohistory]) }
|
103
103
|
assert_raises(ArgumentError) { ol1.select([:history, {:history=>:nohistory}]) }
|
104
104
|
assert_raises(ArgumentError) { ol1.select([{:history=>:history}, {:history=>:nohistory}]) }
|
105
|
-
|
105
|
+
|
106
106
|
#Reject on an undefined category.
|
107
107
|
assert_raises(ArgumentError) { ol1.select({:zoo => 999})}
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
def test_that_it_handles_good_options
|
111
111
|
#ol1 test series.
|
112
112
|
ol1 = OptionList.new([:history, :history, :nohistory], {:pg_len => 42})
|
113
|
-
|
113
|
+
|
114
114
|
o = ol1.select
|
115
115
|
assert(o.history?)
|
116
116
|
refute(o.nohistory?)
|
117
117
|
assert_equal(o.history, :history)
|
118
|
-
assert_equal(o.pg_len, 42)
|
119
|
-
|
118
|
+
assert_equal(o.pg_len, 42)
|
119
|
+
|
120
120
|
o = ol1.select([])
|
121
121
|
assert(o.history?)
|
122
122
|
refute(o.nohistory?)
|
123
123
|
assert_equal(o.history, :history)
|
124
|
-
assert_equal(o.pg_len, 42)
|
125
|
-
|
124
|
+
assert_equal(o.pg_len, 42)
|
125
|
+
|
126
126
|
o = ol1.select([:history])
|
127
127
|
assert(o.history?)
|
128
128
|
refute(o.nohistory?)
|
129
129
|
assert_equal(o.history, :history)
|
130
|
-
assert_equal(o.pg_len, 42)
|
131
|
-
|
130
|
+
assert_equal(o.pg_len, 42)
|
131
|
+
|
132
132
|
o = ol1.select([:nohistory])
|
133
133
|
refute(o.history?)
|
134
134
|
assert(o.nohistory?)
|
135
135
|
assert_equal(o.history, :nohistory)
|
136
|
-
assert_equal(o.pg_len, 42)
|
136
|
+
assert_equal(o.pg_len, 42)
|
137
137
|
|
138
138
|
o = ol1.select({:history=>:history})
|
139
139
|
assert(o.history?)
|
140
140
|
refute(o.nohistory?)
|
141
141
|
assert_equal(o.history, :history)
|
142
|
-
assert_equal(o.pg_len, 42)
|
143
|
-
|
142
|
+
assert_equal(o.pg_len, 42)
|
143
|
+
|
144
144
|
o = ol1.select({:history=>:nohistory})
|
145
145
|
refute(o.history?)
|
146
146
|
assert(o.nohistory?)
|
147
147
|
assert_equal(o.history, :nohistory)
|
148
|
-
assert_equal(o.pg_len, 42)
|
148
|
+
assert_equal(o.pg_len, 42)
|
149
149
|
|
150
150
|
o = ol1.select({:pg_len=>55})
|
151
151
|
assert(o.history?)
|
152
152
|
refute(o.nohistory?)
|
153
153
|
assert_equal(o.history, :history)
|
154
154
|
assert_equal(o.pg_len, 55)
|
155
|
-
|
155
|
+
|
156
156
|
o = ol1.select({:history=>:history, :pg_len=>55})
|
157
157
|
assert(o.history?)
|
158
158
|
refute(o.nohistory?)
|
@@ -177,10 +177,10 @@ class OptionListTester < MiniTest::Unit::TestCase
|
|
177
177
|
assert_equal(o.history, :nohistory)
|
178
178
|
assert_equal(o.pg_len, 55)
|
179
179
|
|
180
|
-
|
180
|
+
|
181
181
|
#ol2 test series.
|
182
|
-
ol2 = OptionList.new([:history, nil, :history, :nohistory])
|
183
|
-
|
182
|
+
ol2 = OptionList.new([:history, nil, :history, :nohistory])
|
183
|
+
|
184
184
|
o = ol2.select([:history])
|
185
185
|
assert(o.history?)
|
186
186
|
refute(o.nohistory?)
|
@@ -196,9 +196,9 @@ class OptionListTester < MiniTest::Unit::TestCase
|
|
196
196
|
refute(o.nohistory?)
|
197
197
|
assert(o.history.nil?)
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
def test_that_mandatory_parms_work
|
201
|
-
ol2 = OptionList.new([:history, false, :history, :nohistory])
|
201
|
+
ol2 = OptionList.new([:history, false, :history, :nohistory])
|
202
202
|
|
203
203
|
o = ol2.select([:history])
|
204
204
|
assert(o.history?)
|
@@ -211,30 +211,30 @@ class OptionListTester < MiniTest::Unit::TestCase
|
|
211
211
|
assert_equal(o.history, :nohistory)
|
212
212
|
|
213
213
|
assert_raises(ArgumentError) { ol2.select() }
|
214
|
-
|
214
|
+
|
215
215
|
ol3 = OptionList.new(page_len: false)
|
216
216
|
o = ol3.select(page_len: 42)
|
217
217
|
assert_equal(o.page_len, 42)
|
218
|
-
|
218
|
+
|
219
219
|
assert_raises(ArgumentError) { ol3.select() }
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
def test_that_it_does_not_munge_parms
|
223
223
|
parm1 = [:history, false, :history, :nohistory]
|
224
224
|
parm2 = parm1.clone
|
225
|
-
|
225
|
+
OptionList.new(parm1)
|
226
226
|
assert_equal(parm1, parm2)
|
227
227
|
end
|
228
|
-
|
228
|
+
|
229
229
|
def test_that_the_select_block_works
|
230
230
|
ol3 = OptionList.new([:history, nil, :history, :nohistory],
|
231
231
|
fuel1: :matter, fuel2: :antimatter) do |opt|
|
232
232
|
fail "The :history option must be set." if opt.history.nil?
|
233
233
|
fail "Improper fuel mix." unless opt.fuel1 == :matter && opt.fuel2 == :antimatter
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
t = OptionTest.new(ol3)
|
237
|
-
|
237
|
+
|
238
238
|
assert_raises(RuntimeError) { t.test() }
|
239
239
|
assert_raises(RuntimeError) { t.test(:nohistory, fuel2: :income_tax) }
|
240
240
|
#Really though, this should work! Both anti-matter and income tax
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: option_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Camilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.1.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,10 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
|
139
|
-
rubygems_version: 2.2.2
|
138
|
+
rubygems_version: 3.2.17
|
140
139
|
signing_key:
|
141
140
|
specification_version: 4
|
142
141
|
summary: Flexible, Easy Function Parameters with Validation.
|
143
142
|
test_files: []
|
144
|
-
has_rdoc: true
|