squared 0.7.2 → 0.7.3

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.
@@ -49,10 +49,10 @@ module Squared
49
49
  ret.map! do |val|
50
50
  next val if opt?(val)
51
51
 
52
- if quote || val.is_a?(Pathname)
53
- shell_quote(val, force: force, double: double)
54
- elsif escape
52
+ if !(pa = val.is_a?(Pathname)) && escape
55
53
  shell_escape(val, quote: quote, double: double)
54
+ elsif quote || pa
55
+ shell_quote(val, force: force, double: double)
56
56
  else
57
57
  val
58
58
  end
@@ -153,7 +153,7 @@ module Squared
153
153
 
154
154
  def pattern?(val)
155
155
  val.start_with?('\A', '^') || val.end_with?('\z', '$') ||
156
- val.match?(/[.)][*+?]|\(\?:|\\[dsw\d]|\[.+\]|\{\d+,?\d*\}/i)
156
+ val.match?(/[.)][*+?]|\(\?[:=!><]|\\[dsw\d]|\[.+\]|\{\d+,?\d*\}/i)
157
157
  end
158
158
 
159
159
  private
@@ -362,7 +362,7 @@ module Squared
362
362
  push opt
363
363
  skip = true if args
364
364
  end
365
- skip = true if first&.any? { |s| s.is_a?(Regexp) ? opt.match?(s) : !opt.include?(s) }
365
+ skip = true if first&.any? { |pat| pat.is_a?(Regexp) ? opt.match?(pat) : !opt.include?(pat) }
366
366
  end
367
367
  end
368
368
  @values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})#{sep}(.+)\z/m
@@ -388,7 +388,8 @@ module Squared
388
388
  self
389
389
  end
390
390
 
391
- def append_any(*args, escape: false, quote: true, **kwargs)
391
+ def append_any(*args, escape: false, **kwargs)
392
+ quote = kwargs.fetch(:quote, true)
392
393
  (args.empty? ? extras : args.flatten(1)).each do |val|
393
394
  if block_given?
394
395
  temp = val
@@ -396,7 +397,7 @@ module Squared
396
397
  if val.is_a?(Array)
397
398
  found << temp
398
399
  k, v, q = val
399
- add_option(k, v, escape: escape, quote: quote, double: q == '"', merge: q == true, **kwargs)
400
+ add_option(k, v, escape: escape, double: q == '"', merge: q == true, **kwargs)
400
401
  next
401
402
  end
402
403
  end
@@ -404,10 +405,10 @@ module Squared
404
405
 
405
406
  if exist?(val)
406
407
  add_path(val, **kwargs)
407
- elsif quote
408
- add_quote(val, **kwargs)
409
408
  elsif escape
410
409
  add shell_escape(val, **kwargs)
410
+ elsif quote
411
+ add_quote(val, **kwargs)
411
412
  else
412
413
  add val
413
414
  end
@@ -521,7 +522,7 @@ module Squared
521
522
 
522
523
  def add_path(*args, option: nil, force: true, double: false, **kwargs)
523
524
  if args.empty?
524
- list = select { |val| val.is_a?(String) }
525
+ list = grep(String)
525
526
  found.concat(list)
526
527
  list.map! { |val| path + val } if path
527
528
  append(list, force: force, **kwargs)
@@ -537,6 +538,7 @@ module Squared
537
538
  end
538
539
 
539
540
  def add_quote(*args, **kwargs)
541
+ kwargs.delete(:quote)
540
542
  merge(args.compact.map { |s| s == '--' || OptionPartition.opt?(s) ? s : shell_quote(s, **kwargs) })
541
543
  self
542
544
  end
@@ -546,8 +548,8 @@ module Squared
546
548
  self
547
549
  end
548
550
 
549
- def add_first(fallback = nil, prefix: nil, path: false, escape: false, quote: false, reverse: false,
550
- expect: false, **kwargs)
551
+ def add_first(fallback = nil, prefix: nil, path: false, escape: false, reverse: false, expect: false,
552
+ **kwargs)
551
553
  val = (reverse ? pop : shift) || fallback
552
554
  if val
553
555
  temp = val
@@ -555,10 +557,10 @@ module Squared
555
557
  unless block_given? && !(val = yield val).is_a?(String)
556
558
  if path
557
559
  add_path(val, **kwargs)
558
- elsif quote
559
- add_quote(val, **kwargs)
560
560
  elsif escape
561
561
  add shell_escape(val, **kwargs)
562
+ elsif kwargs[:quote]
563
+ add_quote(val, **kwargs)
562
564
  else
563
565
  add val
564
566
  end
@@ -669,7 +671,7 @@ module Squared
669
671
  end
670
672
 
671
673
  def exist?(*args, add: false, first: false, last: false, glob: false)
672
- return with_glob?(File.join(*args), glob) unless args.empty?
674
+ return !args.first.nil? && with_glob?(File.join(*args), glob) unless args.empty?
673
675
 
674
676
  if first || last
675
677
  return false unless (val = first ? self.first : self.last)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham