clasp-ruby 0.10.3 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e007bbed01cc21eac912ca3b1b9bb469c7d43374
4
- data.tar.gz: 4150fa56767e91625f28ab54e79a4c1be191a10a
3
+ metadata.gz: a8da53dd37696e2528150ea2194a0b3455df79ce
4
+ data.tar.gz: 531aa7eb5a3f7fac55f024c021f22aefe84b5d75
5
5
  SHA512:
6
- metadata.gz: 61b42dbcd038db45a01c41aa9d6bb9cd1eb1f01477aace59a0ea8d7a0b645fd8df61d980484b33c16b68b54a9c9d0c83a8bf3a7fe37c761a70b19abe3a8fe8dd
7
- data.tar.gz: 68f0d1dab2deb640869437ec1e1de6958717593f12dd2a89ab8d69f515caaf42802f0493846fa7592b08c0dfe30cf2829dcec7e1fdb8202d4fa7e8a8b1b0f979
6
+ metadata.gz: 182e5db95920e7adbd62786d608d8a8de0c29f85e266d4a3ab481ed24a5c7665fe51c9e1a6a498e78d43d08b3597f145a05bf464fa5c44013001685f849a0e33
7
+ data.tar.gz: 72372e9151b6f1acf8efe591b9b1d9213acf52c5a042fd442d69c090908ba4f42d091297e6e709a5b18d317ba6f73d568448ce7c8a8a7749c6d720cf9f420513
@@ -6,7 +6,7 @@
6
6
  # CLASP.Ruby
7
7
  #
8
8
  # Created: 14th February 2014
9
- # Updated: 11th June 2016
9
+ # Updated: 16th July 2016
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/CLASP.Ruby
12
12
  #
@@ -46,6 +46,7 @@
46
46
 
47
47
 
48
48
 
49
+ require 'clasp/util/immutable_array'
49
50
 
50
51
  =begin
51
52
  =end
@@ -178,50 +179,25 @@ class Arguments
178
179
  end
179
180
  end
180
181
 
181
- class ImmutableArray #:nodoc: all
182
-
183
- include Enumerable
184
-
185
- #:nodoc:
186
- def initialize(a)
187
-
188
- @a = a
189
- end
190
-
191
- #:nodoc:
192
- def each
182
+ #:startdoc:
193
183
 
194
- @a.each { |i| yield i }
195
- end
184
+ class ImmutableArray < ::CLASP::Util::ImmutableArray
196
185
 
197
- #:nodoc:
198
- def size
186
+ def initialize a
199
187
 
200
- @a.size
188
+ super a
201
189
  end
202
190
 
203
- #:nodoc:
204
- def empty?
191
+ # returns truthy if the given flag/option is found or the
192
+ # given block is truthy
193
+ def specified? id = nil
205
194
 
206
- @a.empty?
207
- end
208
-
209
- #:nodoc:
210
- def [](index)
195
+ return find(id) { |o| yield o } if block_given?
211
196
 
212
- @a[index]
213
- end
214
-
215
- #:nodoc:
216
- def ==(rhs)
217
-
218
- return rhs == @a if rhs.is_a? self.class
219
- @a == rhs
197
+ find { |item| item == id }
220
198
  end
221
199
  end
222
200
 
223
- #:startdoc:
224
-
225
201
  # ######################
226
202
  # Construction
227
203
 
@@ -431,37 +407,37 @@ class Arguments
431
407
 
432
408
  # unchanged copy of the original array of arguments passed to new
433
409
  attr_reader :argv_original_copy
434
- end
435
410
 
436
- # ######################################################################## #
437
- # module
438
411
 
439
- end # module CLASP
412
+ # finds the first unknown flag or option; +nil+ if all used
413
+ def find_first_unknown options = {}
440
414
 
441
- # ######################################################################## #
442
- # extensions
415
+ option = {} if options.nil?
443
416
 
444
- #:nodoc:
445
- class Array
417
+ raise ArgumentError, "options must be nil or Hash - #{option.class} given" unless options.is_a? ::Hash
446
418
 
447
- # Monkey-patched Array#== in order to handle comparison with
448
- # ImmutableArray
449
- #
450
- # NOTE: do not do so for +eql?+
419
+ aliases = options[:aliases] || @aliases
451
420
 
452
- #:nodoc:
453
- alias_method :old_equal, :==
421
+ raise ArgumentError, "aliases may not be nil" if aliases.nil?
454
422
 
455
- undef :==
423
+ flags.each do |f|
456
424
 
457
- #:nodoc:
458
- def ==(rhs)
425
+ return f unless aliases.any? { |al| al.is_a?(::CLASP::Flag) && al.name == f.name }
426
+ end
427
+
428
+ options.each do |o|
459
429
 
460
- return rhs == self if rhs.is_a? CLASP::Arguments::ImmutableArray
430
+ return o unless aliases.any? { |al| al.is_a?(::CLASP::Option) && al.name == o.name }
431
+ end
461
432
 
462
- old_equal rhs
433
+ nil
463
434
  end
464
435
  end
465
436
 
437
+ # ######################################################################## #
438
+ # module
439
+
440
+ end # module CLASP
441
+
466
442
  # ############################## end of file ############################# #
467
443
 
@@ -0,0 +1,169 @@
1
+
2
+ # ######################################################################## #
3
+ # File: clasp/util/immutable_array.rb
4
+ #
5
+ # Purpose: Definition of the CLASP::Util::ImmutableArray class
6
+ #
7
+ # Created: 14th February 2014
8
+ # Updated: 16th July 2016
9
+ #
10
+ # Home: http://github.com/synesissoftware/CLASP.Ruby
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2014-2016, Matthew Wilson and Synesis Software
15
+ # All rights reserved.
16
+ #
17
+ # Redistribution and use in source and binary forms, with or without
18
+ # modification, are permitted provided that the following conditions are
19
+ # met:
20
+ #
21
+ # * Redistributions of source code must retain the above copyright
22
+ # notice, this list of conditions and the following disclaimer.
23
+ #
24
+ # * Redistributions in binary form must reproduce the above copyright
25
+ # notice, this list of conditions and the following disclaimer in the
26
+ # documentation and/or other materials provided with the distribution.
27
+ #
28
+ # * Neither the names of the copyright holder nor the names of its
29
+ # contributors may be used to endorse or promote products derived from
30
+ # this software without specific prior written permission.
31
+ #
32
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
33
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
34
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
36
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
+ #
44
+ # ######################################################################## #
45
+
46
+
47
+
48
+
49
+ =begin
50
+ =end
51
+
52
+ module CLASP
53
+ module Util
54
+
55
+ # ######################################################################## #
56
+ # classes
57
+
58
+ # An immutable array
59
+ class ImmutableArray
60
+
61
+ include Enumerable
62
+
63
+ #:nodoc:
64
+ def initialize(a)
65
+
66
+ raise ArgumentError, "must supply array" if a.nil?
67
+ raise TypeError, "must supply instance of #{::Array}; #{a.class} given" unless a.is_a? ::Array
68
+
69
+ @a = a
70
+ end
71
+
72
+ # Calls the block once for each element in the array
73
+ def each
74
+
75
+ return @a.each unless block_given?
76
+
77
+ @a.each { |i| yield i }
78
+ end
79
+
80
+ # Alias for +length+
81
+ def size
82
+
83
+ @a.size
84
+ end
85
+
86
+ # Indicates whether the immutable array has no elements
87
+ def empty?
88
+
89
+ @a.empty?
90
+ end
91
+
92
+ # Same semantics as +Enumerable#find+ for the underlying array
93
+ def find ifnone = nil
94
+
95
+ return @a.find(ifnone) { |o| yield o } if block_given?
96
+
97
+ @a.find ifnone
98
+ end
99
+
100
+ # The number of elements in the immutable array
101
+ def length
102
+
103
+ @a.length
104
+ end
105
+
106
+ # Same semantics as +Array#slice+
107
+ def slice *args
108
+
109
+ case args.length
110
+ when 1
111
+ case args[0]
112
+ when ::Integer
113
+ return @a.slice args[0]
114
+ end
115
+ when 2
116
+ else
117
+ end
118
+
119
+ self.class.new @a.slice(*args)
120
+ end
121
+
122
+ # Same semantics as +Array#[]+
123
+ def [] *args
124
+
125
+ slice(*args)
126
+ end
127
+
128
+ # Determines whether +rhs+ is each to the receiver
129
+ def == rhs
130
+
131
+ return rhs == @a if rhs.is_a? self.class
132
+
133
+ @a == rhs
134
+ end
135
+ end
136
+
137
+ # ######################################################################## #
138
+ # module
139
+
140
+ end # module Util
141
+ end # module CLASP
142
+
143
+ # ######################################################################## #
144
+ # extensions
145
+
146
+ #:nodoc:
147
+ class Array
148
+
149
+ # Monkey-patched Array#== in order to handle comparison with
150
+ # ImmutableArray
151
+ #
152
+ # NOTE: do not do so for +eql?+
153
+
154
+ #:nodoc:
155
+ alias_method :old_equal, :==
156
+
157
+ undef :==
158
+
159
+ #:nodoc:
160
+ def ==(rhs)
161
+
162
+ return rhs == self if rhs.is_a? CLASP::Arguments::ImmutableArray
163
+
164
+ old_equal rhs
165
+ end
166
+ end
167
+
168
+ # ############################## end of file ############################# #
169
+
data/lib/clasp/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for CLASP.Ruby library
6
6
  #
7
7
  # Created: 16th November 2014
8
- # Updated: 26th June 2016
8
+ # Updated: 16th July 2016
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/CLASP.Ruby
11
11
  #
@@ -51,7 +51,7 @@
51
51
  module CLASP
52
52
 
53
53
  # Current version of the CLASP.Ruby library
54
- VERSION = '0.10.3'
54
+ VERSION = '0.11.1'
55
55
 
56
56
  private
57
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
4
+
5
+ require 'clasp'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_ImmutableArray < Test::Unit::TestCase
10
+
11
+ ImmutableArray = ::CLASP::Arguments::ImmutableArray
12
+
13
+ def test_empty
14
+
15
+ ia = ImmutableArray.new []
16
+
17
+ assert ia.empty?
18
+ assert_equal 0, ia.size
19
+ assert_equal 0, ia.length
20
+ assert_equal 0, ia.count
21
+ assert_equal 0, ia.count(:abc)
22
+ assert_equal 0, ia.count { |o| !o.nil? }
23
+ assert (ia.find { |o| !o.nil? }).nil?
24
+ assert_equal ImmutableArray.new([]), ia
25
+ assert_not_equal ImmutableArray.new([ :def ]), ia
26
+ assert_not_equal ImmutableArray.new([ :abc, :def ]), ia
27
+ assert ia[0].nil?
28
+ assert ia[1].nil?
29
+ assert_equal ImmutableArray.new([]), ia[0..1]
30
+ end
31
+
32
+ def test_one_item
33
+
34
+ ia = ImmutableArray.new [ :def ]
35
+
36
+ assert !ia.empty?
37
+ assert_equal 1, ia.size
38
+ assert_equal 1, ia.length
39
+ assert_equal 1, ia.count
40
+ assert_equal 0, ia.count(:abc)
41
+ assert_equal 1, ia.count { |o| !o.nil? }
42
+ assert !(ia.find { |o| !o.nil? }).nil?
43
+ assert_not_equal ImmutableArray.new([]), ia
44
+ assert_equal ImmutableArray.new([ :def ]), ia
45
+ assert_not_equal ImmutableArray.new([ :abc, :def ]), ia
46
+ assert_equal :def, ia[0]
47
+ assert ia[1].nil?
48
+ assert_equal ImmutableArray.new([ :def ]), ia[0..1]
49
+ end
50
+
51
+ def test_two_items
52
+
53
+ ia = ImmutableArray.new [ :abc, :def ]
54
+
55
+ assert !ia.empty?
56
+ assert_equal 2, ia.size
57
+ assert_equal 2, ia.length
58
+ assert_equal 2, ia.count
59
+ assert_equal 1, ia.count(:abc)
60
+ assert_equal 2, ia.count { |o| !o.nil? }
61
+ assert !(ia.find { |o| !o.nil? }).nil?
62
+ assert_not_equal ImmutableArray.new([]), ia
63
+ assert_not_equal ImmutableArray.new([ :def ]), ia
64
+ assert_equal ImmutableArray.new([ :abc, :def ]), ia
65
+ assert_equal :abc, ia[0]
66
+ assert_equal :def, ia[1]
67
+ assert_equal ImmutableArray.new([ :abc, :def ]), ia[0..1]
68
+ end
69
+ end
70
+
71
+ # ############################## end of file ############################# #
72
+
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
4
+
5
+ require 'clasp'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_Util_ImmutableArray < Test::Unit::TestCase
10
+
11
+ include ::CLASP::Util
12
+
13
+ def test_empty
14
+
15
+ ia = ImmutableArray.new []
16
+
17
+ assert ia.empty?
18
+ assert_equal 0, ia.size
19
+ assert_equal 0, ia.length
20
+ assert_equal 0, ia.count
21
+ assert_equal 0, ia.count(:abc)
22
+ assert_equal 0, ia.count { |o| !o.nil? }
23
+ assert (ia.find { |o| !o.nil? }).nil?
24
+ assert_equal ImmutableArray.new([]), ia
25
+ assert_not_equal ImmutableArray.new([ :def ]), ia
26
+ assert_not_equal ImmutableArray.new([ :abc, :def ]), ia
27
+ assert ia[0].nil?
28
+ assert ia[1].nil?
29
+ assert_equal ImmutableArray.new([]), ia[0..1]
30
+ end
31
+
32
+ def test_one_item
33
+
34
+ ia = ImmutableArray.new [ :def ]
35
+
36
+ assert !ia.empty?
37
+ assert_equal 1, ia.size
38
+ assert_equal 1, ia.length
39
+ assert_equal 1, ia.count
40
+ assert_equal 0, ia.count(:abc)
41
+ assert_equal 1, ia.count { |o| !o.nil? }
42
+ assert !(ia.find { |o| !o.nil? }).nil?
43
+ assert_not_equal ImmutableArray.new([]), ia
44
+ assert_equal ImmutableArray.new([ :def ]), ia
45
+ assert_not_equal ImmutableArray.new([ :abc, :def ]), ia
46
+ assert_equal :def, ia[0]
47
+ assert ia[1].nil?
48
+ assert_equal ImmutableArray.new([ :def ]), ia[0..1]
49
+ end
50
+
51
+ def test_two_items
52
+
53
+ ia = ImmutableArray.new [ :abc, :def ]
54
+
55
+ assert !ia.empty?
56
+ assert_equal 2, ia.size
57
+ assert_equal 2, ia.length
58
+ assert_equal 2, ia.count
59
+ assert_equal 1, ia.count(:abc)
60
+ assert_equal 2, ia.count { |o| !o.nil? }
61
+ assert !(ia.find { |o| !o.nil? }).nil?
62
+ assert_not_equal ImmutableArray.new([]), ia
63
+ assert_not_equal ImmutableArray.new([ :def ]), ia
64
+ assert_equal ImmutableArray.new([ :abc, :def ]), ia
65
+ assert_equal :abc, ia[0]
66
+ assert_equal :def, ia[1]
67
+ assert_equal ImmutableArray.new([ :abc, :def ]), ia[0..1]
68
+ end
69
+ end
70
+
71
+ # ############################## end of file ############################# #
72
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clasp-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-16 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Command-Line Argument Sorting and Parsing library that provides a powerful
@@ -29,6 +29,7 @@ files:
29
29
  - lib/clasp/cli.rb
30
30
  - lib/clasp/doc_.rb
31
31
  - lib/clasp/old_module.rb
32
+ - lib/clasp/util/immutable_array.rb
32
33
  - lib/clasp/version.rb
33
34
  - test/scratch/test_aliases.rb
34
35
  - test/scratch/test_list_command_line.rb
@@ -41,7 +42,9 @@ files:
41
42
  - test/unit/tc_arguments_3.rb
42
43
  - test/unit/tc_defaults_1.rb
43
44
  - test/unit/tc_examples_Arguments.rb
45
+ - test/unit/tc_immutable_array.rb
44
46
  - test/unit/tc_usage.rb
47
+ - test/unit/tc_util_immutable_array.rb
45
48
  - test/unit/ts_all.rb
46
49
  homepage: http://github.com/synesissoftware/CLASP.Ruby
47
50
  licenses: