tins 1.19.0 → 1.20.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
  SHA256:
3
- metadata.gz: c162dc3ce6ee0fe3d5cc14201c0ef65a9d0cebca7d9a30216f2d0749ed259acf
4
- data.tar.gz: 77b5ff9739a7909fe05166e3a8ed251356992439f5d0089d1b600f56a1d8e90e
3
+ metadata.gz: 6ef6d2f0b36fcd36a9e2d04a93734e2344f34b3e7fbb7cf338e5d96c4a956b2f
4
+ data.tar.gz: 336a0db38796155a2561e55ac4c631730c179f1246045b1161cdd5a32e197c6a
5
5
  SHA512:
6
- metadata.gz: edac0fbe5c2e439d67e0aa1bddb126f97f90c7184b3677c1d8e8cc9ef63bf1233ecf481698a9d70d677be2ef0ce9440a6c8daae68cd87eeb78237ee3d6b847f4
7
- data.tar.gz: e215a79e72afbae06ed880c26de22c597483243c78fa7612479705348370da5c069ad93e3d4b0aff855ddf3fd65eb3811a5064e81f27f4c5d9d9f92ff59028e8
6
+ metadata.gz: 53f6a410165371cb96139274549b0dff25f33c538aca7e71adf62e36b2c7bd94bef7c4f321de7321faea9eb220deceac8479a0a1c02fe96a438c92691d22f215
7
+ data.tar.gz: 67c04f5f1c9804b574ef4af508cf2ae814da283a9bed1714413274d4ca91b8fe10f798672ec58813362f50bb13c3c4cf8aab9ad2726fae66def4a6048f33f8cf
data/README.md CHANGED
@@ -12,7 +12,10 @@ Non yet.
12
12
 
13
13
  ## Changes
14
14
 
15
- * * 2018-11-07 Release 1.19.0
15
+
16
+ * 2018-11-14 Release 1.20.0
17
+ - Support default arguments in Tins::GO#go method.
18
+ * 2018-11-07 Release 1.19.0
16
19
  - Allow annotations without arguments
17
20
  * 2018-11-02 Release 1.18.0
18
21
  - `thread_local` and `thread_global` with default block
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.19.0
1
+ 1.20.0
@@ -22,14 +22,35 @@ module Tins
22
22
  # 'xy:' an option '-x' without an option argument is searched, and an
23
23
  # option '-y foo' with an option argument ('foo').
24
24
  #
25
+ # The _defaults_ argument specifies default values for the options.
26
+ #
25
27
  # An option hash is returned with all found options set to true or the
26
28
  # found option argument.
27
- def go(s, args = ARGV)
29
+ def go(s, args = ARGV, defaults: {})
30
+ d = defaults || {}
28
31
  b, v = s.scan(/(.)(:?)/).inject([ {}, {} ]) { |t, (o, a)|
29
32
  a = a == ':'
30
33
  t[a ? 1 : 0][o] = a ? nil : false
31
34
  t
32
35
  }
36
+ b.each_key do |k|
37
+ d.key?(k) or next
38
+ if [ 0, false, nil ].include?(d[k])
39
+ b[k] = false
40
+ elsif d[k].respond_to?(:to_int)
41
+ b[k] = d[k].to_int
42
+ else
43
+ b[k] = 1
44
+ end
45
+ end
46
+ v.each_key do |k|
47
+ d.key?(k) or next
48
+ if [ 0, false, nil ].include?(d[k])
49
+ v[k] = nil
50
+ else
51
+ v[k] = d[k].to_s
52
+ end
53
+ end
33
54
  r = []
34
55
  while a = args.shift
35
56
  /\A-(?<p>.+)/ =~ a or (r << a; next)
@@ -44,7 +65,7 @@ module Tins
44
65
  else
45
66
  a = p
46
67
  end
47
- if v[o].nil?
68
+ if v[o].nil? || !(EnumerableExtension === v[o])
48
69
  a = a.dup
49
70
  a.extend EnumerableExtension
50
71
  a << a
@@ -1,6 +1,6 @@
1
1
  module Tins
2
2
  # Tins version
3
- VERSION = '1.19.0'
3
+ VERSION = '1.20.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -58,5 +58,20 @@ module Tins
58
58
  assert_equal({ 'a' => 1, 'b' => 'hello', 'e' => nil }, r)
59
59
  assert_equal [], args
60
60
  end
61
+
62
+ def test_defaults
63
+ r = go('bv:', args = %w[ -v bar ], defaults: { ?b => true, ?v => 'foo' })
64
+ assert_equal({ ?b => 1, 'v' => 'bar' }, r)
65
+ assert_equal [], args
66
+ r = go('bv:', args = %w[ -b -v bar ], defaults: { ?b => 22, ?v => 'foo' })
67
+ assert_equal({ ?b => 23, 'v' => 'bar' }, r)
68
+ assert_equal [], args
69
+ r = go('bv:', args = %w[ -b ], defaults: { ?b => false, ?v => 'foo' })
70
+ assert_equal({ ?b => 1, 'v' => 'foo' }, r)
71
+ assert_equal [], args
72
+ r = go('bv:', args = %w[ ], defaults: { ?b => false, ?v => 'foo' })
73
+ assert_equal({ ?b => false, 'v' => 'foo' }, r)
74
+ assert_equal [], args
75
+ end
61
76
  end
62
77
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: tins 1.19.0 ruby lib
2
+ # stub: tins 1.20.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "tins".freeze
6
- s.version = "1.19.0"
6
+ s.version = "1.20.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2018-11-07"
11
+ s.date = "2018-11-14"
12
12
  s.description = "All the stuff that isn't good/big enough for a real library.".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.extra_rdoc_files = ["README.md".freeze, "lib/dslkit.rb".freeze, "lib/dslkit/polite.rb".freeze, "lib/dslkit/rude.rb".freeze, "lib/spruz.rb".freeze, "lib/tins.rb".freeze, "lib/tins/alias.rb".freeze, "lib/tins/annotate.rb".freeze, "lib/tins/ask_and_send.rb".freeze, "lib/tins/attempt.rb".freeze, "lib/tins/bijection.rb".freeze, "lib/tins/case_predicate.rb".freeze, "lib/tins/complete.rb".freeze, "lib/tins/concern.rb".freeze, "lib/tins/count_by.rb".freeze, "lib/tins/date_dummy.rb".freeze, "lib/tins/date_time_dummy.rb".freeze, "lib/tins/deep_const_get.rb".freeze, "lib/tins/deep_dup.rb".freeze, "lib/tins/dslkit.rb".freeze, "lib/tins/duration.rb".freeze, "lib/tins/expose.rb".freeze, "lib/tins/extract_last_argument_options.rb".freeze, "lib/tins/file_binary.rb".freeze, "lib/tins/find.rb".freeze, "lib/tins/generator.rb".freeze, "lib/tins/go.rb".freeze, "lib/tins/hash_symbolize_keys_recursive.rb".freeze, "lib/tins/hash_union.rb".freeze, "lib/tins/if_predicate.rb".freeze, "lib/tins/implement.rb".freeze, "lib/tins/limited.rb".freeze, "lib/tins/lines_file.rb".freeze, "lib/tins/memoize.rb".freeze, "lib/tins/method_description.rb".freeze, "lib/tins/minimize.rb".freeze, "lib/tins/module_group.rb".freeze, "lib/tins/named_set.rb".freeze, "lib/tins/null.rb".freeze, "lib/tins/once.rb".freeze, "lib/tins/p.rb".freeze, "lib/tins/partial_application.rb".freeze, "lib/tins/proc_compose.rb".freeze, "lib/tins/proc_prelude.rb".freeze, "lib/tins/range_plus.rb".freeze, "lib/tins/require_maybe.rb".freeze, "lib/tins/responding.rb".freeze, "lib/tins/secure_write.rb".freeze, "lib/tins/sexy_singleton.rb".freeze, "lib/tins/string_byte_order_mark.rb".freeze, "lib/tins/string_camelize.rb".freeze, "lib/tins/string_underscore.rb".freeze, "lib/tins/string_version.rb".freeze, "lib/tins/subhash.rb".freeze, "lib/tins/temp_io.rb".freeze, "lib/tins/temp_io_enum.rb".freeze, "lib/tins/terminal.rb".freeze, "lib/tins/thread_local.rb".freeze, "lib/tins/time_dummy.rb".freeze, "lib/tins/to.rb".freeze, "lib/tins/to_proc.rb".freeze, "lib/tins/token.rb".freeze, "lib/tins/uniq_by.rb".freeze, "lib/tins/unit.rb".freeze, "lib/tins/version.rb".freeze, "lib/tins/write.rb".freeze, "lib/tins/xt.rb".freeze, "lib/tins/xt/annotate.rb".freeze, "lib/tins/xt/ask_and_send.rb".freeze, "lib/tins/xt/attempt.rb".freeze, "lib/tins/xt/blank.rb".freeze, "lib/tins/xt/case_predicate.rb".freeze, "lib/tins/xt/complete.rb".freeze, "lib/tins/xt/concern.rb".freeze, "lib/tins/xt/count_by.rb".freeze, "lib/tins/xt/date_dummy.rb".freeze, "lib/tins/xt/date_time_dummy.rb".freeze, "lib/tins/xt/deep_const_get.rb".freeze, "lib/tins/xt/deep_dup.rb".freeze, "lib/tins/xt/dslkit.rb".freeze, "lib/tins/xt/expose.rb".freeze, "lib/tins/xt/extract_last_argument_options.rb".freeze, "lib/tins/xt/file_binary.rb".freeze, "lib/tins/xt/full.rb".freeze, "lib/tins/xt/hash_symbolize_keys_recursive.rb".freeze, "lib/tins/xt/hash_union.rb".freeze, "lib/tins/xt/if_predicate.rb".freeze, "lib/tins/xt/implement.rb".freeze, "lib/tins/xt/irb.rb".freeze, "lib/tins/xt/method_description.rb".freeze, "lib/tins/xt/named.rb".freeze, "lib/tins/xt/null.rb".freeze, "lib/tins/xt/p.rb".freeze, "lib/tins/xt/partial_application.rb".freeze, "lib/tins/xt/proc_compose.rb".freeze, "lib/tins/xt/proc_prelude.rb".freeze, "lib/tins/xt/range_plus.rb".freeze, "lib/tins/xt/require_maybe.rb".freeze, "lib/tins/xt/responding.rb".freeze, "lib/tins/xt/secure_write.rb".freeze, "lib/tins/xt/sexy_singleton.rb".freeze, "lib/tins/xt/string.rb".freeze, "lib/tins/xt/string_byte_order_mark.rb".freeze, "lib/tins/xt/string_camelize.rb".freeze, "lib/tins/xt/string_underscore.rb".freeze, "lib/tins/xt/string_version.rb".freeze, "lib/tins/xt/subhash.rb".freeze, "lib/tins/xt/temp_io.rb".freeze, "lib/tins/xt/time_dummy.rb".freeze, "lib/tins/xt/time_freezer.rb".freeze, "lib/tins/xt/to.rb".freeze, "lib/tins/xt/uniq_by.rb".freeze, "lib/tins/xt/write.rb".freeze]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-07 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar