eac_ruby_utils 0.72.0 → 0.75.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: 5b24691000bd2898cc25e42008b85e0fd995ccb59469c90ed3605e188b6647b7
4
- data.tar.gz: 8f574e39585fad8cf17ebaedebad4effce286ee97d2e3b94365168f6b337b055
3
+ metadata.gz: 68abbc7acfbe86b2e24bb721047ef23e0d99c7444c9d97e107db9adbb92adca8
4
+ data.tar.gz: af3d13481855122ae753eaaf0ed1dec94ec620524d03cf358592573405017399
5
5
  SHA512:
6
- metadata.gz: 80d55c6dfe85ba433b85ab5564140fd392799a8a03e5608798c0ee6b74302cae8b4c181726d8c267546d98a512a35658ffefae984c5f96b1c3c0d916f3ca4aa2
7
- data.tar.gz: d30fac4198006b23d93bc2aa7f34913be7ff833260ec4eaf59efe10f4ed35f30686f34509f730349539bc53288a5149a7d2431ec47bed958259fad8c6b63b11a
6
+ metadata.gz: '0041989ecacd0b99a2a699fd2fbbceebf22f002360c8f4ef1b622bce4975d230e42b8912b4236d3d653b55a9864c00873be0222ac33ecf8b1efc588880c4bb23'
7
+ data.tar.gz: 0a030761ca0ae9030bd68421b8c6e1cbd883ffcae51e947241821deef8c887fcf99819ef2fc7c3f2912c962b81c7c35271950934c87553839923a492af698e8b
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class Compact
5
+ attr_reader :object, :attributes
6
+
7
+ def initialize(object, attributes)
8
+ @object = object
9
+ @attributes = attributes
10
+ end
11
+
12
+ # @return [Array]
13
+ def to_a
14
+ attributes.map { |attr| object.send(attr) }
15
+ end
16
+
17
+ # @return [Hash]
18
+ def to_h
19
+ attributes.map { |attr| [attr.to_sym, object.send(attr)] }.to_h
20
+ end
21
+ end
22
+ end
@@ -6,7 +6,7 @@ require 'tmpdir'
6
6
  module EacRubyUtils
7
7
  class << self
8
8
  def fs_cache
9
- @fs_cache ||= ::EacRubyUtils::FilesystemCache.new(::Dir.tmpdir, 'eac_ruby_utils', '.cache')
9
+ @fs_cache ||= ::EacRubyUtils::FilesystemCache.new(::Dir.tmpdir, 'eac_ruby_utils_fs_cache')
10
10
  end
11
11
  end
12
12
  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
@@ -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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/compact'
4
+
5
+ class Object
6
+ # @return [EacRubyUtils::Compact]
7
+ def compact(*attributes)
8
+ ::EacRubyUtils::Compact.new(self, attributes)
9
+ end
10
+
11
+ # @return [Array]
12
+ def compact_to_a(*attributes)
13
+ compact(*attributes).to_a
14
+ end
15
+
16
+ # @return [Hash]
17
+ def compact_to_h(*attributes)
18
+ compact(*attributes).to_h
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/string_delimited'
4
+
5
+ class String
6
+ # @return [EacRubyUtils::StringDelimited]
7
+ def delimited(begin_delimiter, end_delimiter)
8
+ ::EacRubyUtils::StringDelimited.new(self, begin_delimiter, end_delimiter)
9
+ end
10
+
11
+ %w[inner outer without_inner without_outer].each do |method_suffix|
12
+ define_method "delimited_#{method_suffix}" do |begin_delimiter, end_delimiter|
13
+ delimited(begin_delimiter, end_delimiter).send(method_suffix)
14
+ end
15
+ end
16
+ 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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module EacRubyUtils
4
4
  module Rspec
5
- class Setup
5
+ module Setup
6
6
  module Conditionals
7
7
  def conditional(tag, &condition)
8
8
  message = condition.call
@@ -4,13 +4,9 @@ require 'eac_ruby_utils/core_ext'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Rspec
7
- class Setup
8
- require_sub __FILE__
9
- common_constructor :setup_obj
10
-
11
- def perform
12
- setup_obj.singleton_class.include(::EacRubyUtils::Rspec::Setup::Conditionals)
13
- end
7
+ module Setup
8
+ extend ::ActiveSupport::Concern
9
+ require_sub __FILE__, include_modules: true
14
10
  end
15
11
  end
16
12
  end
@@ -36,9 +36,14 @@ module EacRubyUtils
36
36
 
37
37
  def include_registry
38
38
  gems_registry.registered.each do |gem|
39
- gem.registered_module.new(self).perform
39
+ include_gem_registered(gem.registered_module)
40
40
  end
41
41
  end
42
+
43
+ # @param gem [EacRubyUtils::GemsRegistry::Gem]
44
+ def include_gem_registered(registered_module)
45
+ extend(registered_module)
46
+ end
42
47
  end
43
48
  end
44
49
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class StringDelimited
5
+ attr_reader :string, :begin_delimiter, :end_delimiter
6
+
7
+ def initialize(string, begin_delimiter, end_delimiter)
8
+ @string = string
9
+ @begin_delimiter = begin_delimiter
10
+ @end_delimiter = end_delimiter
11
+ end
12
+
13
+ def inner
14
+ between_indexes(content_index, end_index).to_s
15
+ end
16
+
17
+ def outer
18
+ between_indexes(begin_index, after_end_index).to_s
19
+ end
20
+
21
+ def without_inner
22
+ without_join(
23
+ between_indexes(sos_index, content_index), between_indexes(end_index, eos_index)
24
+ )
25
+ end
26
+
27
+ def without_outer
28
+ without_join(
29
+ between_indexes(sos_index, begin_index),
30
+ between_indexes(after_end_index, eos_index)
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ def after_end_index
37
+ end_index.if_present { |v| v + end_delimiter.length }
38
+ end
39
+
40
+ def begin_index
41
+ string.index(begin_delimiter)
42
+ end
43
+
44
+ def between_indexes(a_begin_index, a_end_index)
45
+ a_begin_index && a_end_index ? string[a_begin_index, a_end_index - a_begin_index] : nil
46
+ end
47
+
48
+ def content_index
49
+ begin_index.if_present { |v| v + begin_delimiter.length }
50
+ end
51
+
52
+ def without_join(*strings)
53
+ return string if strings.any?(&:nil?)
54
+
55
+ strings.join('')
56
+ end
57
+
58
+ def end_index
59
+ content_index.if_present { |_v| string.index(end_delimiter, content_index) }
60
+ end
61
+
62
+ def sos_index
63
+ 0
64
+ end
65
+
66
+ def eos_index
67
+ string.length
68
+ end
69
+ end
70
+ 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.75.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.72.0
4
+ version: 0.75.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-07-31 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: '0.3'
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 0.3.1
78
+ version: 0.3.2
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: '0.3'
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 0.3.1
88
+ version: 0.3.2
89
89
  description:
90
90
  email:
91
91
  executables: []
@@ -106,6 +106,7 @@ files:
106
106
  - lib/eac_ruby_utils/common_constructor/class_initialize.rb
107
107
  - lib/eac_ruby_utils/common_constructor/instance_initialize.rb
108
108
  - lib/eac_ruby_utils/common_constructor/super_args.rb
109
+ - lib/eac_ruby_utils/compact.rb
109
110
  - lib/eac_ruby_utils/context.rb
110
111
  - lib/eac_ruby_utils/contextualizable.rb
111
112
  - lib/eac_ruby_utils/core_ext.rb
@@ -187,6 +188,7 @@ files:
187
188
  - lib/eac_ruby_utils/patches/module/speaker.rb
188
189
  - lib/eac_ruby_utils/patches/object.rb
189
190
  - lib/eac_ruby_utils/patches/object/asserts.rb
191
+ - lib/eac_ruby_utils/patches/object/compact.rb
190
192
  - lib/eac_ruby_utils/patches/object/debug.rb
191
193
  - lib/eac_ruby_utils/patches/object/if_nil.rb
192
194
  - lib/eac_ruby_utils/patches/object/if_present.rb
@@ -199,9 +201,11 @@ files:
199
201
  - lib/eac_ruby_utils/patches/regexp/if_match.rb
200
202
  - lib/eac_ruby_utils/patches/regexp/to_parser.rb
201
203
  - lib/eac_ruby_utils/patches/string.rb
204
+ - lib/eac_ruby_utils/patches/string/delimited.rb
202
205
  - lib/eac_ruby_utils/patches/string/inflector.rb
203
206
  - lib/eac_ruby_utils/patches/time.rb
204
207
  - lib/eac_ruby_utils/patches/time/required_zone.rb
208
+ - lib/eac_ruby_utils/recursive_builder.rb
205
209
  - lib/eac_ruby_utils/regexp_parser.rb
206
210
  - lib/eac_ruby_utils/require_sub.rb
207
211
  - lib/eac_ruby_utils/rspec.rb
@@ -218,6 +222,7 @@ files:
218
222
  - lib/eac_ruby_utils/speaker.rb
219
223
  - lib/eac_ruby_utils/speaker/receiver.rb
220
224
  - lib/eac_ruby_utils/speaker/sender.rb
225
+ - lib/eac_ruby_utils/string_delimited.rb
221
226
  - lib/eac_ruby_utils/struct.rb
222
227
  - lib/eac_ruby_utils/version.rb
223
228
  - lib/eac_ruby_utils/yaml.rb