dreck 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 50f32193f86f5b00b6d9a76ee3ff5e88108d60b9
4
- data.tar.gz: 7a272d6f3e0178929973d3f1fc7cf8d3c8a84240
3
+ metadata.gz: 9668c3e8314c8998e12acbf57edbcbdd24131b96
4
+ data.tar.gz: e0df1442d96e40ff4a6c6ed69dfdc2ebd3dbeb57
5
5
  SHA512:
6
- metadata.gz: 1658a420eebf35e0c52a053aa422b743ca92564c6ad4e85fcd52740175173c9aeaeaa70808d38e83a901ffaec8c3bc8ff731ad64faed81ef4e696cecef0bae4c
7
- data.tar.gz: e2dbfdf5b22e7b285d28f8570b8b9c270ccc2cf14639c0e7d202aff6e573d72839009599d1e287caa9d3cb7f8327a808f80a9cba8ead523a8aa6eb23ab474ae4
6
+ metadata.gz: f02e2a2ad89d1b13822a78a28802572ac750a1a750922d0ba4c00a3a041027bd6cef0ed98f25b360f6a77acb70a610dcf85f402d19aa218831e5d5f20fd08b21
7
+ data.tar.gz: 74313791854a9b9535823bca0967adf04601e7d5ab584e1f437144e6b1109347f5e9b863e37f7152644239fe8378f8cf8852ce80a8f4fc96260945dffc53860a
@@ -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.4"
8
+ VERSION = "0.0.5"
9
9
 
10
10
  # Parse the given arguments and produce a result.
11
11
  # @param args [Array<String>] the arguments to parse
@@ -8,9 +8,13 @@ module Dreck
8
8
  # Raised during argument absorption if arguments are either left over
9
9
  # or are insufficient to populate the expected results.
10
10
  class AbsorptionError < DreckError
11
- def initialize(actual, expected)
11
+ # @param actual [Integer] the actual number of arguments given
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)
12
15
  nmany = actual > expected ? "too few" : "too many"
13
- super "#{nmany} arguments given (#{actual}, expected #{expected})"
16
+ exp = greedy ? ">#{actual}" : expected
17
+ super "#{nmany} arguments given (#{actual}, expected #{exp})"
14
18
  end
15
19
  end
16
20
 
@@ -68,10 +68,12 @@ module Dreck
68
68
  # @raise [AbsoptionError] if absorption fails and {strict?} is not true
69
69
  # @api private
70
70
  def check_absorption!
71
- count = count_expected
71
+ count, greedy = count_expected
72
72
 
73
- return if count.nil?
74
- raise AbsorptionError.new(count, @args.size) if count != @args.size && strict?
73
+ return if greedy && @args.size >= count
74
+ return unless strict?
75
+
76
+ raise AbsorptionError.new(count, @args.size, greedy) if count != @args.size
75
77
  end
76
78
 
77
79
  # Count the number of arguments expected to be supplied.
@@ -79,17 +81,19 @@ module Dreck
79
81
  # of indeterminate size is specified
80
82
  # @api private
81
83
  def count_expected
82
- @expected.inject(0) do |n, exp|
84
+ count = @expected.inject(0) do |n, exp|
83
85
  case exp.first
84
86
  when :list
85
87
  # if the list is greedy, all arguments have to be absorbed
86
- break unless exp[3]
88
+ return [n, true] unless exp[3]
87
89
 
88
90
  n + exp[3]
89
91
  else
90
92
  n + 1
91
93
  end
92
94
  end
95
+
96
+ [count, false]
93
97
  end
94
98
 
95
99
  # Parse a one or more expected arguments of a given type and add them to
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.4
4
+ version: 0.0.5
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-23 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Typechecks and coerces non-option arguments.
14
14
  email: william@tuffbizz.com