eac_ruby_utils 0.127.0 → 0.128.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eca375f90c7ffb3c396d1ca14f300e80a371d257634d7c09c8ae0f18f435dfd
4
- data.tar.gz: 5a52cdfc7394d729ac702b0b5df8a5721afcdb79aa75d69aee25be06a20159c5
3
+ metadata.gz: 2b94935e750593c0ab19c4a7dd5a7c9706b59a92c42c0be89daee54f88f236a0
4
+ data.tar.gz: 9f71b5d9ed0c45d0c8338288a19487693de100a1fa1b23787ee03fff63d5aa94
5
5
  SHA512:
6
- metadata.gz: 33098fe65997ad6b380543fb11a1d43be9b604748c180f1ac1bd294e98dba83892b4ebd90c5cead54fe3a21c684c1cda2464cec67ef599605758e207fba1518b
7
- data.tar.gz: fdc66f5a7426bc825db9e472574b6500c656f9cd6aad33587b60daf438db6b45fc6f6971bdd4c3515a799d67515e85bfd76d10e6f0f75bc8f129ecd351e5ebfe
6
+ metadata.gz: 40951b5b3c354a75e30cfbe82c614289da2c7b4564b3f65d61c8f327949f5443954bfd11561d790faf6bd1596a85ba9722f86a33aeddec330fc136f9fcf8a4a4
7
+ data.tar.gz: bd9eb72941c5eb09ce73a3b4e337f324d254a6d33c845eb67dca62abd67a046674dbaae4fb0cbf9b5c9b2ed52fadc1d88311d0e4b35a459997c925d297e93a00
@@ -13,11 +13,11 @@ module EacRubyUtils
13
13
 
14
14
  private
15
15
 
16
- def parse_string(value)
16
+ def parse_string(value) # rubocop:disable Naming/PredicateMethod
17
17
  ['', 'n', 'no', 'f', 'false'].exclude?(value.strip.downcase)
18
18
  end
19
19
 
20
- def parse_number(value)
20
+ def parse_number(value) # rubocop:disable Naming/PredicateMethod
21
21
  value.zero?
22
22
  end
23
23
  end
@@ -25,7 +25,7 @@ module EacRubyUtils
25
25
 
26
26
  private
27
27
 
28
- def parse_arg_options_process_arg(result, arg)
28
+ def parse_arg_options_process_arg(result, arg) # rubocop:disable Naming/PredicateMethod
29
29
  if arg.is_a?(::Hash)
30
30
  result.options = arg
31
31
  true
@@ -90,7 +90,7 @@ module EacRubyUtils
90
90
  def value_args
91
91
  r = if block
92
92
  block.call
93
- elsif args.count == 1 && args.first.is_a?(::Enumerable)
93
+ elsif args.one? && args.first.is_a?(::Enumerable)
94
94
  args.first
95
95
  else
96
96
  args
@@ -13,7 +13,7 @@ module EacRubyUtils
13
13
  # @param command [Array]
14
14
  # @return [Array]
15
15
  def sanitize_initialize_arguments(arguments)
16
- if arguments.count == 1 && arguments.first.is_a?(Array)
16
+ if arguments.one? && arguments.first.is_a?(Array)
17
17
  arguments.first
18
18
  elsif arguments.is_a?(Array)
19
19
  arguments
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/recursive_builder'
4
+
5
+ module EacRubyUtils
6
+ class GemsRegistry
7
+ class Gem
8
+ module Dependencies
9
+ def depend_on(gem) # rubocop:disable Naming/PredicateMethod
10
+ dependencies.lazy.map(&:name).include?(gem.gemspec.name)
11
+ end
12
+
13
+ def dependencies
14
+ @dependencies ||= dependencies_uncached # dependencies_uncached
15
+ end
16
+
17
+ private
18
+
19
+ def dependencies_uncached
20
+ ::EacRubyUtils::RecursiveBuilder
21
+ .new(gemspec) { |item| gem_item_dependencies(item) }
22
+ .result
23
+ end
24
+
25
+ # @return [Array<Gem::Dependency>]
26
+ def gem_item_dependencies(item)
27
+ ::Gem::Specification.find_by_name(item.name).dependencies.select(&:runtime?)
28
+ rescue ::Gem::MissingSpecError
29
+ []
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'eac_ruby_utils/recursive_builder'
5
+ require 'eac_ruby_utils/simple_cache'
6
+
7
+ module EacRubyUtils
8
+ class GemsRegistry
9
+ class Gem
10
+ module PathsToRequire
11
+ ROOT_MODULE_REQUIRE_PATTERNS = %w[EacRubyUtils::RootModuleSetup Zeitwerk].freeze
12
+
13
+ # @return [Enumerable<Pathname>]
14
+ def absolute_require_paths(lib_relative_path)
15
+ gemspec.require_paths.lazy.map do |e|
16
+ ::Pathname.new(e).expand_path(gemspec.gem_dir)
17
+ .join("#{lib_relative_path}.rb")
18
+ end
19
+ end
20
+
21
+ # @return [String]
22
+ def path_to_require
23
+ require_root_module? ? root_module_path_to_require : direct_path_to_require
24
+ end
25
+
26
+ # @return [String]
27
+ def to_s
28
+ "#{self.class.name}[#{gemspec.name}]"
29
+ end
30
+
31
+ protected
32
+
33
+ # @return [String]
34
+ def direct_path_to_require
35
+ "#{root_module_path_to_require}/#{registry.module_suffix.underscore}"
36
+ end
37
+
38
+ # @return [Boolean]
39
+ def require_root_module?
40
+ absolute_require_paths(root_module_path_to_require).find do |e|
41
+ next false unless e.file?
42
+
43
+ content = e.read
44
+ ROOT_MODULE_REQUIRE_PATTERNS.any? { |e| content.include?(e) }
45
+ end
46
+ end
47
+
48
+ # @return [String]
49
+ def root_module_path_to_require
50
+ gemspec.name.gsub('-', '/')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/core_ext/string/inflections'
4
- require 'eac_ruby_utils/recursive_builder'
4
+ require 'eac_ruby_utils/gems_registry/gem/dependencies'
5
+ require 'eac_ruby_utils/gems_registry/gem/paths_to_require'
5
6
  require 'eac_ruby_utils/simple_cache'
6
7
 
7
8
  module EacRubyUtils
8
9
  class GemsRegistry
9
10
  class Gem
10
11
  include ::Comparable
12
+ include ::EacRubyUtils::GemsRegistry::Gem::Dependencies
13
+ include ::EacRubyUtils::GemsRegistry::Gem::PathsToRequire
11
14
  include ::EacRubyUtils::SimpleCache
12
15
 
13
16
  attr_reader :registry, :gemspec
@@ -17,14 +20,6 @@ module EacRubyUtils
17
20
  @gemspec = gemspec
18
21
  end
19
22
 
20
- def depend_on(gem)
21
- dependencies.lazy.map(&:name).include?(gem.gemspec.name)
22
- end
23
-
24
- def dependencies
25
- @dependencies ||= dependencies_uncached # dependencies_uncached
26
- end
27
-
28
23
  def <=>(other)
29
24
  sd = depend_on(other)
30
25
  od = other.depend_on(self)
@@ -38,42 +33,16 @@ module EacRubyUtils
38
33
  lib_file_found? && registered_module.is_a?(::Module)
39
34
  end
40
35
 
36
+ # @return [Boolean]
41
37
  def lib_file_found?
42
- gemspec.require_paths.any? do |require_path|
43
- ::Pathname.new(require_path).expand_path(gemspec.gem_dir).join("#{path_to_require}.rb")
44
- .file?
45
- end
38
+ absolute_require_paths(direct_path_to_require).any?(&:file?)
46
39
  end
47
40
 
48
41
  def registered_module
49
42
  return nil unless lib_file_found?
50
43
 
51
44
  require path_to_require
52
- path_to_require.camelize.constantize
53
- end
54
-
55
- # @return [String]
56
- def path_to_require
57
- "#{gemspec.name.gsub('-', '/')}/#{registry.module_suffix.underscore}"
58
- end
59
-
60
- def to_s
61
- "#{self.class.name}[#{gemspec.name}]"
62
- end
63
-
64
- private
65
-
66
- def dependencies_uncached
67
- ::EacRubyUtils::RecursiveBuilder
68
- .new(gemspec) { |item| gem_item_dependencies(item) }
69
- .result
70
- end
71
-
72
- # @return [Array<Gem::Dependency>]
73
- def gem_item_dependencies(item)
74
- ::Gem::Specification.find_by_name(item.name).dependencies.select(&:runtime?)
75
- rescue ::Gem::MissingSpecError
76
- []
45
+ direct_path_to_require.camelize.constantize
77
46
  end
78
47
  end
79
48
  end
@@ -5,7 +5,7 @@ require 'eac_ruby_utils/regexp_parser'
5
5
  module EacRubyUtils
6
6
  class ObjectsTable
7
7
  BY_PARSER = ::EacRubyUtils::RegexpParser.new(/\Aby_([^!\?]+)(!)?\z/) do |m|
8
- BY_PARSER_PARSED_STRUCT.new(m[1], "by_attribute#{m[2].present? ? '!' : ''}")
8
+ BY_PARSER_PARSED_STRUCT.new(m[1], "by_attribute#{'!' if m[2].present?}")
9
9
  end
10
10
  BY_PARSER_PARSED_STRUCT = ::Struct.new(:attribute, :method_name)
11
11
 
@@ -7,6 +7,10 @@ module EacRubyUtils
7
7
  common_concern
8
8
 
9
9
  class_methods do
10
+ delegate :patch_module, to: :'::EacRubyUtils::PatchModule'
11
+ end
12
+
13
+ class << self
10
14
  def patch_module(target, patch)
11
15
  return if target.included_modules.include?(patch)
12
16
 
@@ -10,7 +10,7 @@ module Addressable
10
10
  end
11
11
 
12
12
  def query_value(*args)
13
- if args.count == 1
13
+ if args.one?
14
14
  query_value_get(*args)
15
15
  elsif args.count == 2
16
16
  query_value_set(*args)
@@ -4,6 +4,6 @@ require 'eac_ruby_utils/patch_module'
4
4
 
5
5
  class Module
6
6
  def patch_self(patch_module)
7
- ::EacRubyUtils.patch_module(self, patch_module)
7
+ ::EacRubyUtils::PatchModule.patch_module(self, patch_module)
8
8
  end
9
9
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/patch_module'
3
+ require 'eac_ruby_utils/patches/module/patch_self'
4
4
  require 'eac_ruby_utils/simple_cache'
5
5
 
6
6
  class Module
7
7
  def enable_simple_cache
8
- ::EacRubyUtils.patch_module(self, ::EacRubyUtils::SimpleCache)
8
+ patch_self(::EacRubyUtils::SimpleCache)
9
9
  end
10
10
  end
@@ -35,7 +35,7 @@ module EacRubyUtils
35
35
  added.include?(item) || to_check.include?(item)
36
36
  end
37
37
 
38
- def check_next_item
38
+ def check_next_item # rubocop:disable Naming/PredicateMethod
39
39
  return false unless to_check.any?
40
40
 
41
41
  item = to_check.shift
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/acts_as_instance_method'
4
+ require 'eac_ruby_utils/patches/object/to_pathname'
5
+ require 'eac_ruby_utils/patches/module/simple_cache'
6
+ require 'eac_ruby_utils/patches/pathname/basename_sub'
7
+
8
+ module EacRubyUtils
9
+ class RootModuleSetup
10
+ class Ignore
11
+ acts_as_instance_method
12
+ enable_simple_cache
13
+ common_constructor :setup, :path do
14
+ self.path = path.to_pathname
15
+ end
16
+ delegate :loader, :root_module_directory, to: :setup
17
+
18
+ # @return [Set]
19
+ def result
20
+ target_paths.each do |target_path|
21
+ expect_count_increment { loader.ignore target_path }
22
+ end
23
+ end
24
+
25
+ protected
26
+
27
+ # @return [Pathname]
28
+ def absolute_path_uncached
29
+ path.expand_path(root_module_directory)
30
+ end
31
+
32
+ # @return [Set]
33
+ def expect_count_increment
34
+ count_before = loader.send(:ignored_paths).count
35
+ result = yield
36
+ return result if result.count > count_before
37
+
38
+ raise ::ArgumentError, [
39
+ "Trying to ignore path \"#{path}\" did not increase the ignored paths.",
40
+ "Argument path: \"#{path}\"", "Target path: \"#{target_path}\"",
41
+ "Ignored paths: #{result}"
42
+ ].join("\n")
43
+ end
44
+
45
+ # @return [Pathname]
46
+ def target_paths_uncached
47
+ return [absolute_path] if %w[* ?].any? { |e| absolute_path.to_path.include?(e) }
48
+
49
+ r = []
50
+ r << absolute_path if absolute_path.directory?
51
+ r << [absolute_path.basename_sub { |b| "#{b.basename('.*')}.rb" }]
52
+ r
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/inflector'
4
- require 'eac_ruby_utils/patches/pathname'
5
- require 'eac_ruby_utils/patches/object/to_pathname'
4
+ require 'eac_ruby_utils/patches/module/require_sub'
6
5
  require 'zeitwerk'
7
6
 
8
7
  module EacRubyUtils
9
8
  class RootModuleSetup
9
+ require_sub __FILE__, require_mode: :kernel
10
+
10
11
  DEFAULT_NAMESPACE = ::Object
11
12
  LIB_DIRECTORY_BASENAME = 'lib'
12
13
 
@@ -34,18 +35,13 @@ module EacRubyUtils
34
35
  ::ActiveSupport::Inflector.constantize(dirname.classify)
35
36
  end
36
37
 
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")
38
+ # @return [Zeitwerk::GemLoader]
39
+ def loader
40
+ @loader ||= ::Zeitwerk::Registry.loader_for_gem(
41
+ root_module_file,
42
+ namespace: namespace,
43
+ warn_on_extra_files: true
44
+ )
49
45
  end
50
46
 
51
47
  # @return [Module]
@@ -94,14 +90,5 @@ module EacRubyUtils
94
90
  def perform_zeitwerk
95
91
  loader.setup
96
92
  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
106
93
  end
107
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.127.0'
4
+ VERSION = '0.128.1'
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.127.0
4
+ version: 0.128.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: 2025-06-02 00:00:00.000000000 Z
11
+ date: 2025-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -228,6 +228,8 @@ files:
228
228
  - lib/eac_ruby_utils/fs/temp/file.rb
229
229
  - lib/eac_ruby_utils/gems_registry.rb
230
230
  - lib/eac_ruby_utils/gems_registry/gem.rb
231
+ - lib/eac_ruby_utils/gems_registry/gem/dependencies.rb
232
+ - lib/eac_ruby_utils/gems_registry/gem/paths_to_require.rb
231
233
  - lib/eac_ruby_utils/inflector.rb
232
234
  - lib/eac_ruby_utils/listable.rb
233
235
  - lib/eac_ruby_utils/listable/class_methods.rb
@@ -331,6 +333,7 @@ files:
331
333
  - lib/eac_ruby_utils/require_sub/base.rb
332
334
  - lib/eac_ruby_utils/require_sub/sub_file.rb
333
335
  - lib/eac_ruby_utils/root_module_setup.rb
336
+ - lib/eac_ruby_utils/root_module_setup/ignore.rb
334
337
  - lib/eac_ruby_utils/rspec.rb
335
338
  - lib/eac_ruby_utils/rspec/default_setup.rb
336
339
  - lib/eac_ruby_utils/rspec/setup.rb