eac_ruby_utils 0.125.0 → 0.126.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: b6fa9ca21dfcc4833795698cd71fe64c049739f6621bc4cc9e92f9617c820b56
4
+ data.tar.gz: 5f952359cdc1e9a8dc648ecc5b4f1d9401868ad9a08657eeec8d510850ed89dd
5
5
  SHA512:
6
- metadata.gz: f7fa02c030b616f9463453e072d1eff2ae00b5e7a100655670d869858f4d2f6a2261426832e7390dae78ab6869e984912ae785c4149cf20dd412442be9bec507
7
- data.tar.gz: bbec39d79d0ebe83ed89ccb00810dd5f330c2600225d3ea832533aa25271d29a7a95740055aac0338f1155e6c6620cb9e171d548f4b345ace3cc584da6b93e18
6
+ metadata.gz: f92a99f7e5f4746d3f7bc761e6d1977dd50920924e09676ac3d10298a3197cce9f7e1fc923e311058b8efee8468681bf6643d65cf8b70078a55d5308e3ef3627
7
+ data.tar.gz: e2304ee62e742a30c48bff94f9db979d6c2ae609e1db33cfc1843b66891e2406a0ee41e24ab4ecb19ae2a211268c168262c5cb7bd713e1eef2756b9b445d52e6
@@ -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,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/patches/pathname'
4
+ require 'eac_ruby_utils/patches/object/to_pathname'
3
5
  require 'zeitwerk'
4
6
 
5
7
  module EacRubyUtils
6
8
  class RootModuleSetup
7
9
  class << self
8
- def perform; end
10
+ # @param root_module_file [String]
11
+ def perform(root_module_file, &block)
12
+ new(root_module_file, &block).perform
13
+ end
9
14
  end
10
15
 
16
+ attr_reader :block, :root_module_file
17
+
18
+ # @param root_module_file [String]
19
+ def initialize(root_module_file, &block)
20
+ self.root_module_file = root_module_file
21
+ self.block = block
22
+ end
23
+
24
+ # @param path [String] Relative path to root module's directory.
25
+ def ignore(path)
26
+ count_before = loader.send(:ignored_paths).count
27
+ target_path = path.to_pathname.basename_sub { |b| "#{b.basename('.*')}.rb" }
28
+ .expand_path(root_module_directory)
29
+ result = loader.ignore target_path
30
+ return result if result.count > count_before
31
+
32
+ raise ::ArgumentError, [
33
+ "Trying to ignore path \"#{path}\" did not increase the ignored paths.",
34
+ "Argument path: \"#{path}\"", "Target path: \"#{target_path}\"", "Ignored paths: #{result}"
35
+ ].join("\n")
36
+ end
37
+
38
+ # @return [void]
11
39
  def perform
12
- loader = Zeitwerk::Loader.for_gem
40
+ perform_block
41
+ perform_zeitwerk
42
+ end
43
+
44
+ # @return [String]
45
+ def root_module_directory
46
+ ::File.expand_path(::File.basename(root_module_file, '.*'),
47
+ ::File.dirname(root_module_file))
48
+ end
49
+
50
+ protected
51
+
52
+ attr_writer :block, :root_module_file
53
+
54
+ def perform_block
55
+ instance_eval(&block) if block
56
+ end
57
+
58
+ # @return [void]
59
+ def perform_zeitwerk
13
60
  loader.setup
14
61
  end
62
+
63
+ # @return [Zeitwerk::GemLoader]
64
+ def loader
65
+ @loader ||= ::Zeitwerk::Registry.loader_for_gem(
66
+ root_module_file,
67
+ namespace: Object,
68
+ warn_on_extra_files: true
69
+ )
70
+ end
15
71
  end
16
72
  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.126.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.126.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-05-16 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