dreck 0.0.7 → 0.1.0

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: c92ebc35034ec54b87f763e6d2f080232cc5a4e1
4
- data.tar.gz: '00601982073b1ac4bd08e734c38967236773d167'
3
+ metadata.gz: 79881a5433a29683e6c61380f0a52a29ce443c13
4
+ data.tar.gz: 04e7ae02e53f85e3b86384e9ef055b0e3262776a
5
5
  SHA512:
6
- metadata.gz: c86759e00c6a8ad1bdfdfd414ed5bdc14303542994d2a47d813c00b2902e90f4eb8fc5158d7b08d94530037c287d9df86888386b4fe77242d507602bf9392710
7
- data.tar.gz: c7a2b7d64a0ddc6ac9fe8b39ff00fac601dde294e4e537fe1d208cfbeb01577bf000a6d5e86487c729ae7d6afd9d0984681e2e519e55db598fc8976f5d61993a
6
+ metadata.gz: 9a97e85038cc19205c7cc69c7534d9a8e189a72122b4983877f6aa758bf92ea88ad214869eef5d7c51fb54b6be1ad120a2f3f2744c29b7b937b0e950c461790b
7
+ data.tar.gz: a467df281d0b7e1c7b3c33a0a67482394915a40d623a47148d04b7e6cdba0773df00f4a7a7e53427b5dacd27299ebb1b1557001c96813d0313018dadb7113506
data/lib/dreck.rb CHANGED
@@ -5,7 +5,7 @@ require_relative "dreck/result"
5
5
  # The primary namespace for {Dreck}.
6
6
  module Dreck
7
7
  # {Dreck}'s current version.
8
- VERSION = "0.0.7"
8
+ VERSION = "0.1.0"
9
9
 
10
10
  # Parse the given arguments and produce a result.
11
11
  # @param args [Array<String>] the arguments to parse
@@ -10,12 +10,19 @@ module Dreck
10
10
  class AbsorptionError < DreckError
11
11
  # @param actual [Integer] the actual number of arguments given
12
12
  # @param expected [Integer] the expected number of arguments
13
- # @param greedy [Boolean] whether or not a list that absorbs the tail is present
14
- def initialize(actual, expected, greedy = false)
15
- nmany = actual > expected ? "too few" : "too many"
16
- act = greedy && actual > expected ? expected : actual
17
- exp = greedy ? ">=#{actual}" : expected
18
- super "#{nmany} arguments given (#{act}, expected #{exp})"
13
+ def initialize(actual, expected)
14
+ nmany = actual < expected ? "too few" : "too many"
15
+ super "#{nmany} arguments given (#{actual}, expected #{expected})"
16
+ end
17
+ end
18
+
19
+ # Raised during argument absorption if a greedy list was expected but all arguments
20
+ # have already been absorbed.
21
+ class GreedyAbsorptionError < DreckError
22
+ # @param actual [Integer] the actual number of arguments given
23
+ # @param expected [Integer] the expected number of arguments
24
+ def initialize(actual, expected)
25
+ super "too few arguments given (>#{actual}, expected >#{expected})"
19
26
  end
20
27
  end
21
28
 
data/lib/dreck/result.rb CHANGED
@@ -70,10 +70,10 @@ module Dreck
70
70
  def check_absorption!
71
71
  count, greedy = count_expected
72
72
 
73
- return if greedy && @args.size >= count
74
73
  return unless strict?
75
74
 
76
- raise AbsorptionError.new(count, @args.size, greedy) if count != @args.size
75
+ raise GreedyAbsorptionError.new(count, @args.size) if count >= @args.size && greedy
76
+ raise AbsorptionError.new(count, @args.size) if count != @args.size && !greedy
77
77
  end
78
78
 
79
79
  # Count the number of arguments expected to be supplied.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dreck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-30 00:00:00.000000000 Z
11
+ date: 2017-07-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Typechecks and coerces non-option arguments.
14
14
  email: william@tuffbizz.com