eac_ruby_utils 0.76.0 → 0.79.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: '09b73f3a93332bc0d9ef7963c51ab545d9f40de9ffa6df3c09beaab2f788cc14'
4
- data.tar.gz: 6574b30b1407c63bb3ff51fcda661c05622d663deabbd7032b5ad32635376902
3
+ metadata.gz: e172525643a9ed06ab4af7d0e35f66eecb49c363d368abeabde1b9ecbff8a686
4
+ data.tar.gz: ecdf6f1fd26f286a0a71b74f2ba345cbeeb385017ea41b6475a09d2c42aeb54e
5
5
  SHA512:
6
- metadata.gz: b7afb496fd00e1ed22f567673dce53a2a678dee0c95a06c664a5155ee19bdb2f4208a37cfd97ec26492ff78663558ead8be6c9e1f36cba36868a2319e326e8c1
7
- data.tar.gz: 7378232e47c0b748669c68dd4e8125765a60b59628aba6c795061fc3c20a3609dff96fd80cbcbaa0e40a28b76e8c9aecbbd54436d039a0d7e419c37fdb491d08
6
+ metadata.gz: 8cb0d8299f65375a594790f37c06b126bd57e37f48ea30575c200fed283edad2f7e7ed4e6cb7a3de43a47fbb76cc775fd5955289f1287cc4a213cff1b3ade9db
7
+ data.tar.gz: 1aeea157e9b2c593421b498f6aca325a26d45e93e61c3f46bb344a6edc0805915e3b89bf8e9aaa3daeec7d148fb387d9e1b0e44f670d0add7bc8aad4263b6090
@@ -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|
@@ -3,3 +3,4 @@
3
3
  require 'eac_ruby_utils/patches'
4
4
  require 'active_support/dependencies/autoload'
5
5
  require 'active_support/core_ext'
6
+ require 'active_support/json'
@@ -57,6 +57,10 @@ module EacRubyUtils
57
57
  gemspec.name.gsub('-', '/') + '/' + registry.module_suffix.underscore
58
58
  end
59
59
 
60
+ def to_s
61
+ "#{self.class.name}[#{gemspec.name}]"
62
+ end
63
+
60
64
  private
61
65
 
62
66
  def dependencies_uncached
@@ -21,7 +21,7 @@ module EacRubyUtils
21
21
 
22
22
  # @return [Array<EacRubyUtils::GemsRegistry::Gem>]
23
23
  def registered
24
- @registered ||= all_gems.select(&:found?)
24
+ @registered ||= all_gems.select(&:found?).sort
25
25
  end
26
26
 
27
27
  private
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/abstract_methods'
4
+
5
+ class Class
6
+ def abstract?
7
+ ::EacRubyUtils::AbstractMethods.abstract?(self)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Class
4
+ def self_included_modules
5
+ ancestors.take_while { |a| a != superclass }.select { |ancestor| ancestor.instance_of?(Module) }
6
+ end
7
+ 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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/compact'
4
+
5
+ class Object
6
+ # If +self+ is a Proc, return the value of +.call+. If not, return +self+.
7
+ # @return [Object]
8
+ def call_if_proc
9
+ is_a?(::Proc) ? call : self
10
+ end
11
+ 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
@@ -8,7 +8,7 @@ module EacRubyUtils
8
8
  extend ::EacRubyUtils::AbstractMethods
9
9
 
10
10
  def error(_string)
11
- raise_abstract_method(__FILE__)
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(__FILE__)
21
+ raise_abstract_method(__method__)
22
22
  end
23
23
 
24
24
  def info(_string)
25
- raise_abstract_method(__FILE__)
25
+ raise_abstract_method(__method__)
26
26
  end
27
27
 
28
28
  def infom(_string)
29
- raise_abstract_method(__FILE__)
29
+ raise_abstract_method(__method__)
30
30
  end
31
31
 
32
32
  def infov(*_args)
33
- raise_abstract_method(__FILE__)
33
+ raise_abstract_method(__method__)
34
34
  end
35
35
 
36
36
  def out(_string = '')
37
- raise_abstract_method(__FILE__)
37
+ raise_abstract_method(__method__)
38
38
  end
39
39
 
40
40
  def puts(_string = '')
41
- raise_abstract_method(__FILE__)
41
+ raise_abstract_method(__method__)
42
42
  end
43
43
 
44
44
  def success(_string)
45
- raise_abstract_method(__FILE__)
45
+ raise_abstract_method(__method__)
46
46
  end
47
47
 
48
48
  def title(_string)
49
- raise_abstract_method(__FILE__)
49
+ raise_abstract_method(__method__)
50
50
  end
51
51
 
52
52
  def warn(_string)
53
- raise_abstract_method(__FILE__)
53
+ raise_abstract_method(__method__)
54
54
  end
55
55
  end
56
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.76.0'
4
+ VERSION = '0.79.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.76.0
4
+ version: 0.79.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-09-23 00:00:00.000000000 Z
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -134,8 +134,6 @@ files:
134
134
  - lib/eac_ruby_utils/fs/temp.rb
135
135
  - lib/eac_ruby_utils/fs/temp/directory.rb
136
136
  - lib/eac_ruby_utils/fs/temp/file.rb
137
- - lib/eac_ruby_utils/fs/traversable.rb
138
- - lib/eac_ruby_utils/fs/traverser.rb
139
137
  - lib/eac_ruby_utils/gems_registry.rb
140
138
  - lib/eac_ruby_utils/gems_registry/gem.rb
141
139
  - lib/eac_ruby_utils/immutable.rb
@@ -157,12 +155,13 @@ files:
157
155
  - lib/eac_ruby_utils/listable/symbol_list.rb
158
156
  - lib/eac_ruby_utils/listable/value.rb
159
157
  - lib/eac_ruby_utils/local_time_zone.rb
160
- - lib/eac_ruby_utils/on_clean_ruby_environment.rb
161
158
  - lib/eac_ruby_utils/options_consumer.rb
162
159
  - lib/eac_ruby_utils/patch.rb
163
160
  - lib/eac_ruby_utils/patches.rb
164
161
  - lib/eac_ruby_utils/patches/class.rb
162
+ - lib/eac_ruby_utils/patches/class/abstract.rb
165
163
  - lib/eac_ruby_utils/patches/class/common_constructor.rb
164
+ - lib/eac_ruby_utils/patches/class/self_included_modules.rb
166
165
  - lib/eac_ruby_utils/patches/class/settings_provider.rb
167
166
  - lib/eac_ruby_utils/patches/enumerable.rb
168
167
  - lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb
@@ -178,6 +177,7 @@ files:
178
177
  - lib/eac_ruby_utils/patches/module/abstract_methods.rb
179
178
  - lib/eac_ruby_utils/patches/module/common_concern.rb
180
179
  - lib/eac_ruby_utils/patches/module/context.rb
180
+ - lib/eac_ruby_utils/patches/module/i18n_translate.rb
181
181
  - lib/eac_ruby_utils/patches/module/immutable.rb
182
182
  - lib/eac_ruby_utils/patches/module/listable.rb
183
183
  - lib/eac_ruby_utils/patches/module/patch.rb
@@ -186,8 +186,10 @@ files:
186
186
  - lib/eac_ruby_utils/patches/module/speaker.rb
187
187
  - lib/eac_ruby_utils/patches/object.rb
188
188
  - lib/eac_ruby_utils/patches/object/asserts.rb
189
+ - lib/eac_ruby_utils/patches/object/call_if_proc.rb
189
190
  - lib/eac_ruby_utils/patches/object/compact.rb
190
191
  - lib/eac_ruby_utils/patches/object/debug.rb
192
+ - lib/eac_ruby_utils/patches/object/i18n_translate.rb
191
193
  - lib/eac_ruby_utils/patches/object/if_nil.rb
192
194
  - lib/eac_ruby_utils/patches/object/if_present.rb
193
195
  - lib/eac_ruby_utils/patches/object/if_respond.rb
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/fs/traverser'
4
-
5
- module EacRubyUtils
6
- module Fs
7
- module Traversable
8
- PROP_METHOD_PREFIX = 'traverser_'
9
- BOOLEAN_PROPS = %i[hidden_directories recursive sort].freeze
10
- PATH_PROPS = %i[check_directory check_file].freeze
11
-
12
- class << self
13
- def prop_method_name(prop)
14
- "#{PROP_METHOD_PREFIX}#{prop}"
15
- end
16
- end
17
-
18
- PATH_PROPS.each do |method|
19
- define_method(::EacRubyUtils::Fs::Traversable.prop_method_name(method)) do |_path|
20
- nil
21
- end
22
- end
23
-
24
- BOOLEAN_PROPS.each do |method|
25
- define_method(::EacRubyUtils::Fs::Traversable.prop_method_name(method)) do
26
- false
27
- end
28
-
29
- define_method("#{::EacRubyUtils::Fs::Traversable.prop_method_name(method)}?") do
30
- send(method_name)
31
- end
32
- end
33
-
34
- def traverser_check_path(path)
35
- traverser_new.check_path(path)
36
- end
37
-
38
- def traverser_new
39
- r = ::EacRubyUtils::Fs::Traverser.new
40
- (BOOLEAN_PROPS + PATH_PROPS).each do |prop|
41
- r.send("#{prop}=", method(::EacRubyUtils::Fs::Traversable.prop_method_name(prop)))
42
- end
43
- r
44
- end
45
- end
46
- end
47
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EacRubyUtils
4
- module Fs
5
- class Traverser
6
- attr_accessor :check_directory, :check_file, :recursive, :hidden_directories, :sort
7
-
8
- def check_path(path)
9
- path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
10
- internal_check_path(path, 0)
11
- end
12
-
13
- def hidden_directories?
14
- boolean_value(hidden_directories)
15
- end
16
-
17
- def recursive?
18
- boolean_value(recursive)
19
- end
20
-
21
- def sort?
22
- boolean_value(sort)
23
- end
24
-
25
- private
26
-
27
- def boolean_value(source_value)
28
- source_value = source_value.call if source_value.respond_to?(:call)
29
- source_value ? true : false
30
- end
31
-
32
- def each_child(dir, &block)
33
- if sort?
34
- dir.each_child.sort_by { |p| [p.to_s] }.each(&block)
35
- else
36
- dir.each_child(&block)
37
- end
38
- end
39
-
40
- def process_directory?(level)
41
- level.zero? || recursive?
42
- end
43
-
44
- def inner_check_directory(dir, level)
45
- return unless process_directory?(level)
46
-
47
- user_check_directory(dir)
48
- each_child(dir) do |e|
49
- next unless !e.basename.to_s.start_with?('.') || hidden_directories?
50
-
51
- internal_check_path(e, level + 1)
52
- end
53
- end
54
-
55
- def internal_check_path(path, level)
56
- if path.file?
57
- user_check_file(path)
58
- elsif path.directory?
59
- inner_check_directory(path, level)
60
- end
61
- end
62
-
63
- def user_check_file(path)
64
- check_file&.call(path)
65
- end
66
-
67
- def user_check_directory(path)
68
- check_directory&.call(path)
69
- end
70
- end
71
- end
72
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/ruby/on_clean_environment'
4
-
5
- module EacRubyUtils
6
- class << self
7
- # <b>DEPRECATED:</b> Please use <tt>EacRubyUtils::Ruby.on_clean_environment</tt> instead.
8
- def on_clean_ruby_environment(*args, &block)
9
- ::EacRubyUtils::Ruby.on_clean_environment(*args, &block)
10
- end
11
- end
12
- end