eac_ruby_utils 0.72.0 → 0.72.1

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: 5b24691000bd2898cc25e42008b85e0fd995ccb59469c90ed3605e188b6647b7
4
- data.tar.gz: 8f574e39585fad8cf17ebaedebad4effce286ee97d2e3b94365168f6b337b055
3
+ metadata.gz: 262c5b03a02ac07effc5ccac5108cbdc513aa73d61174a895416b8e954992da5
4
+ data.tar.gz: 4e7cc39170e0701152949c01ff4c645a92f4a4c768a3bd42785be48e8ae0e303
5
5
  SHA512:
6
- metadata.gz: 80d55c6dfe85ba433b85ab5564140fd392799a8a03e5608798c0ee6b74302cae8b4c181726d8c267546d98a512a35658ffefae984c5f96b1c3c0d916f3ca4aa2
7
- data.tar.gz: d30fac4198006b23d93bc2aa7f34913be7ff833260ec4eaf59efe10f4ed35f30686f34509f730349539bc53288a5149a7d2431ec47bed958259fad8c6b63b11a
6
+ metadata.gz: d5052fda81fdebe2467ceb52f443f0d38777417c3b070a8b7cd3aaa60a996bac8dfdc4cee9ec0ce2977e2a737595e3e5c1b3412e79bbca2f230ec3044625c563
7
+ data.tar.gz: 8f543e1fc5f8b194404fbf40f000d6d8fe1262788f9e4a8e59983ab00f3697ec201239e2a9a4945ca11ce1d0f7349b1a2255f50312130be4e404600df12a54c1
@@ -28,9 +28,8 @@ module EacRubyUtils
28
28
 
29
29
  # @return [Array<EacRubyUtils::GemsRegistry::Gem>]
30
30
  def all_gems
31
- ::Gem::Specification.map do |gemspec|
32
- ::EacRubyUtils::GemsRegistry::Gem.new(self, gemspec)
33
- end
31
+ ::Gem::Specification.map { |gemspec| ::EacRubyUtils::GemsRegistry::Gem.new(self, gemspec) }
32
+ .sort
34
33
  end
35
34
  end
36
35
  end
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/core_ext/string/inflections'
4
+ require 'eac_ruby_utils/recursive_builder'
5
+ require 'eac_ruby_utils/simple_cache'
4
6
 
5
7
  module EacRubyUtils
6
8
  class GemsRegistry
7
9
  class Gem
10
+ include ::Comparable
11
+ include ::EacRubyUtils::SimpleCache
12
+
8
13
  attr_reader :registry, :gemspec
9
14
 
10
15
  def initialize(registry, gemspec)
@@ -12,6 +17,23 @@ module EacRubyUtils
12
17
  @gemspec = gemspec
13
18
  end
14
19
 
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
+ def <=>(other)
29
+ sd = depend_on(other)
30
+ od = other.depend_on(self)
31
+ return 1 if sd && !od
32
+ return -1 if od && !sd
33
+
34
+ gemspec.name <=> other.gemspec.name
35
+ end
36
+
15
37
  def found?
16
38
  lib_file_found? && registered_module.is_a?(::Module)
17
39
  end
@@ -34,6 +56,20 @@ module EacRubyUtils
34
56
  def path_to_require
35
57
  gemspec.name.gsub('-', '/') + '/' + registry.module_suffix.underscore
36
58
  end
59
+
60
+ private
61
+
62
+ def dependencies_uncached
63
+ ::EacRubyUtils::RecursiveBuilder
64
+ .new(gemspec) { |item| gem_item_dependencies(item) }
65
+ .result
66
+ end
67
+
68
+ def gem_item_dependencies(item)
69
+ ::Gem::Specification.find_by_name(item.name).dependencies
70
+ rescue ::Gem::MissingSpecError
71
+ []
72
+ end
37
73
  end
38
74
  end
39
75
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/simple_cache'
4
+
5
+ module EacRubyUtils
6
+ class RecursiveBuilder
7
+ include ::EacRubyUtils::SimpleCache
8
+
9
+ attr_reader :root, :neighbors_block
10
+
11
+ def initialize(root, &neighbors_block)
12
+ @root = root
13
+ @neighbors_block = neighbors_block
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :added, :to_check
19
+
20
+ def result_uncached
21
+ @added = []
22
+ @to_check = []
23
+ item_try_add_to_check(root)
24
+ while check_next_item
25
+ # Do nothing
26
+ end
27
+ added
28
+ end
29
+
30
+ def item_try_add_to_check(item)
31
+ to_check << item unless item_added?(item)
32
+ end
33
+
34
+ def item_added?(item)
35
+ added.include?(item) || to_check.include?(item)
36
+ end
37
+
38
+ def check_next_item
39
+ return false unless to_check.any?
40
+
41
+ item = to_check.shift
42
+ added << item
43
+ item_neighborhs(item).each { |sub_item| item_try_add_to_check(sub_item) }
44
+ true
45
+ end
46
+
47
+ def item_neighborhs(item)
48
+ neighbors_block.call(item)
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.72.0'
4
+ VERSION = '0.72.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.72.0
4
+ version: 0.72.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-07-31 00:00:00.000000000 Z
11
+ date: 2021-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -202,6 +202,7 @@ files:
202
202
  - lib/eac_ruby_utils/patches/string/inflector.rb
203
203
  - lib/eac_ruby_utils/patches/time.rb
204
204
  - lib/eac_ruby_utils/patches/time/required_zone.rb
205
+ - lib/eac_ruby_utils/recursive_builder.rb
205
206
  - lib/eac_ruby_utils/regexp_parser.rb
206
207
  - lib/eac_ruby_utils/require_sub.rb
207
208
  - lib/eac_ruby_utils/rspec.rb