eac_ruby_utils 0.125.0 → 0.127.0

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: 4decfb4061ccef911b55104f59a49e4a75dee175d5cc08fff7d8cde0f826a126
4
- data.tar.gz: dc239d0a41eb9e43ccbfc3a9776dc36f689f0963243b0df9f43dc5f5e6213e43
3
+ metadata.gz: 1eca375f90c7ffb3c396d1ca14f300e80a371d257634d7c09c8ae0f18f435dfd
4
+ data.tar.gz: 5a52cdfc7394d729ac702b0b5df8a5721afcdb79aa75d69aee25be06a20159c5
5
5
  SHA512:
6
- metadata.gz: f7fa02c030b616f9463453e072d1eff2ae00b5e7a100655670d869858f4d2f6a2261426832e7390dae78ab6869e984912ae785c4149cf20dd412442be9bec507
7
- data.tar.gz: bbec39d79d0ebe83ed89ccb00810dd5f330c2600225d3ea832533aa25271d29a7a95740055aac0338f1155e6c6620cb9e171d548f4b345ace3cc584da6b93e18
6
+ metadata.gz: 33098fe65997ad6b380543fb11a1d43be9b604748c180f1ac1bd294e98dba83892b4ebd90c5cead54fe3a21c684c1cda2464cec67ef599605758e207fba1518b
7
+ data.tar.gz: fdc66f5a7426bc825db9e472574b6500c656f9cd6aad33587b60daf438db6b45fc6f6971bdd4c3515a799d67515e85bfd76d10e6f0f75bc8f129ecd351e5ebfe
@@ -4,6 +4,7 @@ require 'active_support/callbacks'
4
4
  require 'eac_ruby_utils/arguments_consumer'
5
5
  require 'eac_ruby_utils/common_constructor/class_accessors'
6
6
  require 'eac_ruby_utils/common_constructor/class_initialize'
7
+ require 'eac_ruby_utils/patches/object/call_if_proc'
7
8
 
8
9
  module EacRubyUtils
9
10
  class CommonConstructor
@@ -66,8 +67,9 @@ module EacRubyUtils
66
67
  options[:block_arg] || false
67
68
  end
68
69
 
70
+ # @return [Enumerable]
69
71
  def default_values
70
- options[:default] || []
72
+ options[:default].call_if_proc || []
71
73
  end
72
74
 
73
75
  def setup_class(klass)
@@ -1,28 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/patches/module/common_concern'
4
+
3
5
  module EacRubyUtils
4
6
  module Fs
5
- class << self
6
- # A [File.extname] which find multiple extensions (Ex.: .tar.gz).
7
- def extname(path, limit = -1)
8
- recursive_extension(::File.basename(path), limit)
9
- end
7
+ module Extname
8
+ common_concern
9
+ class_methods do
10
+ # A [File.extname] which find multiple extensions (Ex.: .tar.gz).
11
+ def extname(path, limit = -1)
12
+ recursive_extension(::File.basename(path), limit)
13
+ end
10
14
 
11
- # Shortcut to +extname(2)+.
12
- def extname2(path)
13
- extname(path, 2)
14
- end
15
+ # Shortcut to +extname(2)+.
16
+ def extname2(path)
17
+ extname(path, 2)
18
+ end
15
19
 
16
- private
20
+ private
17
21
 
18
- def recursive_extension(basename, limit)
19
- return '' if limit.zero?
22
+ def recursive_extension(basename, limit)
23
+ return '' if limit.zero?
20
24
 
21
- m = /\A(.+)(\.[a-z][a-z0-9]*)\z/i.match(basename)
22
- if m
23
- "#{recursive_extension(m[1], limit - 1)}#{m[2]}"
24
- else
25
- ''
25
+ m = /\A(.+)(\.[a-z][a-z0-9]*)\z/i.match(basename)
26
+ if m
27
+ "#{recursive_extension(m[1], limit - 1)}#{m[2]}"
28
+ else
29
+ ''
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -4,6 +4,8 @@ require 'eac_ruby_utils/require_sub'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Fs
7
+ include ::EacRubyUtils::Fs::Extname
8
+
7
9
  ::EacRubyUtils.require_sub __FILE__
8
10
  end
9
11
  end
@@ -4,7 +4,10 @@ require 'eac_ruby_utils/regexp_parser'
4
4
 
5
5
  module EacRubyUtils
6
6
  class ObjectsTable
7
- BY_PARSER = ::EacRubyUtils::RegexpParser.new(/\Aby_(.+)\z/) { |m| m[1] }
7
+ BY_PARSER = ::EacRubyUtils::RegexpParser.new(/\Aby_([^!\?]+)(!)?\z/) do |m|
8
+ BY_PARSER_PARSED_STRUCT.new(m[1], "by_attribute#{m[2].present? ? '!' : ''}")
9
+ end
10
+ BY_PARSER_PARSED_STRUCT = ::Struct.new(:attribute, :method_name)
8
11
 
9
12
  common_constructor :objects, default: [[]]
10
13
 
@@ -28,8 +31,8 @@ module EacRubyUtils
28
31
  end
29
32
 
30
33
  def method_missing(method_name, *arguments, &block)
31
- if (attribute = BY_PARSER.parse(method_name))
32
- return by_attribute(attribute, *arguments, &block)
34
+ if (parsed = BY_PARSER.parse(method_name))
35
+ return send(parsed.method_name, parsed.attribute, *arguments, &block)
33
36
  end
34
37
 
35
38
  super
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/common_concern'
4
+
5
+ module EacRubyUtils
6
+ module PatchModule
7
+ common_concern
8
+
9
+ class_methods do
10
+ def patch_module(target, patch)
11
+ return if target.included_modules.include?(patch)
12
+
13
+ target.send(:include, patch)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -4,6 +4,6 @@ require 'eac_ruby_utils/method_class'
4
4
 
5
5
  class Module
6
6
  def enable_method_class
7
- ::EacRubyUtils.patch(self, ::EacRubyUtils::MethodClass)
7
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::MethodClass)
8
8
  end
9
9
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch'
3
+ require 'eac_ruby_utils/patch_module'
4
4
  require 'eac_ruby_utils/settings_provider'
5
5
 
6
6
  class Class
7
7
  def enable_settings_provider
8
- ::EacRubyUtils.patch(self, ::EacRubyUtils::SettingsProvider)
8
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::SettingsProvider)
9
9
  end
10
10
  end
@@ -4,6 +4,6 @@ require 'eac_ruby_utils/static_method_class'
4
4
 
5
5
  class Module
6
6
  def enable_static_method_class
7
- ::EacRubyUtils.patch(self, ::EacRubyUtils::StaticMethodClass)
7
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::StaticMethodClass)
8
8
  end
9
9
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils'
4
+
5
+ class Integer
6
+ RJUST_ZERO_STRING = '0'
7
+
8
+ # @param size [Integer]
9
+ # @return [String]
10
+ def rjust_zero(size)
11
+ to_s.rjust(size, RJUST_ZERO_STRING)
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ EacRubyUtils.require_sub __FILE__
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch'
3
+ require 'eac_ruby_utils/patch_module'
4
4
  require 'eac_ruby_utils/acts_as_immutable'
5
5
 
6
6
  class Module
7
7
  def acts_as_immutable
8
- ::EacRubyUtils.patch(self, ::EacRubyUtils::ActsAsImmutable)
8
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::ActsAsImmutable)
9
9
  end
10
10
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch'
3
+ require 'eac_ruby_utils/patch_module'
4
4
  require 'eac_ruby_utils/contextualizable'
5
5
 
6
6
  class Module
7
7
  # Patches module with [EacRubyUtils::Contextualizable].
8
8
  def enable_context
9
- ::EacRubyUtils.patch(self, ::EacRubyUtils::Contextualizable)
9
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::Contextualizable)
10
10
  end
11
11
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch'
3
+ require 'eac_ruby_utils/patch_module'
4
4
  require 'eac_ruby_utils/acts_as_immutable'
5
5
 
6
6
  class Module
7
7
  # @deprecated Use {#acts_as_immutable} instead.
8
8
  def enable_immutable
9
- ::EacRubyUtils.patch(self, ::EacRubyUtils::ActsAsImmutable)
9
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::ActsAsImmutable)
10
10
  end
11
11
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch'
3
+ require 'eac_ruby_utils/patch_module'
4
4
  require 'eac_ruby_utils/listable'
5
5
 
6
6
  class Module
7
7
  def enable_listable
8
- ::EacRubyUtils.patch(self, ::EacRubyUtils::Listable)
8
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::Listable)
9
9
  end
10
10
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patch_module'
4
+
5
+ class Module
6
+ def patch_self(patch_module)
7
+ ::EacRubyUtils.patch_module(self, patch_module)
8
+ end
9
+ end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch'
3
+ require 'eac_ruby_utils/patch_module'
4
4
  require 'eac_ruby_utils/simple_cache'
5
5
 
6
6
  class Module
7
7
  def enable_simple_cache
8
- ::EacRubyUtils.patch(self, ::EacRubyUtils::SimpleCache)
8
+ ::EacRubyUtils.patch_module(self, ::EacRubyUtils::SimpleCache)
9
9
  end
10
10
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/fs/extname'
4
3
  require 'pathname'
5
4
 
6
5
  class Pathname
@@ -1,16 +1,107 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/inflector'
4
+ require 'eac_ruby_utils/patches/pathname'
5
+ require 'eac_ruby_utils/patches/object/to_pathname'
3
6
  require 'zeitwerk'
4
7
 
5
8
  module EacRubyUtils
6
9
  class RootModuleSetup
10
+ DEFAULT_NAMESPACE = ::Object
11
+ LIB_DIRECTORY_BASENAME = 'lib'
12
+
7
13
  class << self
8
- def perform; end
14
+ # @param root_module_file [String]
15
+ def perform(root_module_file, &block)
16
+ new(root_module_file, &block).perform
17
+ end
18
+ end
19
+
20
+ attr_reader :block, :root_module_file
21
+
22
+ # @param root_module_file [String]
23
+ def initialize(root_module_file, &block)
24
+ self.root_module_file = root_module_file
25
+ self.block = block
26
+ end
27
+
28
+ # @return [Module, nil]
29
+ def extension_for
30
+ dirname = ::File.dirname(relative_root_module_file)
31
+ return nil if ['.', '/', ''].include?(dirname)
32
+
33
+ require dirname
34
+ ::ActiveSupport::Inflector.constantize(dirname.classify)
9
35
  end
10
36
 
37
+ # @param path [String] Relative path to root module's directory.
38
+ def ignore(path)
39
+ count_before = loader.send(:ignored_paths).count
40
+ target_path = path.to_pathname.basename_sub { |b| "#{b.basename('.*')}.rb" }
41
+ .expand_path(root_module_directory)
42
+ result = loader.ignore target_path
43
+ return result if result.count > count_before
44
+
45
+ raise ::ArgumentError, [
46
+ "Trying to ignore path \"#{path}\" did not increase the ignored paths.",
47
+ "Argument path: \"#{path}\"", "Target path: \"#{target_path}\"", "Ignored paths: #{result}"
48
+ ].join("\n")
49
+ end
50
+
51
+ # @return [Module]
52
+ def namespace
53
+ extension_for || DEFAULT_NAMESPACE
54
+ end
55
+
56
+ # @return [void]
11
57
  def perform
12
- loader = Zeitwerk::Loader.for_gem
58
+ perform_block
59
+ perform_zeitwerk
60
+ end
61
+
62
+ # @return [String]
63
+ def relative_root_module_file
64
+ count = 0
65
+ current = ::File.basename(root_module_file, '.*')
66
+ dirname = ::File.dirname(root_module_file)
67
+ loop do
68
+ ibr if dirname == '/'
69
+
70
+ break current if ::File.basename(dirname) == LIB_DIRECTORY_BASENAME
71
+
72
+ current = ::File.join(::File.basename(dirname), current)
73
+ dirname = ::File.dirname(dirname)
74
+
75
+ count += 1
76
+ end
77
+ end
78
+
79
+ # @return [String]
80
+ def root_module_directory
81
+ ::File.expand_path(::File.basename(root_module_file, '.*'),
82
+ ::File.dirname(root_module_file))
83
+ end
84
+
85
+ protected
86
+
87
+ attr_writer :block, :root_module_file
88
+
89
+ def perform_block
90
+ instance_eval(&block) if block
91
+ end
92
+
93
+ # @return [void]
94
+ def perform_zeitwerk
13
95
  loader.setup
14
96
  end
97
+
98
+ # @return [Zeitwerk::GemLoader]
99
+ def loader
100
+ @loader ||= ::Zeitwerk::Registry.loader_for_gem(
101
+ root_module_file,
102
+ namespace: namespace,
103
+ warn_on_extra_files: true
104
+ )
105
+ end
15
106
  end
16
107
  end
@@ -4,16 +4,19 @@ require 'eac_ruby_utils/rspec/setup_manager'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Rspec
7
- class << self
8
- # @return [EacRubyUtils::Rspec::SetupManager]
9
- def default_setup
10
- @default_setup ||
11
- raise("Default instance was not set. Use #{self.class.name}.default_setup_create")
12
- end
7
+ module DefaultSetup
8
+ common_concern
9
+ class_methods do
10
+ # @return [EacRubyUtils::Rspec::SetupManager]
11
+ def default_setup
12
+ @default_setup ||
13
+ raise("Default instance was not set. Use #{self.class.name}.default_setup_create")
14
+ end
13
15
 
14
- # @return [EacRubyUtils::Rspec::SetupManager]
15
- def default_setup_create(app_root_path, rspec_config = nil)
16
- @default_setup = ::EacRubyUtils::Rspec::SetupManager.create(app_root_path, rspec_config)
16
+ # @return [EacRubyUtils::Rspec::SetupManager]
17
+ def default_setup_create(app_root_path, rspec_config = nil)
18
+ @default_setup = ::EacRubyUtils::Rspec::SetupManager.create(app_root_path, rspec_config)
19
+ end
17
20
  end
18
21
  end
19
22
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/require_sub'
4
- EacRubyUtils.require_sub(__FILE__)
3
+ require 'eac_ruby_utils/patches/module/require_sub'
5
4
 
6
5
  module EacRubyUtils
7
6
  module Rspec
7
+ require_sub __FILE__, include_modules: true
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.125.0'
4
+ VERSION = '0.127.0'
5
5
  end
@@ -1,9 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/root_module_setup'
4
- EacRubyUtils::RootModuleSetup.perform
4
+ EacRubyUtils::RootModuleSetup.perform __FILE__ do
5
+ ignore 'core_ext'
6
+ ignore 'locales/from_all_gems'
7
+ ignore 'patches'
8
+ ignore 'ruby/on_clean_environment'
9
+ end
5
10
 
6
11
  module EacRubyUtils
12
+ include ::EacRubyUtils::PatchModule
7
13
  end
8
14
 
9
15
  require 'eac_ruby_utils/core_ext'
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.125.0
4
+ version: 0.127.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: 2025-04-04 00:00:00.000000000 Z
11
+ date: 2025-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -139,6 +139,9 @@ dependencies:
139
139
  - - "~>"
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0.11'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 0.11.1
142
145
  type: :development
143
146
  prerelease: false
144
147
  version_requirements: !ruby/object:Gem::Requirement
@@ -146,6 +149,9 @@ dependencies:
146
149
  - - "~>"
147
150
  - !ruby/object:Gem::Version
148
151
  version: '0.11'
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 0.11.1
149
155
  description:
150
156
  email:
151
157
  executables: []
@@ -244,7 +250,7 @@ files:
244
250
  - lib/eac_ruby_utils/module_ancestors_variable/set.rb
245
251
  - lib/eac_ruby_utils/objects_table.rb
246
252
  - lib/eac_ruby_utils/options_consumer.rb
247
- - lib/eac_ruby_utils/patch.rb
253
+ - lib/eac_ruby_utils/patch_module.rb
248
254
  - lib/eac_ruby_utils/patches.rb
249
255
  - lib/eac_ruby_utils/patches/addressable.rb
250
256
  - lib/eac_ruby_utils/patches/addressable/uri.rb
@@ -266,6 +272,8 @@ files:
266
272
  - lib/eac_ruby_utils/patches/hash/options_consumer.rb
267
273
  - lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
268
274
  - lib/eac_ruby_utils/patches/hash/to_struct.rb
275
+ - lib/eac_ruby_utils/patches/integer.rb
276
+ - lib/eac_ruby_utils/patches/integer/rjust_zero.rb
269
277
  - lib/eac_ruby_utils/patches/kernel.rb
270
278
  - lib/eac_ruby_utils/patches/kernel/ibr.rb
271
279
  - lib/eac_ruby_utils/patches/kernel/nyi.rb
@@ -281,7 +289,7 @@ files:
281
289
  - lib/eac_ruby_utils/patches/module/immutable.rb
282
290
  - lib/eac_ruby_utils/patches/module/listable.rb
283
291
  - lib/eac_ruby_utils/patches/module/module_parent.rb
284
- - lib/eac_ruby_utils/patches/module/patch.rb
292
+ - lib/eac_ruby_utils/patches/module/patch_self.rb
285
293
  - lib/eac_ruby_utils/patches/module/require_sub.rb
286
294
  - lib/eac_ruby_utils/patches/module/simple_cache.rb
287
295
  - lib/eac_ruby_utils/patches/module/speaker.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EacRubyUtils
4
- class << self
5
- def patch(target, patch)
6
- return if target.included_modules.include?(patch)
7
-
8
- target.send(:include, patch)
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/patch'
4
-
5
- class Module
6
- def patch(patch_module)
7
- ::EacRubyUtils.patch(self, patch_module)
8
- end
9
- end