scout-essentials 1.1.0 → 1.2.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: a848d630e2eeffecaf053c2cd4a531e526edd32117fafd71c35833abdb41cc3b
4
- data.tar.gz: 8b18cd5f7c4819814aee3edbabcb88975b7cb635ae2e0b7c0fc87cf37fc3bd6d
3
+ metadata.gz: 0b0a00cab2e80f5ac221c5b89ba51ac9d2e179108523533ccff04bcffa28b621
4
+ data.tar.gz: 59658780d237328a638a962d9645de6994534015c932deddd7c7b55ddad394c5
5
5
  SHA512:
6
- metadata.gz: 52ef4a13bd1950d21dcad55fa0b5811521388b276ba11908f88e1e2bd13cd9658320591eb83aa689c7d62f724104c28706449c38e1dd79877882268893fe3cea
7
- data.tar.gz: b412f4e6b21198aaaaaabdb87908e9e5222fab838d32f4666d33e336b497b23990ac5db1e7236cc89c0a6b79fab4d9435c21f0d5202537620d1bcb66089c136a
6
+ metadata.gz: 88d48ab2416e00f99db24211774c93841e3aab8bbe14d9a495358f77771aaf3fa03e08d9864a81e5e9818de13bc0bcafe94e975a2d8186312909dc1934750906
7
+ data.tar.gz: 2cdc543433977a1901f6cc15ad92d30acbb3718bc70919829912083f4cd71e8e18fe9bc63bc396625a78946d15450802b38fd564f6ba63dcd8b2723393db4d84
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -1,5 +1,8 @@
1
1
  require 'digest/md5'
2
2
  module Log
3
+ FP_MAX_STRING = 150
4
+ FP_MAX_ARRAY = 20
5
+ FP_MAX_HASH = 10
3
6
  def self.fingerprint(obj)
4
7
  return obj.fingerprint if obj.respond_to?(:fingerprint)
5
8
 
@@ -13,9 +16,11 @@ module Log
13
16
  when Symbol
14
17
  ":" << obj.to_s
15
18
  when String
16
- if obj.length > 100
19
+ if obj.length > FP_MAX_STRING
17
20
  digest = Digest::MD5.hexdigest(obj)
18
- "'" << obj.slice(0,30) << "<...#{obj.length} - #{digest[0..4]}...>" << obj.slice(-10,30)<< "'"
21
+ middle = "<...#{obj.length} - #{digest[0..4]}...>"
22
+ s = (FP_MAX_STRING - middle.length) / 2
23
+ "'" << obj.slice(0,s-1) << middle << obj.slice(-s, obj.length )<< "'"
19
24
  else
20
25
  "'" << obj << "'"
21
26
  end
@@ -28,13 +33,13 @@ module Log
28
33
  when File
29
34
  "<File:" + obj.path + ">"
30
35
  when Array
31
- if (length = obj.length) > 10
36
+ if (length = obj.length) > FP_MAX_ARRAY
32
37
  "[#{length}--" << (obj.values_at(0,1, length / 2, -2, -1).collect{|e| fingerprint(e)} * ",") << "]"
33
38
  else
34
39
  "[" << (obj.collect{|e| fingerprint(e) } * ", ") << "]"
35
40
  end
36
41
  when Hash
37
- if obj.length > 10
42
+ if obj.length > FP_MAX_HASH
38
43
  "H:{"<< fingerprint(obj.keys) << ";" << fingerprint(obj.values) << "}"
39
44
  else
40
45
  new = "{"
@@ -68,7 +68,8 @@ module MetaExtension
68
68
 
69
69
  if new.instance_variables.include?(:@extension_attrs)
70
70
  new.instance_variable_get(:@extension_attrs).each do |a|
71
- new.remove_instance_variable("@#{a}")
71
+ var_name = "@#{a}".to_sym
72
+ new.remove_instance_variable(var_name) if new.instance_variables.include? var_name
72
73
  end
73
74
  new.remove_instance_variable("@extension_attrs")
74
75
  end
@@ -9,6 +9,8 @@ module Misc
9
9
  #'\'' << obj << '\''
10
10
  if Path === obj || ! Open.exists?(obj)
11
11
  '\'' << obj << '\''
12
+ elsif File.directory?(obj)
13
+ "Directory MD5: #{digest_str(Dir.glob(File.join(obj, "*")))}"
12
14
  else
13
15
  "File MD5: #{Misc.file_md5(obj)}"
14
16
  end
@@ -8,8 +8,8 @@ module Misc
8
8
  res = nil
9
9
  begin
10
10
  measure = Benchmark.measure do
11
- repeats.times do
12
- res = yield
11
+ repeats.times do |i|
12
+ res = yield i
13
13
  end
14
14
  end
15
15
  if message
@@ -70,6 +70,13 @@ module NamedArray
70
70
  super(pos)
71
71
  end
72
72
 
73
+ def []=(key, value)
74
+ pos = NamedArray.identify_name(@fields, key)
75
+ return nil if pos.nil?
76
+ super(pos, value)
77
+ end
78
+
79
+
73
80
  def concat(other)
74
81
  super(other)
75
82
  self.fields.concat(other.fields) if NamedArray === other
@@ -31,6 +31,7 @@ module Open
31
31
  end
32
32
 
33
33
  def self.wget(url, options = {})
34
+ options = options[:wget_options] if options.include?(:wget_options)
34
35
  if ! (options[:force] || options[:nocache]) && cache_file = in_cache(url, options)
35
36
  return file_open(cache_file)
36
37
  end
@@ -114,6 +114,10 @@ module Open
114
114
  end
115
115
  class << self; alias exist? exists? end
116
116
 
117
+ def self.exist_or_link?(file)
118
+ self.exists?(file) || File.symlink?(file)
119
+ end
120
+
117
121
  def self.mv(source, target, options = {})
118
122
  target = target.find if Path === target
119
123
  source = source.find if Path === source
@@ -2,7 +2,7 @@ require_relative '../indiferent_hash'
2
2
  module Path
3
3
 
4
4
  def self.caller_lib_dir(file = nil, relative_to = ['lib', 'bin'])
5
-
5
+
6
6
  if file.nil?
7
7
  caller_dup = caller.dup
8
8
  while file = caller_dup.shift
@@ -41,7 +41,7 @@ module Path
41
41
  sub('{SUBPATH}', path._subpath).
42
42
  sub('{BASENAME}', File.basename(path)).
43
43
  sub('{PATH}', path).
44
- sub('{LIBDIR}', path.libdir || (path.pkgdir.respond_to?(:libdir) && path.pkgdir.libdir) || Path.caller_lib_dir || "NOLIBDIR").
44
+ sub('{LIBDIR}'){ path.libdir || (path.pkgdir.respond_to?(:libdir) && path.pkgdir.libdir) || Path.caller_lib_dir || "NOLIBDIR" }.
45
45
  sub('{MAPNAME}', map_name.to_s).
46
46
  sub('{REMOVE}/', '').
47
47
  sub('{REMOVE}', '').gsub(/\/+/,'/')
@@ -88,6 +88,19 @@ module Path
88
88
  @@map_order = nil
89
89
  end
90
90
 
91
+ def self.load_path_maps(filename)
92
+ Path.setup(filename) unless Path === filename
93
+ if filename.exist?
94
+ begin
95
+ YAML.load(filename.read).each do |where, location|
96
+ @@path_maps[where.to_sym] = location
97
+ end
98
+ rescue
99
+ Log.error "Error loading search_paths from #{filename}: " << $!.message
100
+ end
101
+ end
102
+ end
103
+
91
104
  def _parts
92
105
  @_parts ||= self.split("/")
93
106
  end
@@ -95,7 +108,7 @@ module Path
95
108
  def _subpath
96
109
  @subpath ||= _parts.length > 1 ? _parts[1..-1] * "/" : _parts[0] || ""
97
110
  end
98
-
111
+
99
112
  def _toplevel
100
113
  @toplevel ||= _parts.length > 1 ? _parts[0] : ""
101
114
  end
@@ -34,6 +34,10 @@ module Path
34
34
  File.directory?(self.find)
35
35
  end
36
36
 
37
+ def sub(*args)
38
+ self.annotate super(*args)
39
+ end
40
+
37
41
  def dirname
38
42
  self.annotate(File.dirname(self))
39
43
  end
@@ -52,7 +52,7 @@ module Persist
52
52
  when nil, :string, :text, :file, :stream, :select, :folder
53
53
  serialized
54
54
  when :path
55
- Path.setup(serialized)
55
+ Path.setup(serialized.strip)
56
56
  when :integer
57
57
  serialized.to_i
58
58
  when :float
@@ -1,3 +1,5 @@
1
1
  module Scout
2
2
  extend Resource
3
3
  end
4
+
5
+ Path.load_path_maps(Scout.etc["path_maps"])
@@ -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.1.0 ruby lib
5
+ # stub: scout-essentials 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-essentials".freeze
9
- s.version = "1.1.0"
9
+ s.version = "1.2.0"
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 = "2023-07-06"
14
+ s.date = "2023-08-08"
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 = [
@@ -88,6 +88,7 @@ Gem::Specification.new do |s|
88
88
  "test/scout/indiferent_hash/test_case_insensitive.rb",
89
89
  "test/scout/indiferent_hash/test_options.rb",
90
90
  "test/scout/log/test_color.rb",
91
+ "test/scout/log/test_fingerprint.rb",
91
92
  "test/scout/log/test_progress.rb",
92
93
  "test/scout/misc/test_digest.rb",
93
94
  "test/scout/misc/test_filesystem.rb",
@@ -127,7 +128,7 @@ Gem::Specification.new do |s|
127
128
  ]
128
129
  s.homepage = "http://github.com/mikisvaz/scout-essentials".freeze
129
130
  s.licenses = ["MIT".freeze]
130
- s.rubygems_version = "3.4.13".freeze
131
+ s.rubygems_version = "3.5.0.dev".freeze
131
132
  s.summary = "Scout essential tools".freeze
132
133
 
133
134
  s.specification_version = 4
@@ -0,0 +1,10 @@
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 TestFingerprint < Test::Unit::TestCase
5
+ def test_str
6
+ str = "Start-" + ("0123456789" * 20) + "-End"
7
+ assert_equal 150, Log.fingerprint(str).length
8
+ end
9
+ end
10
+
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-06 00:00:00.000000000 Z
11
+ date: 2023-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -185,6 +185,7 @@ files:
185
185
  - test/scout/indiferent_hash/test_case_insensitive.rb
186
186
  - test/scout/indiferent_hash/test_options.rb
187
187
  - test/scout/log/test_color.rb
188
+ - test/scout/log/test_fingerprint.rb
188
189
  - test/scout/log/test_progress.rb
189
190
  - test/scout/misc/test_digest.rb
190
191
  - test/scout/misc/test_filesystem.rb
@@ -240,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
241
  - !ruby/object:Gem::Version
241
242
  version: '0'
242
243
  requirements: []
243
- rubygems_version: 3.4.13
244
+ rubygems_version: 3.5.0.dev
244
245
  signing_key:
245
246
  specification_version: 4
246
247
  summary: Scout essential tools