scout-essentials 1.6.5 → 1.6.6

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: e5c16f695461037137552a5dc43c5135eae7873176ae2bc9495e9c0ed7fdbf0b
4
- data.tar.gz: 6bea89686ff4be00f385757cf2d4e96aa15c973253432244eb7c0412c7977365
3
+ metadata.gz: 49e4171f1423c14ce88fa83062e7a90febad44c979596dd3e185d296ec37d9bc
4
+ data.tar.gz: 174e9b8798c3d2541d1b1ee72233adb98152406dc95611a4e2022938442ce373
5
5
  SHA512:
6
- metadata.gz: 10864ea7dc1d73802a5c4bdc4f48f48434f3d610c4efef5df281f0d34b38eae366329673daff86756242ca43cee792ba76c8c8f590d0ed030c0c77c645eb4a58
7
- data.tar.gz: 6d2d19fa54ee2ab3c3130310f54feb080713a53f41a69a99debed28e69f127e7e1596eb99a0e715f4a6af5f89af78c86d8c189cc94afef6427c5802962c12c1f
6
+ metadata.gz: 5826fb333507b38743aa46232391eec8208062539d72263794747b8b67b79d642c22146866d207fb69fcc1b35bcba07da4ce9deabf936783aff75e2b6c6ce598
7
+ data.tar.gz: 381d4453ac80ee4ac6258da44cd0818f5df046744995620d8fc957e873b874360dfb4915f0e30e2ea3c69faddedff0307db6ecd7429ab96c1f3f5e3696e752b6
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ Juwelier::Tasks.new do |gem|
19
19
 
20
20
  gem.add_runtime_dependency 'term-ansicolor'
21
21
  gem.add_runtime_dependency 'yaml'
22
+ gem.add_runtime_dependency 'rake'
22
23
  end
23
24
  Juwelier::RubygemsDotOrgTasks.new
24
25
  require 'rake/testtask'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.5
1
+ 1.6.6
data/lib/scout/config.rb CHANGED
@@ -89,7 +89,19 @@ module Scout::Config
89
89
  # For equal priorities the matching prioritizes tokens ealier in the list
90
90
  def self.get(key, *tokens)
91
91
  options = tokens.pop if Hash === tokens.last
92
+ options = IndiferentHash.setup options if options
93
+
92
94
  default = options.nil? ? nil : options[:default]
95
+ env = options.nil? ? nil : options[:env]
96
+
97
+ if env
98
+ env.split(/,\s*/).each do |variable|
99
+ if ENV[variable]
100
+ default = ENV[variable]
101
+ break
102
+ end
103
+ end
104
+ end
93
105
 
94
106
  tokens = ["key:" + key] if tokens.empty?
95
107
 
@@ -120,12 +132,16 @@ module Scout::Config
120
132
  value = priorities.empty? ? default : priorities.collect{|p| p }.sort_by{|p,v| p}.first.last.first
121
133
  value = false if value == 'false'
122
134
 
123
- Log.debug "Value #{value.inspect} for config key '#{ key }': #{tokens * ", "}"
135
+ Log.debug "Value #{value.inspect} for config key '#{ key }': #{tokens * ", "}" + (env ? " env:#{env}" : '')
124
136
  GOT_KEYS << [key, value, tokens]
125
137
 
126
138
  if String === value && m = value.match(/^env:(.*)/)
127
- variable = m.captures.first
128
- ENV[variable]
139
+ variables = m.captures.first
140
+ variables.split(/,\s*/).each do |variable|
141
+ value = ENV[variable]
142
+ return value if value
143
+ end
144
+ nil
129
145
  elsif value == 'nil'
130
146
  nil
131
147
  else
@@ -34,17 +34,18 @@ module Misc
34
34
  def self.chunk(array, size)
35
35
  total = array.length
36
36
  current = 0
37
- res = [] unless block_given?
37
+ res = []
38
38
  while current < total
39
39
  last = current + size - 1
40
40
  if block_given?
41
- yield array[current..last]
41
+ r = yield array[current..last]
42
+ res.concat r if Array === r
42
43
  else
43
44
  res << array[current..last]
44
45
  end
45
46
  current = last + 1
46
47
  end
47
- block_given? ? nil : res
48
+ res
48
49
  end
49
50
 
50
51
  # Divides the array into +num+ chunks of the same size by placing one
@@ -52,7 +52,7 @@ module Misc
52
52
  end
53
53
 
54
54
  def self.variance(list)
55
- return nil if list.length < 3
55
+ return nil if list.length < 2
56
56
  mean = mean(list)
57
57
  list = list.compact
58
58
  list_length = list.length
@@ -66,9 +66,8 @@ module Misc
66
66
  total_square_distance / (list_length - 1)
67
67
  end
68
68
 
69
-
70
69
  def self.sd(list)
71
- return nil if list.length < 3
70
+ return nil if list.length < 2
72
71
  variance = self.variance(list)
73
72
  Math.sqrt(variance)
74
73
  end
@@ -52,7 +52,23 @@ module Misc
52
52
  ENV[var] = old_value
53
53
  end
54
54
  end
55
-
55
+
56
+ def self.with_envs(hash, &block)
57
+ old_value = {}
58
+ begin
59
+ hash.each do |var,value|
60
+ old_value[var] = ENV[var]
61
+ ENV[var] = value
62
+ end
63
+ yield
64
+ ensure
65
+ old_value.each do |var,value|
66
+ ENV[var] = value
67
+ end
68
+ end
69
+ end
70
+
71
+
56
72
  def self.update_git(gem_name = 'scout-essentials')
57
73
  gem_name = 'scout-essentials' if gem_name.nil?
58
74
  dir = File.join(__dir__, '../../../../', gem_name)
@@ -30,6 +30,17 @@ module Open
30
30
  end
31
31
  end
32
32
 
33
+ LAST_TIME = {}
34
+ def self.wait(lag, key = nil)
35
+ time = Time.now
36
+
37
+ if LAST_TIME[key] != nil && (time < LAST_TIME[key] + lag)
38
+ sleep (LAST_TIME[key] + lag) - time
39
+ end
40
+
41
+ LAST_TIME[key] = Time.now
42
+ end
43
+
33
44
  def self.wget(url, options = {})
34
45
  options = options[:wget_options] if options.include?(:wget_options)
35
46
  if ! (options[:force] || options[:nocache]) && cache_file = in_cache(url, options)
@@ -98,7 +98,12 @@ module Path
98
98
  end
99
99
 
100
100
  def unset_extension
101
- self.annotate(self.split(".")[0..-2] * ".")
101
+ parts = self.split("/")
102
+ basename = parts.pop
103
+ return self unless basename.include?(".")
104
+ basename = basename.split(".")[0..-2] * "."
105
+ parts.push basename
106
+ self.annotate(parts * "/")
102
107
  end
103
108
 
104
109
  def remove_extension(extension = nil)
@@ -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.5 ruby lib
5
+ # stub: scout-essentials 1.6.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-essentials".freeze
9
- s.version = "1.6.5".freeze
9
+ s.version = "1.6.6".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 = "2025-01-17"
14
+ s.date = "2025-03-10"
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 = [
@@ -139,7 +139,7 @@ Gem::Specification.new do |s|
139
139
  ]
140
140
  s.homepage = "http://github.com/mikisvaz/scout-essentials".freeze
141
141
  s.licenses = ["MIT".freeze]
142
- s.rubygems_version = "3.5.23".freeze
142
+ s.rubygems_version = "3.6.5".freeze
143
143
  s.summary = "Scout essential tools".freeze
144
144
 
145
145
  s.specification_version = 4
@@ -151,5 +151,6 @@ Gem::Specification.new do |s|
151
151
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
152
152
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, [">= 0".freeze])
153
153
  s.add_runtime_dependency(%q<yaml>.freeze, [">= 0".freeze])
154
+ s.add_runtime_dependency(%q<rake>.freeze, [">= 0".freeze])
154
155
  end
155
156
 
@@ -18,5 +18,13 @@ class TestPathUtil < Test::Unit::TestCase
18
18
  assert_equal %w(foo bar).sort, tmpdir.glob.collect{|p| p.basename }.sort
19
19
  end
20
20
  end
21
+
22
+ def test_unset_extension
23
+ path = Path.setup("/home/.scout/dir/file.txt")
24
+ assert_equal "/home/.scout/dir/file", path.unset_extension
25
+
26
+ path = Path.setup("/home/.scout/dir/file")
27
+ assert_equal "/home/.scout/dir/file", path.unset_extension
28
+ end
21
29
  end
22
30
 
@@ -63,4 +63,20 @@ class TestConfig < Test::Unit::TestCase
63
63
  Scout::Config.add_entry 'key', 'V1', 'token1'
64
64
  assert_equal "V3", Scout::Config.get('key', 'token2', :default => 'V3')
65
65
  end
66
+
67
+ def test_env
68
+ Misc.with_env "TEST_VAR", "TEST" do
69
+ assert_equal "TEST", Scout::Config.get("value", :key, :env => "TEST_VAR")
70
+ Scout::Config.set "value", 'env:TEST_VAR', 'key'
71
+ assert_equal "TEST", Scout::Config.get(:value, :key)
72
+ end
73
+ end
74
+
75
+ def test_env_multiple
76
+ Misc.with_env "TEST_VAR", "TEST" do
77
+ assert_equal "TEST", Scout::Config.get("value", :key, :env => "TEST_VAR,TESTVAR")
78
+ Scout::Config.set "value", 'env:TEST_VAR,TESTVAR', 'key'
79
+ assert_equal "TEST", Scout::Config.get(:value, :key)
80
+ end
81
+ end
66
82
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-01-17 00:00:00.000000000 Z
10
+ date: 2025-03-10 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: shoulda
@@ -108,6 +107,20 @@ dependencies:
108
107
  - - ">="
109
108
  - !ruby/object:Gem::Version
110
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rake
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
111
124
  description: Things a scout can use anywhere
112
125
  email: mikisvaz@gmail.com
113
126
  executables: []
@@ -237,7 +250,6 @@ homepage: http://github.com/mikisvaz/scout-essentials
237
250
  licenses:
238
251
  - MIT
239
252
  metadata: {}
240
- post_install_message:
241
253
  rdoc_options: []
242
254
  require_paths:
243
255
  - lib
@@ -252,8 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
264
  - !ruby/object:Gem::Version
253
265
  version: '0'
254
266
  requirements: []
255
- rubygems_version: 3.5.23
256
- signing_key:
267
+ rubygems_version: 3.6.5
257
268
  specification_version: 4
258
269
  summary: Scout essential tools
259
270
  test_files: []