scout-essentials 1.6.3 → 1.6.5

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: 8ff597b1b0d5a5a8582e92677aa951559d3ddf2f56cec76bbbfd5f0c90ea180e
4
- data.tar.gz: 298441b06d0c2d048732fa7fb525a51c4ff93a31e39b1882211048f06978c1b9
3
+ metadata.gz: e5c16f695461037137552a5dc43c5135eae7873176ae2bc9495e9c0ed7fdbf0b
4
+ data.tar.gz: 6bea89686ff4be00f385757cf2d4e96aa15c973253432244eb7c0412c7977365
5
5
  SHA512:
6
- metadata.gz: 91c63f92b747ea2c39b291430b8a63a7db63bf28465eb66b5d7cceda88f07ceaefef1c7718a589bd5f8f040ff082f9a90232edfa16d4c28a5ba75877ac5a34b9
7
- data.tar.gz: 10d3e562974232b7fe87954a6970cc9008799e341d2bb01e454406d3ceec5386bb27542dcc8b6622a27fd5382d29320561766b1abfd0467eee939d7c82af0a84
6
+ metadata.gz: 10864ea7dc1d73802a5c4bdc4f48f48434f3d610c4efef5df281f0d34b38eae366329673daff86756242ca43cee792ba76c8c8f590d0ed030c0c77c645eb4a58
7
+ data.tar.gz: 6d2d19fa54ee2ab3c3130310f54feb080713a53f41a69a99debed28e69f127e7e1596eb99a0e715f4a6af5f89af78c86d8c189cc94afef6427c5802962c12c1f
data/.vimproject CHANGED
@@ -34,6 +34,11 @@ scout-essentials=/$PWD filter="*.rb *.txt *.md *.conf *.yaml" {
34
34
  color_class.rb
35
35
  fingerprint.rb
36
36
  progress.rb
37
+ progress=progress{
38
+ report.rb
39
+ util.rb
40
+ }
41
+
37
42
  trap.rb
38
43
  }
39
44
  tmpfile.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.3
1
+ 1.6.5
@@ -1,9 +1,5 @@
1
1
  module Annotation
2
2
  module AnnotatedObject
3
- def annotations
4
- @annotations ||= []
5
- end
6
-
7
3
  def annotation_types
8
4
  @annotation_types ||= []
9
5
  end
@@ -34,7 +34,11 @@ module Annotation
34
34
  end
35
35
  obj = block if obj.nil?
36
36
  return nil if obj.nil?
37
- obj.extend self unless self === obj
37
+ begin
38
+ obj.extend self unless self === obj
39
+ rescue TypeError
40
+ return obj
41
+ end
38
42
  attrs = self.instance_variable_get("@annotations")
39
43
 
40
44
  return obj if attrs.nil? || attrs.empty?
@@ -34,7 +34,7 @@ module AnnotatedArray
34
34
 
35
35
  def each_with_index(&block)
36
36
  super do |item,i|
37
- block.call annotate_item(item, i)
37
+ block.call annotate_item(item, i), i
38
38
  end
39
39
  end
40
40
 
@@ -70,6 +70,14 @@ module AnnotatedArray
70
70
  end
71
71
  end
72
72
 
73
+ def subset(list)
74
+ self.annotate(self & list)
75
+ end
76
+
77
+ def remove(list)
78
+ self.annotate(self - list)
79
+ end
80
+
73
81
  %w(compact uniq flatten reverse sort_by).each do |method|
74
82
 
75
83
  self.define_method(method) do |*args,&block|
@@ -9,8 +9,12 @@ module Annotation
9
9
  annotation_types = annotation_types.split("|") if String === annotation_types
10
10
  annotation_types = [annotation_types] unless Array === annotation_types
11
11
  annotation_types.each do |type|
12
- type = Kernel.const_get(type) if String === type
13
- type.setup(obj, annotation_hash)
12
+ begin
13
+ type = Kernel.const_get(type) if String === type
14
+ type.setup(obj, annotation_hash)
15
+ rescue NameError
16
+ Log.warn "Annotation #{type} not defined"
17
+ end
14
18
  end
15
19
  obj
16
20
  end
@@ -29,7 +29,9 @@ module IndiferentHash
29
29
 
30
30
  def self.pull_keys(hash, prefix)
31
31
  IndiferentHash.setup(hash)
32
- new = hash.include?("#{prefix}_options") ? hash.delete("#{prefix}_options") : {}
32
+ new = hash.delete("#{prefix}_options") if hash.include?("#{prefix}_options")
33
+ new = {} if new.nil?
34
+ IndiferentHash.setup(new)
33
35
  prefix = prefix.to_s
34
36
  hash.keys.each do |key|
35
37
  if key.to_s =~ /#{ prefix }_(.*)/
@@ -45,8 +47,7 @@ module IndiferentHash
45
47
  end
46
48
  end
47
49
  end
48
-
49
- IndiferentHash.setup(new)
50
+ new
50
51
  end
51
52
 
52
53
  def self.zip2hash(list1, list2)
@@ -17,6 +17,19 @@ module IndiferentHash
17
17
  new
18
18
  end
19
19
 
20
+ def deep_merge(other)
21
+ new = self.dup
22
+ IndiferentHash.setup(new)
23
+ other.each do |k,value|
24
+ if new.include?(k) && IndiferentHash === new[k] && Hash === value
25
+ new[k] = new[k].deep_merge(value)
26
+ else
27
+ new[k] = value
28
+ end
29
+ end
30
+ new
31
+ end
32
+
20
33
  def []=(key,value)
21
34
  delete(key)
22
35
  super(key,value)
@@ -28,16 +41,22 @@ module IndiferentHash
28
41
 
29
42
  def [](key)
30
43
  res = super(key)
31
- return res unless res.nil? or (_default? and not keys.include? key)
32
44
 
33
- case key
34
- when Symbol, Module
35
- super(key.to_s)
36
- when String
37
- super(key.to_sym)
38
- else
39
- res
45
+ if ! (res.nil? || (_default? and not keys.include?(key)))
46
+ IndiferentHash.setup(res) if Hash === res
47
+ return res
40
48
  end
49
+
50
+ res = case key
51
+ when Symbol, Module
52
+ super(key.to_s)
53
+ when String
54
+ super(key.to_sym)
55
+ else
56
+ res
57
+ end
58
+ IndiferentHash.setup(res) if Hash === res
59
+ res
41
60
  end
42
61
 
43
62
  def values_at(*key_list)
@@ -92,5 +111,34 @@ module IndiferentHash
92
111
  end
93
112
  IndiferentHash.setup(super(*ext_list))
94
113
  end
114
+
115
+ def keys_to_sym!
116
+ string_keys = keys.select{|k| String === k}
117
+ string_keys.each do |key|
118
+ self[key.to_sym] = self.delete(key)
119
+ end
120
+ end
121
+
122
+ def prety_print
123
+ Misc.format_definition_list(self, sep: "\n")
124
+ end
125
+
126
+ def except(*list)
127
+ full_list = list.dup
128
+
129
+ list.each do |e|
130
+ begin
131
+ if String === e
132
+ full_list << e.to_sym
133
+ else
134
+ full_list << e.to_s
135
+ end
136
+ rescue
137
+ next
138
+ end
139
+ end
140
+
141
+ super(*full_list)
142
+ end
95
143
  end
96
144
 
data/lib/scout/log.rb CHANGED
@@ -252,14 +252,18 @@ module Log
252
252
  end
253
253
 
254
254
  def self.exception(e)
255
- stack = caller
255
+ return if e.message.include?("NOLOG")
256
+ last_caller = last_caller caller
257
+ message = e.message
258
+ message = Log.fingerprint(message) if String === message && message.length > 1000
256
259
  backtrace = e.backtrace || []
260
+ backtrace = [] if message.include?("NOSTACK")
257
261
  if ENV["SCOUT_ORIGINAL_STACK"] == 'true'
258
- error([e.class.to_s, e.message].compact * ": " )
259
- error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace)*"\n")
262
+ error([e.class.to_s, message].compact * ": " )
263
+ error("BACKTRACE [#{Process.pid}]: " << last_caller << "\n" + color_stack(backtrace)*"\n")
260
264
  else
261
- error("BACKTRACE [#{Process.pid}]: " << Log.last_caller(stack) << "\n" + color_stack(backtrace.reverse)*"\n")
262
- error([e.class.to_s, e.message].compact * ": " )
265
+ error("BACKTRACE [#{Process.pid}]: " << last_caller << "\n" + color_stack(backtrace.reverse)*"\n")
266
+ error([e.class.to_s, message].compact * ": " )
263
267
  end
264
268
  end
265
269
 
@@ -355,6 +359,7 @@ def ppp(message)
355
359
  stack = caller
356
360
  puts "#{Log.color :cyan, "PRINT:"} " << stack.first
357
361
  puts ""
362
+ message = message.prety_print if message.respond_to?(:prety_print)
358
363
  if message.length > 200 or message.include? "\n"
359
364
  puts Log.color(:cyan, "=>|") << "\n" << message.to_s
360
365
  else
@@ -72,7 +72,7 @@ module Misc
72
72
  end*""
73
73
  end
74
74
 
75
- def self.format_definition_list_item(dt, dd, indent = nil, size = nil, color = :yellow)
75
+ def self.format_definition_list_item(dt, dd, indent = nil, size = nil, color: :yellow)
76
76
  if size.nil?
77
77
  base_size = MAX_TTY_LINE_WIDTH
78
78
  base_indent = indent || (base_size / 3)
@@ -98,12 +98,12 @@ module Misc
98
98
  text
99
99
  end
100
100
 
101
- def self.format_definition_list(defs, indent = nil, size = nil, color = :yellow, sep = "\n\n")
101
+ def self.format_definition_list(defs, indent = nil, size = nil, color: :yellow, sep: "\n\n")
102
102
  indent ||= 30
103
103
  size ||= (Log.tty_size || MAX_TTY_LINE_WIDTH) - indent
104
104
  entries = []
105
105
  defs.each do |dt,dd|
106
- text = format_definition_list_item(dt,dd,indent, size,color)
106
+ text = format_definition_list_item(dt,dd,indent, size, color: color)
107
107
  entries << text
108
108
  end
109
109
  entries * sep
@@ -0,0 +1,44 @@
1
+ module Misc
2
+ def self._convert_match_condition(condition)
3
+ return true if condition == 'true'
4
+ return false if condition == 'false'
5
+ return condition.to_regexp if condition[0] == "/"
6
+ return [:cmp, $1, $2.to_f] if condition =~ /^([<>]=?)(.*)/
7
+ return [:invert, _convert_match_condition(condition[1..-1].strip)] if condition[0] == "!"
8
+ #return {$1 => $2.to_f} if condition =~ /^([<>]=?)(.*)/
9
+ #return {false => _convert_match_condition(condition[1..-1].strip)} if condition[0] == "!"
10
+ return condition
11
+ end
12
+
13
+ def self.match_value(value, condition)
14
+ condition = _convert_match_condition(condition.strip) if String === condition
15
+
16
+ case condition
17
+ when Regexp
18
+ !! value.match(condition)
19
+ when NilClass, TrueClass
20
+ value === TrueClass or (String === value and value.downcase == 'true')
21
+ when FalseClass
22
+ value === FalseClass or (String === value and value.downcase == 'false')
23
+ when String
24
+ Numeric === value ? value.to_f == condition.to_f : value == condition
25
+ when Numeric
26
+ value.to_f == condition.to_f
27
+ when Array
28
+ case condition.first
29
+ when :cmp
30
+ value.to_f.send(condition[1], condition[2])
31
+ when :invert
32
+ ! match_value(value, condition[1] )
33
+ else
34
+ condition.inject(false){|acc,e| acc = acc ? true : match_value(value, e) }
35
+ end
36
+ else
37
+ raise "Condition not understood: #{Misc.fingerprint condition}"
38
+ end
39
+ end
40
+
41
+ def self.tokenize(str)
42
+ str.scan(/"([^"]*)"|'([^']*)'|([^"'\s]+)/).flatten.compact
43
+ end
44
+ end
data/lib/scout/misc.rb CHANGED
@@ -5,6 +5,7 @@ require_relative 'misc/filesystem'
5
5
  require_relative 'misc/monitor'
6
6
  require_relative 'misc/system'
7
7
  require_relative 'misc/helper'
8
+ require_relative 'misc/matching'
8
9
  require_relative 'misc/math'
9
10
 
10
11
  module Misc
@@ -42,7 +42,7 @@ module NamedArray
42
42
  pos = names.index{|f| f.to_s == field }
43
43
  next pos if pos
44
44
  if field =~ /^\d+$/
45
- next identify_names(names, field.to_i)
45
+ next identify_name(names, field.to_i)
46
46
  end
47
47
  next pos if strict
48
48
  pos = names.index{|name| field_match(field, name) }
@@ -158,4 +158,8 @@ module NamedArray
158
158
  return super(name, *args)
159
159
  end
160
160
  end
161
+
162
+ def prety_print
163
+ Misc.format_definition_list(self.to_hash, sep: "\n")
164
+ end
161
165
  end
@@ -407,7 +407,8 @@ module Open
407
407
  str
408
408
  end
409
409
 
410
- def self.sort_stream(stream, header_hash: "#", cmd_args: "-u", memory: false)
410
+ def self.sort_stream(stream, header_hash: "#", cmd_args: nil, memory: false)
411
+ cmd_args = '-u' if cmd_args.nil?
411
412
  sout = Open.open_pipe do |sin|
412
413
  ConcurrentStream.process_stream(stream) do
413
414
  line = stream.gets
data/lib/scout/open.rb CHANGED
@@ -68,11 +68,11 @@ module Open
68
68
 
69
69
  options = IndiferentHash.add_defaults options, :noz => false, :mode => 'r'
70
70
 
71
- mode = IndiferentHash.process_options options, :mode
71
+ mode, grep, invert_grep, fixed_grep = IndiferentHash.process_options options, :mode, :grep, :invert_grep, :fixed_grep
72
72
 
73
73
  options[:noz] = true if mode.include? "w"
74
74
 
75
- io = file_open(file, options[:grep], mode, options[:invert_grep], options[:fixed_grep], options)
75
+ io = file_open(file, grep, mode, invert_grep, fixed_grep, options)
76
76
 
77
77
  io = unzip(io) if ((String === file and zip?(file)) and not options[:noz]) or options[:zip]
78
78
  io = gunzip(io) if ((String === file and gzip?(file)) and not options[:noz]) or options[:gzip]
@@ -82,6 +82,17 @@ module Path
82
82
  end.flatten.uniq
83
83
  end
84
84
 
85
+ def get_extension(multiple = false)
86
+ parts = File.basename(self).split(".")
87
+ extension = [parts.pop]
88
+
89
+ while parts.length < 5
90
+ extension << [parts.pop]
91
+ end if multiple
92
+
93
+ extension * "."
94
+ end
95
+
85
96
  def set_extension(extension)
86
97
  self.annotate(self + ".#{extension}")
87
98
  end
@@ -22,7 +22,7 @@ module Resource
22
22
  }.last
23
23
  end
24
24
 
25
- def has_rake(path)
25
+ def has_rake?(path)
26
26
  !! rake_for(path)
27
27
  end
28
28
 
@@ -34,6 +34,7 @@ module Resource
34
34
  rake_dir = rake_dir.find(:user) if rake_dir.respond_to? :find
35
35
 
36
36
  begin
37
+ Thread.current["resource"] = self
37
38
  if Proc === rakefile
38
39
  ScoutRake.run(nil, rake_dir, task, &rakefile)
39
40
  else
@@ -55,7 +56,7 @@ module Resource
55
56
  type, content = @resources[path]
56
57
  when (Path === path && @resources && @resources.include?(path.original))
57
58
  type, content = @resources[path.original]
58
- when has_rake(path)
59
+ when has_rake?(path)
59
60
  type = :rake
60
61
  rake_dir, content = rake_for(path)
61
62
  rake_dir = Path.setup(rake_dir.dup, self.pkgdir, self)
data/lib/scout/tmpfile.rb CHANGED
@@ -31,6 +31,7 @@ module TmpFile
31
31
  # Creates a random filename in the temporary directory
32
32
  def self.tmp_file(prefix = 'tmp-', max = 1_000_000_000, dir = nil)
33
33
  dir ||= TmpFile.tmpdir
34
+ dir = dir.find if Path === dir
34
35
  File.expand_path(File.join(dir, random_name(prefix, max)))
35
36
  end
36
37
 
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: scout-essentials 1.6.3 ruby lib
5
+ # stub: scout-essentials 1.6.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-essentials".freeze
9
- s.version = "1.6.3".freeze
9
+ s.version = "1.6.5".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Miguel Vazquez".freeze]
14
- s.date = "2024-10-04"
14
+ s.date = "2025-01-17"
15
15
  s.description = "Things a scout can use anywhere".freeze
16
16
  s.email = "mikisvaz@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
52
52
  "lib/scout/misc/format.rb",
53
53
  "lib/scout/misc/helper.rb",
54
54
  "lib/scout/misc/insist.rb",
55
+ "lib/scout/misc/matching.rb",
55
56
  "lib/scout/misc/math.rb",
56
57
  "lib/scout/misc/monitor.rb",
57
58
  "lib/scout/misc/system.rb",
@@ -90,7 +91,6 @@ Gem::Specification.new do |s|
90
91
  "share/color/color_names",
91
92
  "share/color/diverging_colors.hex",
92
93
  "share/software/install_helpers",
93
- "test/scout/annotation/test_annotated_object.rb",
94
94
  "test/scout/annotation/test_array.rb",
95
95
  "test/scout/indiferent_hash/test_case_insensitive.rb",
96
96
  "test/scout/indiferent_hash/test_options.rb",
@@ -101,6 +101,7 @@ Gem::Specification.new do |s|
101
101
  "test/scout/misc/test_filesystem.rb",
102
102
  "test/scout/misc/test_helper.rb",
103
103
  "test/scout/misc/test_insist.rb",
104
+ "test/scout/misc/test_matching.rb",
104
105
  "test/scout/misc/test_math.rb",
105
106
  "test/scout/misc/test_system.rb",
106
107
  "test/scout/open/test_lock.rb",
@@ -138,7 +139,7 @@ Gem::Specification.new do |s|
138
139
  ]
139
140
  s.homepage = "http://github.com/mikisvaz/scout-essentials".freeze
140
141
  s.licenses = ["MIT".freeze]
141
- s.rubygems_version = "3.5.10".freeze
142
+ s.rubygems_version = "3.5.23".freeze
142
143
  s.summary = "Scout essential tools".freeze
143
144
 
144
145
  s.specification_version = 4
@@ -0,0 +1,9 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMatches < Test::Unit::TestCase
5
+ def test_match_value
6
+ assert Misc.match_value('test', 'test')
7
+ end
8
+ end
9
+
@@ -22,5 +22,23 @@ class TestClass < Test::Unit::TestCase
22
22
  assert_equal 2, a["B"]
23
23
  assert_equal 2, a[:b]
24
24
  end
25
+
26
+ def test_deep_merge
27
+ o = {h: {a: 1, b: 2}}
28
+ n = {h: {c: 3}}
29
+
30
+ IndiferentHash.setup(o)
31
+ o = o.deep_merge(n)
32
+
33
+ assert_equal 1, o[:h]["a"]
34
+ assert_equal 3, o[:h]["c"]
35
+ end
36
+
37
+ def test_except
38
+ h = {:a => 1, "b" => 2}
39
+ IndiferentHash.setup(h)
40
+ assert_equal [:a], h.except(:b).keys
41
+ assert_equal ["b"], h.except("a").keys
42
+ end
25
43
  end
26
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2025-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -149,6 +149,7 @@ files:
149
149
  - lib/scout/misc/format.rb
150
150
  - lib/scout/misc/helper.rb
151
151
  - lib/scout/misc/insist.rb
152
+ - lib/scout/misc/matching.rb
152
153
  - lib/scout/misc/math.rb
153
154
  - lib/scout/misc/monitor.rb
154
155
  - lib/scout/misc/system.rb
@@ -187,7 +188,6 @@ files:
187
188
  - share/color/color_names
188
189
  - share/color/diverging_colors.hex
189
190
  - share/software/install_helpers
190
- - test/scout/annotation/test_annotated_object.rb
191
191
  - test/scout/annotation/test_array.rb
192
192
  - test/scout/indiferent_hash/test_case_insensitive.rb
193
193
  - test/scout/indiferent_hash/test_options.rb
@@ -198,6 +198,7 @@ files:
198
198
  - test/scout/misc/test_filesystem.rb
199
199
  - test/scout/misc/test_helper.rb
200
200
  - test/scout/misc/test_insist.rb
201
+ - test/scout/misc/test_matching.rb
201
202
  - test/scout/misc/test_math.rb
202
203
  - test/scout/misc/test_system.rb
203
204
  - test/scout/open/test_lock.rb
@@ -251,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
252
  - !ruby/object:Gem::Version
252
253
  version: '0'
253
254
  requirements: []
254
- rubygems_version: 3.5.10
255
+ rubygems_version: 3.5.23
255
256
  signing_key:
256
257
  specification_version: 4
257
258
  summary: Scout essential tools
File without changes