scout-essentials 1.6.4 → 1.6.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
  SHA256:
3
- metadata.gz: 733fb62cfc8f1119cc35567f30bec3f569856a2c10e7fa4ab8dcb54fb39cf737
4
- data.tar.gz: abc7a2a0ffa9c524da167c1f2132efb557a6ebd7debe267e014bba1269a31661
3
+ metadata.gz: e5c16f695461037137552a5dc43c5135eae7873176ae2bc9495e9c0ed7fdbf0b
4
+ data.tar.gz: 6bea89686ff4be00f385757cf2d4e96aa15c973253432244eb7c0412c7977365
5
5
  SHA512:
6
- metadata.gz: cdd5c50d28fa8ffac0c5f1660ab5ff8b0e63c3df7d27966cb98c78928161c78270b3bab72732c5eeb5c37a1824fc101fdb2b569567b3af977404f540fb5912de
7
- data.tar.gz: c4f4e5f5f7b276d20ea65ef22d8447c0499606a3b9c590768517808f6f226c137361b38f1dc56c5e90f2a7652d8519f9cfc591438f939ed2345de2c999f05139
6
+ metadata.gz: 10864ea7dc1d73802a5c4bdc4f48f48434f3d610c4efef5df281f0d34b38eae366329673daff86756242ca43cee792ba76c8c8f590d0ed030c0c77c645eb4a58
7
+ data.tar.gz: 6d2d19fa54ee2ab3c3130310f54feb080713a53f41a69a99debed28e69f127e7e1596eb99a0e715f4a6af5f89af78c86d8c189cc94afef6427c5802962c12c1f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.4
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
@@ -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)
@@ -99,5 +118,27 @@ module IndiferentHash
99
118
  self[key.to_sym] = self.delete(key)
100
119
  end
101
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
102
143
  end
103
144
 
@@ -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) }
@@ -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
@@ -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
 
@@ -56,7 +56,7 @@ module Resource
56
56
  type, content = @resources[path]
57
57
  when (Path === path && @resources && @resources.include?(path.original))
58
58
  type, content = @resources[path.original]
59
- when has_rake(path)
59
+ when has_rake?(path)
60
60
  type = :rake
61
61
  rake_dir, content = rake_for(path)
62
62
  rake_dir = Path.setup(rake_dir.dup, self.pkgdir, self)
@@ -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.4 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.4".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-12-10"
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",
@@ -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.4
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-12-10 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
File without changes