eac_ruby_utils 0.74.0 → 0.77.1
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 +4 -4
- data/lib/eac_ruby_utils/abstract_methods.rb +7 -0
- data/lib/eac_ruby_utils/compact.rb +22 -0
- data/lib/eac_ruby_utils/gems_registry/gem.rb +4 -0
- data/lib/eac_ruby_utils/gems_registry.rb +1 -1
- data/lib/eac_ruby_utils/patches/class/abstract.rb +9 -0
- data/lib/eac_ruby_utils/patches/class/self_included_modules.rb +7 -0
- data/lib/eac_ruby_utils/patches/module/i18n_translate.rb +32 -0
- data/lib/eac_ruby_utils/patches/object/call_if_proc.rb +11 -0
- data/lib/eac_ruby_utils/patches/object/compact.rb +20 -0
- data/lib/eac_ruby_utils/patches/object/i18n_translate.rb +13 -0
- data/lib/eac_ruby_utils/patches/string/delimited.rb +16 -0
- data/lib/eac_ruby_utils/speaker/receiver.rb +10 -10
- data/lib/eac_ruby_utils/string_delimited.rb +70 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +11 -4
- data/lib/eac_ruby_utils/filesystem_cache.rb +0 -59
- data/lib/eac_ruby_utils/fs_cache.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a79aa784bfe4145425cd5cca34210521f7b818b13bc65c1aa2c99c67e03051
|
4
|
+
data.tar.gz: 42d937120bef307923cd21e98186969051b9c223e5cf7843f72a823839ca07a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 618a01a7a7ca796801a4373ce304940806cc9200bd0bf434f239743b329a99981c39fb44f7f4b5167174963a8e1c4ca34abec704f15574c63abd357d02878783
|
7
|
+
data.tar.gz: 257ae2e8c83d1958ce533f55c9b6bd307ac414ff02e14064aa0a58bc5f63761bbc4ef7257b3442280f31aae998d18a6f3badc683d2f9806c459c03c983076b3b
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/patches/class/self_included_modules'
|
3
4
|
require 'eac_ruby_utils/patches/module/common_concern'
|
4
5
|
|
5
6
|
module EacRubyUtils
|
@@ -27,6 +28,12 @@ module EacRubyUtils
|
|
27
28
|
module AbstractMethods
|
28
29
|
common_concern
|
29
30
|
|
31
|
+
class << self
|
32
|
+
def abstract?(a_class)
|
33
|
+
a_class.self_included_modules.include?(::EacRubyUtils::AbstractMethods)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
30
37
|
module ClassMethods
|
31
38
|
def abstract_methods(*methods_names)
|
32
39
|
methods_names.each do |method_name|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Compact
|
5
|
+
attr_reader :object, :attributes
|
6
|
+
|
7
|
+
def initialize(object, attributes)
|
8
|
+
@object = object
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array]
|
13
|
+
def to_a
|
14
|
+
attributes.map { |attr| object.send(attr) }
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Hash]
|
18
|
+
def to_h
|
19
|
+
attributes.map { |attr| [attr.to_sym, object.send(attr)] }.to_h
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
require 'i18n'
|
5
|
+
|
6
|
+
class Module
|
7
|
+
TRANSLATE_LOCALE_KEY = :__locale
|
8
|
+
|
9
|
+
def i18n_translate(entry_suffix, values = {})
|
10
|
+
on_i18n_locale(values.delete(TRANSLATE_LOCALE_KEY)) do
|
11
|
+
::I18n.translate(i18n_translate_entry_full(entry_suffix), values)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def i18n_translate_entry_full(entry_suffix)
|
16
|
+
"#{i18n_translate_entry_self_prefix}.#{entry_suffix}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def i18n_translate_entry_self_prefix
|
20
|
+
name.underscore.gsub('/', '.')
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_i18n_locale(locale)
|
24
|
+
old_locale = ::I18n.locale
|
25
|
+
begin
|
26
|
+
::I18n.locale = locale
|
27
|
+
yield
|
28
|
+
ensure
|
29
|
+
::I18n.locale = old_locale
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/compact'
|
4
|
+
|
5
|
+
class Object
|
6
|
+
# @return [EacRubyUtils::Compact]
|
7
|
+
def compact(*attributes)
|
8
|
+
::EacRubyUtils::Compact.new(self, attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Array]
|
12
|
+
def compact_to_a(*attributes)
|
13
|
+
compact(*attributes).to_a
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hash]
|
17
|
+
def compact_to_h(*attributes)
|
18
|
+
compact(*attributes).to_h
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/i18n_translate'
|
4
|
+
|
5
|
+
class Object
|
6
|
+
def i18n_translate(entry_suffix, values = {})
|
7
|
+
self.class.i18n_translate(entry_suffix, values)
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_i18n_locale(locale)
|
11
|
+
self.class.on_i18n_locale(locale)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/string_delimited'
|
4
|
+
|
5
|
+
class String
|
6
|
+
# @return [EacRubyUtils::StringDelimited]
|
7
|
+
def delimited(begin_delimiter, end_delimiter)
|
8
|
+
::EacRubyUtils::StringDelimited.new(self, begin_delimiter, end_delimiter)
|
9
|
+
end
|
10
|
+
|
11
|
+
%w[inner outer without_inner without_outer].each do |method_suffix|
|
12
|
+
define_method "delimited_#{method_suffix}" do |begin_delimiter, end_delimiter|
|
13
|
+
delimited(begin_delimiter, end_delimiter).send(method_suffix)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -8,7 +8,7 @@ module EacRubyUtils
|
|
8
8
|
extend ::EacRubyUtils::AbstractMethods
|
9
9
|
|
10
10
|
def error(_string)
|
11
|
-
raise_abstract_method(
|
11
|
+
raise_abstract_method(__method__)
|
12
12
|
end
|
13
13
|
|
14
14
|
def fatal_error(string)
|
@@ -18,39 +18,39 @@ module EacRubyUtils
|
|
18
18
|
|
19
19
|
# @see EacRubyUtils::Speaker::Sender.input
|
20
20
|
def input(_question, _options = {})
|
21
|
-
raise_abstract_method(
|
21
|
+
raise_abstract_method(__method__)
|
22
22
|
end
|
23
23
|
|
24
24
|
def info(_string)
|
25
|
-
raise_abstract_method(
|
25
|
+
raise_abstract_method(__method__)
|
26
26
|
end
|
27
27
|
|
28
28
|
def infom(_string)
|
29
|
-
raise_abstract_method(
|
29
|
+
raise_abstract_method(__method__)
|
30
30
|
end
|
31
31
|
|
32
32
|
def infov(*_args)
|
33
|
-
raise_abstract_method(
|
33
|
+
raise_abstract_method(__method__)
|
34
34
|
end
|
35
35
|
|
36
36
|
def out(_string = '')
|
37
|
-
raise_abstract_method(
|
37
|
+
raise_abstract_method(__method__)
|
38
38
|
end
|
39
39
|
|
40
40
|
def puts(_string = '')
|
41
|
-
raise_abstract_method(
|
41
|
+
raise_abstract_method(__method__)
|
42
42
|
end
|
43
43
|
|
44
44
|
def success(_string)
|
45
|
-
raise_abstract_method(
|
45
|
+
raise_abstract_method(__method__)
|
46
46
|
end
|
47
47
|
|
48
48
|
def title(_string)
|
49
|
-
raise_abstract_method(
|
49
|
+
raise_abstract_method(__method__)
|
50
50
|
end
|
51
51
|
|
52
52
|
def warn(_string)
|
53
|
-
raise_abstract_method(
|
53
|
+
raise_abstract_method(__method__)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class StringDelimited
|
5
|
+
attr_reader :string, :begin_delimiter, :end_delimiter
|
6
|
+
|
7
|
+
def initialize(string, begin_delimiter, end_delimiter)
|
8
|
+
@string = string
|
9
|
+
@begin_delimiter = begin_delimiter
|
10
|
+
@end_delimiter = end_delimiter
|
11
|
+
end
|
12
|
+
|
13
|
+
def inner
|
14
|
+
between_indexes(content_index, end_index).to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def outer
|
18
|
+
between_indexes(begin_index, after_end_index).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def without_inner
|
22
|
+
without_join(
|
23
|
+
between_indexes(sos_index, content_index), between_indexes(end_index, eos_index)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def without_outer
|
28
|
+
without_join(
|
29
|
+
between_indexes(sos_index, begin_index),
|
30
|
+
between_indexes(after_end_index, eos_index)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def after_end_index
|
37
|
+
end_index.if_present { |v| v + end_delimiter.length }
|
38
|
+
end
|
39
|
+
|
40
|
+
def begin_index
|
41
|
+
string.index(begin_delimiter)
|
42
|
+
end
|
43
|
+
|
44
|
+
def between_indexes(a_begin_index, a_end_index)
|
45
|
+
a_begin_index && a_end_index ? string[a_begin_index, a_end_index - a_begin_index] : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def content_index
|
49
|
+
begin_index.if_present { |v| v + begin_delimiter.length }
|
50
|
+
end
|
51
|
+
|
52
|
+
def without_join(*strings)
|
53
|
+
return string if strings.any?(&:nil?)
|
54
|
+
|
55
|
+
strings.join('')
|
56
|
+
end
|
57
|
+
|
58
|
+
def end_index
|
59
|
+
content_index.if_present { |_v| string.index(end_delimiter, content_index) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def sos_index
|
63
|
+
0
|
64
|
+
end
|
65
|
+
|
66
|
+
def eos_index
|
67
|
+
string.length
|
68
|
+
end
|
69
|
+
end
|
70
|
+
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.
|
4
|
+
version: 0.77.1
|
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
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/eac_ruby_utils/common_constructor/class_initialize.rb
|
107
107
|
- lib/eac_ruby_utils/common_constructor/instance_initialize.rb
|
108
108
|
- lib/eac_ruby_utils/common_constructor/super_args.rb
|
109
|
+
- lib/eac_ruby_utils/compact.rb
|
109
110
|
- lib/eac_ruby_utils/context.rb
|
110
111
|
- lib/eac_ruby_utils/contextualizable.rb
|
111
112
|
- lib/eac_ruby_utils/core_ext.rb
|
@@ -126,7 +127,6 @@ files:
|
|
126
127
|
- lib/eac_ruby_utils/envs/ssh_env/identity_file.rb
|
127
128
|
- lib/eac_ruby_utils/envs/ssh_env/quiet.rb
|
128
129
|
- lib/eac_ruby_utils/envs/ssh_env/terminal.rb
|
129
|
-
- lib/eac_ruby_utils/filesystem_cache.rb
|
130
130
|
- lib/eac_ruby_utils/fs.rb
|
131
131
|
- lib/eac_ruby_utils/fs/clearable_directory.rb
|
132
132
|
- lib/eac_ruby_utils/fs/extname.rb
|
@@ -136,7 +136,6 @@ files:
|
|
136
136
|
- lib/eac_ruby_utils/fs/temp/file.rb
|
137
137
|
- lib/eac_ruby_utils/fs/traversable.rb
|
138
138
|
- lib/eac_ruby_utils/fs/traverser.rb
|
139
|
-
- lib/eac_ruby_utils/fs_cache.rb
|
140
139
|
- lib/eac_ruby_utils/gems_registry.rb
|
141
140
|
- lib/eac_ruby_utils/gems_registry/gem.rb
|
142
141
|
- lib/eac_ruby_utils/immutable.rb
|
@@ -163,7 +162,9 @@ files:
|
|
163
162
|
- lib/eac_ruby_utils/patch.rb
|
164
163
|
- lib/eac_ruby_utils/patches.rb
|
165
164
|
- lib/eac_ruby_utils/patches/class.rb
|
165
|
+
- lib/eac_ruby_utils/patches/class/abstract.rb
|
166
166
|
- lib/eac_ruby_utils/patches/class/common_constructor.rb
|
167
|
+
- lib/eac_ruby_utils/patches/class/self_included_modules.rb
|
167
168
|
- lib/eac_ruby_utils/patches/class/settings_provider.rb
|
168
169
|
- lib/eac_ruby_utils/patches/enumerable.rb
|
169
170
|
- lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb
|
@@ -179,6 +180,7 @@ files:
|
|
179
180
|
- lib/eac_ruby_utils/patches/module/abstract_methods.rb
|
180
181
|
- lib/eac_ruby_utils/patches/module/common_concern.rb
|
181
182
|
- lib/eac_ruby_utils/patches/module/context.rb
|
183
|
+
- lib/eac_ruby_utils/patches/module/i18n_translate.rb
|
182
184
|
- lib/eac_ruby_utils/patches/module/immutable.rb
|
183
185
|
- lib/eac_ruby_utils/patches/module/listable.rb
|
184
186
|
- lib/eac_ruby_utils/patches/module/patch.rb
|
@@ -187,7 +189,10 @@ files:
|
|
187
189
|
- lib/eac_ruby_utils/patches/module/speaker.rb
|
188
190
|
- lib/eac_ruby_utils/patches/object.rb
|
189
191
|
- lib/eac_ruby_utils/patches/object/asserts.rb
|
192
|
+
- lib/eac_ruby_utils/patches/object/call_if_proc.rb
|
193
|
+
- lib/eac_ruby_utils/patches/object/compact.rb
|
190
194
|
- lib/eac_ruby_utils/patches/object/debug.rb
|
195
|
+
- lib/eac_ruby_utils/patches/object/i18n_translate.rb
|
191
196
|
- lib/eac_ruby_utils/patches/object/if_nil.rb
|
192
197
|
- lib/eac_ruby_utils/patches/object/if_present.rb
|
193
198
|
- lib/eac_ruby_utils/patches/object/if_respond.rb
|
@@ -199,6 +204,7 @@ files:
|
|
199
204
|
- lib/eac_ruby_utils/patches/regexp/if_match.rb
|
200
205
|
- lib/eac_ruby_utils/patches/regexp/to_parser.rb
|
201
206
|
- lib/eac_ruby_utils/patches/string.rb
|
207
|
+
- lib/eac_ruby_utils/patches/string/delimited.rb
|
202
208
|
- lib/eac_ruby_utils/patches/string/inflector.rb
|
203
209
|
- lib/eac_ruby_utils/patches/time.rb
|
204
210
|
- lib/eac_ruby_utils/patches/time/required_zone.rb
|
@@ -219,6 +225,7 @@ files:
|
|
219
225
|
- lib/eac_ruby_utils/speaker.rb
|
220
226
|
- lib/eac_ruby_utils/speaker/receiver.rb
|
221
227
|
- lib/eac_ruby_utils/speaker/sender.rb
|
228
|
+
- lib/eac_ruby_utils/string_delimited.rb
|
222
229
|
- lib/eac_ruby_utils/struct.rb
|
223
230
|
- lib/eac_ruby_utils/version.rb
|
224
231
|
- lib/eac_ruby_utils/yaml.rb
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EacRubyUtils
|
4
|
-
class FilesystemCache
|
5
|
-
CONTENT_FILE_NAME = '__content__'
|
6
|
-
|
7
|
-
attr_reader :path
|
8
|
-
|
9
|
-
def initialize(*path_parts)
|
10
|
-
raise ArgumentError, "\"#{path_parts}\" is empty" if path_parts.empty?
|
11
|
-
|
12
|
-
@path = ::File.expand_path(::File.join(*path_parts.map(&:to_s)))
|
13
|
-
end
|
14
|
-
|
15
|
-
def clear
|
16
|
-
return unless cached?
|
17
|
-
|
18
|
-
::File.unlink(content_path)
|
19
|
-
end
|
20
|
-
|
21
|
-
def read
|
22
|
-
return nil unless cached?
|
23
|
-
|
24
|
-
::File.read(content_path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def read_or_cache
|
28
|
-
write(yield) unless cached?
|
29
|
-
|
30
|
-
read
|
31
|
-
end
|
32
|
-
|
33
|
-
def write(value)
|
34
|
-
assert_directory_on_path
|
35
|
-
::File.write(content_path, value)
|
36
|
-
value
|
37
|
-
end
|
38
|
-
|
39
|
-
def child(*child_path_parts)
|
40
|
-
self.class.new(path, *child_path_parts)
|
41
|
-
end
|
42
|
-
|
43
|
-
def cached?
|
44
|
-
::File.exist?(content_path)
|
45
|
-
end
|
46
|
-
|
47
|
-
def content_path
|
48
|
-
::File.join(path, CONTENT_FILE_NAME)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def assert_directory_on_path
|
54
|
-
raise "#{path} is a file" if ::File.file?(path)
|
55
|
-
|
56
|
-
::FileUtils.mkdir_p(path)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/filesystem_cache'
|
4
|
-
require 'tmpdir'
|
5
|
-
|
6
|
-
module EacRubyUtils
|
7
|
-
class << self
|
8
|
-
def fs_cache
|
9
|
-
@fs_cache ||= ::EacRubyUtils::FilesystemCache.new(::Dir.tmpdir, 'eac_ruby_utils', '.cache')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|