eac_ruby_utils 0.72.1 → 0.76.0

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: 262c5b03a02ac07effc5ccac5108cbdc513aa73d61174a895416b8e954992da5
4
- data.tar.gz: 4e7cc39170e0701152949c01ff4c645a92f4a4c768a3bd42785be48e8ae0e303
3
+ metadata.gz: '09b73f3a93332bc0d9ef7963c51ab545d9f40de9ffa6df3c09beaab2f788cc14'
4
+ data.tar.gz: 6574b30b1407c63bb3ff51fcda661c05622d663deabbd7032b5ad32635376902
5
5
  SHA512:
6
- metadata.gz: d5052fda81fdebe2467ceb52f443f0d38777417c3b070a8b7cd3aaa60a996bac8dfdc4cee9ec0ce2977e2a737595e3e5c1b3412e79bbca2f230ec3044625c563
7
- data.tar.gz: 8f543e1fc5f8b194404fbf40f000d6d8fe1262788f9e4a8e59983ab00f3697ec201239e2a9a4945ca11ce1d0f7349b1a2255f50312130be4e404600df12a54c1
6
+ metadata.gz: b7afb496fd00e1ed22f567673dce53a2a678dee0c95a06c664a5155ee19bdb2f4208a37cfd97ec26492ff78663558ead8be6c9e1f36cba36868a2319e326e8c1
7
+ data.tar.gz: 7378232e47c0b748669c68dd4e8125765a60b59628aba6c795061fc3c20a3609dff96fd80cbcbaa0e40a28b76e8c9aecbbd54436d039a0d7e419c37fdb491d08
@@ -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
@@ -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
@@ -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.1'
4
+ VERSION = '0.76.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.1
4
+ version: 0.76.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-08-08 00:00:00.000000000 Z
11
+ date: 2021-09-23 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
@@ -126,7 +127,6 @@ files:
126
127
  - lib/eac_ruby_utils/envs/ssh_env/identity_file.rb
127
128
  - lib/eac_ruby_utils/envs/ssh_env/quiet.rb
128
129
  - lib/eac_ruby_utils/envs/ssh_env/terminal.rb
129
- - lib/eac_ruby_utils/filesystem_cache.rb
130
130
  - lib/eac_ruby_utils/fs.rb
131
131
  - lib/eac_ruby_utils/fs/clearable_directory.rb
132
132
  - lib/eac_ruby_utils/fs/extname.rb
@@ -136,7 +136,6 @@ files:
136
136
  - lib/eac_ruby_utils/fs/temp/file.rb
137
137
  - lib/eac_ruby_utils/fs/traversable.rb
138
138
  - lib/eac_ruby_utils/fs/traverser.rb
139
- - lib/eac_ruby_utils/fs_cache.rb
140
139
  - lib/eac_ruby_utils/gems_registry.rb
141
140
  - lib/eac_ruby_utils/gems_registry/gem.rb
142
141
  - lib/eac_ruby_utils/immutable.rb
@@ -187,6 +186,7 @@ files:
187
186
  - lib/eac_ruby_utils/patches/module/speaker.rb
188
187
  - lib/eac_ruby_utils/patches/object.rb
189
188
  - lib/eac_ruby_utils/patches/object/asserts.rb
189
+ - lib/eac_ruby_utils/patches/object/compact.rb
190
190
  - lib/eac_ruby_utils/patches/object/debug.rb
191
191
  - lib/eac_ruby_utils/patches/object/if_nil.rb
192
192
  - lib/eac_ruby_utils/patches/object/if_present.rb
@@ -199,6 +199,7 @@ files:
199
199
  - lib/eac_ruby_utils/patches/regexp/if_match.rb
200
200
  - lib/eac_ruby_utils/patches/regexp/to_parser.rb
201
201
  - lib/eac_ruby_utils/patches/string.rb
202
+ - lib/eac_ruby_utils/patches/string/delimited.rb
202
203
  - lib/eac_ruby_utils/patches/string/inflector.rb
203
204
  - lib/eac_ruby_utils/patches/time.rb
204
205
  - lib/eac_ruby_utils/patches/time/required_zone.rb
@@ -219,6 +220,7 @@ files:
219
220
  - lib/eac_ruby_utils/speaker.rb
220
221
  - lib/eac_ruby_utils/speaker/receiver.rb
221
222
  - lib/eac_ruby_utils/speaker/sender.rb
223
+ - lib/eac_ruby_utils/string_delimited.rb
222
224
  - lib/eac_ruby_utils/struct.rb
223
225
  - lib/eac_ruby_utils/version.rb
224
226
  - lib/eac_ruby_utils/yaml.rb
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EacRubyUtils
4
- class FilesystemCache
5
- CONTENT_FILE_NAME = '__content__'
6
-
7
- attr_reader :path
8
-
9
- def initialize(*path_parts)
10
- raise ArgumentError, "\"#{path_parts}\" is empty" if path_parts.empty?
11
-
12
- @path = ::File.expand_path(::File.join(*path_parts.map(&:to_s)))
13
- end
14
-
15
- def clear
16
- return unless cached?
17
-
18
- ::File.unlink(content_path)
19
- end
20
-
21
- def read
22
- return nil unless cached?
23
-
24
- ::File.read(content_path)
25
- end
26
-
27
- def read_or_cache
28
- write(yield) unless cached?
29
-
30
- read
31
- end
32
-
33
- def write(value)
34
- assert_directory_on_path
35
- ::File.write(content_path, value)
36
- value
37
- end
38
-
39
- def child(*child_path_parts)
40
- self.class.new(path, *child_path_parts)
41
- end
42
-
43
- def cached?
44
- ::File.exist?(content_path)
45
- end
46
-
47
- def content_path
48
- ::File.join(path, CONTENT_FILE_NAME)
49
- end
50
-
51
- private
52
-
53
- def assert_directory_on_path
54
- raise "#{path} is a file" if ::File.file?(path)
55
-
56
- ::FileUtils.mkdir_p(path)
57
- end
58
- end
59
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/filesystem_cache'
4
- require 'tmpdir'
5
-
6
- module EacRubyUtils
7
- class << self
8
- def fs_cache
9
- @fs_cache ||= ::EacRubyUtils::FilesystemCache.new(::Dir.tmpdir, 'eac_ruby_utils', '.cache')
10
- end
11
- end
12
- end