eac_ruby_utils 0.80.1 → 0.83.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: 1179fc3ebeef4795b3750c2579c2a42610ddca10bb96319a2b0a0165ebff1442
4
- data.tar.gz: 0cc302d2b05fb618ac4e92724390eaf2f4f9b52f17449991371ba53b8d15dcca
3
+ metadata.gz: ead277954d30057deff2aadb9f960afabd477f983bacdd0dddd578ebfd5d1f69
4
+ data.tar.gz: c385ec742ac8e478d289f00891caadda9ac8447b2d2b781c99cb8203c33a4ea6
5
5
  SHA512:
6
- metadata.gz: cde6c8f63172f39c586b4ce88f9220b2c8cec78f06ae51118e4eda82938a2931e6c356f0017a69b53c2f48653970fccfa0e91ef533966a5b31d1de2b00612d73
7
- data.tar.gz: 78b2de9f9f9b1e42a50d732e3ad6d5cbf1d7ee16ce210715344a6a2d7d2dc6795f0e2be8ab3e46aa180a50f4f15e8c7f1a536e2ba3ee91002a683d133fad2ab9
6
+ metadata.gz: 70ab1feb4ce84b8239e709992a90a27b854c03038a8aced9a3ea56b1a3954177ef3af5b0ec4ebec84d1ac9045f20926038581b0d4aeef130ffb551c0959d4f28
7
+ data.tar.gz: 31bb8905cbadfd73cf1514d9b1318e66bac201be7ae6e2537956bbebba5392c9f1ad61be8371fa7fbc08976d4491f7975d7ed899f10453d141582c5c19db36d4
@@ -2,6 +2,8 @@
2
2
 
3
3
  module EacRubyUtils
4
4
  class Context
5
+ delegate :any?, to: :stack
6
+
5
7
  def current
6
8
  optional_current || raise('No elements in context')
7
9
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/struct'
4
+
5
+ class Hash
6
+ # Returns an <tt>EacRubyUtils::Struct</tt> out of its receiver.
7
+ def to_struct
8
+ ::EacRubyUtils::Struct.new(self)
9
+ end
10
+ end
@@ -8,7 +8,7 @@ class Object
8
8
  end
9
9
 
10
10
  def to_debug
11
- "|#{self.class}|#{self}|"
11
+ "|#{::Object.instance_method(:to_s).bind(self).call}|#{self}|"
12
12
  end
13
13
 
14
14
  def raise_debug
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ class Pathname
6
+ # Execute .mkpath and return +self+.
7
+ # @return [Pathname]
8
+ def mkpath_s
9
+ mkpath
10
+ self
11
+ end
12
+ end
@@ -20,7 +20,7 @@ module EacRubyUtils
20
20
  end
21
21
 
22
22
  def method_missing(method, *args, &block)
23
- if respond_to?(::EacRubyUtils::SimpleCache.uncached_method_name(method), true)
23
+ if respond_to?(uncached_method_name(method), true)
24
24
  call_method_with_cache(method, args, &block)
25
25
  else
26
26
  super
@@ -37,27 +37,37 @@ module EacRubyUtils
37
37
 
38
38
  def reset_cache(*keys)
39
39
  if keys.any?
40
- keys.each { |key| cache_keys.delete(key) }
40
+ keys.each { |key| cache_keys.delete(sanitize_cache_key(key)) }
41
41
  else
42
42
  @cache_keys = nil
43
43
  end
44
44
  end
45
45
 
46
+ def sanitize_cache_key(key)
47
+ key.to_s.to_sym
48
+ end
49
+
50
+ protected
51
+
52
+ def uncached_method_name(original_method_name)
53
+ ::EacRubyUtils::SimpleCache.uncached_method_name(original_method_name)
54
+ end
55
+
46
56
  private
47
57
 
48
58
  def call_method_with_cache(method, args, &block)
49
59
  raise 'Não é possível realizar o cache de métodos com bloco' if block
50
60
 
51
61
  key = ([method] + args).join('@@@')
52
- unless cache_keys.key?(key)
62
+ unless cache_keys.key?(sanitize_cache_key(key))
53
63
  uncached_value = call_uncached_method(method, args)
54
- cache_keys[key] = uncached_value
64
+ cache_keys[sanitize_cache_key(key)] = uncached_value
55
65
  end
56
- cache_keys[key]
66
+ cache_keys[sanitize_cache_key(key)]
57
67
  end
58
68
 
59
69
  def call_uncached_method(method, args)
60
- send(::EacRubyUtils::SimpleCache.uncached_method_name(method), *args)
70
+ send(uncached_method_name(method), *args)
61
71
  end
62
72
 
63
73
  def cache_keys
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.80.1'
4
+ VERSION = '0.83.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.80.1
4
+ version: 0.83.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-26 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '4.0'
29
+ version: '4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: addressable
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +138,6 @@ files:
132
138
  - lib/eac_ruby_utils/fs.rb
133
139
  - lib/eac_ruby_utils/fs/clearable_directory.rb
134
140
  - lib/eac_ruby_utils/fs/extname.rb
135
- - lib/eac_ruby_utils/fs/logs.rb
136
141
  - lib/eac_ruby_utils/fs/temp.rb
137
142
  - lib/eac_ruby_utils/fs/temp/directory.rb
138
143
  - lib/eac_ruby_utils/fs/temp/file.rb
@@ -173,6 +178,7 @@ files:
173
178
  - lib/eac_ruby_utils/patches/hash.rb
174
179
  - lib/eac_ruby_utils/patches/hash/options_consumer.rb
175
180
  - lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
181
+ - lib/eac_ruby_utils/patches/hash/to_struct.rb
176
182
  - lib/eac_ruby_utils/patches/kernel.rb
177
183
  - lib/eac_ruby_utils/patches/kernel/nyi.rb
178
184
  - lib/eac_ruby_utils/patches/module.rb
@@ -199,6 +205,7 @@ files:
199
205
  - lib/eac_ruby_utils/patches/object/to_pathname.rb
200
206
  - lib/eac_ruby_utils/patches/pathname.rb
201
207
  - lib/eac_ruby_utils/patches/pathname/basename_sub.rb
208
+ - lib/eac_ruby_utils/patches/pathname/mkpath_s.rb
202
209
  - lib/eac_ruby_utils/patches/pathname/parent_n.rb
203
210
  - lib/eac_ruby_utils/patches/regexp.rb
204
211
  - lib/eac_ruby_utils/patches/regexp/if_match.rb
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/string/filters'
4
- require 'eac_ruby_utils/fs/temp'
5
- require 'filesize'
6
-
7
- module EacRubyUtils
8
- module Fs
9
- class Logs
10
- TRUNCATE_DEFAULT_LENGTH = 1000
11
- TRUNCATE_APPEND_TEXT = '(...) '
12
-
13
- def [](label)
14
- log_set.fetch(sanitize_label(label))
15
- end
16
-
17
- def add(label)
18
- log_set[sanitize_label(label)] = ::EacRubyUtils::Fs::Temp.file
19
-
20
- self
21
- end
22
-
23
- def remove_all
24
- log_set.each_key { |label| remove(label) }
25
-
26
- self
27
- end
28
-
29
- def remove(label)
30
- log_set.fetch(sanitize_label(label)).remove
31
- log_set.delete(sanitize_label(label))
32
- end
33
-
34
- def truncate(label, length = TRUNCATE_DEFAULT_LENGTH)
35
- content = self[label].read.strip
36
- return content if content.length <= TRUNCATE_DEFAULT_LENGTH
37
-
38
- TRUNCATE_APPEND_TEXT + content[content.length - length + TRUNCATE_APPEND_TEXT.length,
39
- length - TRUNCATE_APPEND_TEXT.length]
40
- end
41
-
42
- def truncate_all(length = TRUNCATE_DEFAULT_LENGTH)
43
- s = "Files: #{log_set.length}\n"
44
- log_set.each do |label, path|
45
- x = truncate(label, length)
46
- y = [label, path, ::Filesize.from("#{path.size} B").pretty].join(' / ')
47
- s += x.blank? ? ">>> #{y} (Blank) <<<" : ">>> #{y}\n#{x}\n<<< #{y}\n"
48
- end
49
- s
50
- end
51
-
52
- private
53
-
54
- def sanitize_label(label)
55
- label.to_sym
56
- end
57
-
58
- def log_set
59
- @log_set ||= {}
60
- end
61
- end
62
- end
63
- end