eac_ruby_utils 0.27.0 → 0.28.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 +4 -4
- data/lib/eac_ruby_utils/custom_format.rb +53 -0
- data/lib/eac_ruby_utils/fs/traversable.rb +47 -0
- data/lib/eac_ruby_utils/fs/traverser.rb +74 -0
- data/lib/eac_ruby_utils/fs.rb +9 -0
- data/lib/eac_ruby_utils/patches/class/common_constructor.rb +2 -2
- data/lib/eac_ruby_utils/version.rb +1 -1
- data/lib/eac_ruby_utils.rb +1 -19
- metadata +6 -3
- data/lib/eac_ruby_utils/filesystem_traverser.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b13fd043a71f9c041b8f3480e6a90381baba9c2738c7aea8e9d12a8c86ab827b
|
4
|
+
data.tar.gz: b0bcf3b1c78333b58f909b4926a239c35bc28a5d08b235d0a43fed8d07c8d225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d4c591e636688bf439bd7e1ff05788725ef13a30a2558ce640cbdc62b6d5bce593f27543ae2a9fc0df629a4403b25524ddbe420cfa833d2aa0e063788cf88d
|
7
|
+
data.tar.gz: 2dc4524a56bfd3106abea448f98f03f06d72a6fa250bea0f27c0b469c6af731d125c07af482d8b2b3990eb4696fcdedea1829c2d2eab3c8167794f26774a626f
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
# A formatter like [String.sprintf].
|
5
|
+
class CustomFormat
|
6
|
+
TYPE_PATTERN = /[a-zA-Z]/.freeze
|
7
|
+
SEQUENCE_PATTERN = /(?<!%)%(#{TYPE_PATTERN})/.freeze
|
8
|
+
|
9
|
+
attr_reader :mapping
|
10
|
+
|
11
|
+
def initialize(mapping)
|
12
|
+
@mapping = mapping.map { |k, v| [k.to_sym, v] }.to_h.freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
def format(string)
|
16
|
+
::EacRubyUtils::CustomFormat::String.new(self, string)
|
17
|
+
end
|
18
|
+
|
19
|
+
class String
|
20
|
+
attr_reader :format, :string
|
21
|
+
|
22
|
+
def initialize(format, string)
|
23
|
+
@format = format
|
24
|
+
@string = string
|
25
|
+
end
|
26
|
+
|
27
|
+
def mapping
|
28
|
+
@mapping ||= format.mapping.select do |k, _v|
|
29
|
+
sequences.include?(k)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def sequences
|
34
|
+
@sequences ||= string.scan(SEQUENCE_PATTERN).map(&:first).uniq.map(&:to_sym)
|
35
|
+
end
|
36
|
+
|
37
|
+
def source_object_value(object, method)
|
38
|
+
return object.send(method) if object.respond_to?(method)
|
39
|
+
return object[method] if object.respond_to?('[]')
|
40
|
+
|
41
|
+
raise ::ArgumentError, "Methods \"#{method}\" or \"[]\" not found for #{object}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def with(source_object)
|
45
|
+
r = string
|
46
|
+
mapping.each do |key, method|
|
47
|
+
r = r.gsub(/%#{::Regexp.quote(key)}/, source_object_value(source_object, method).to_s)
|
48
|
+
end
|
49
|
+
r.gsub('%%', '%')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/fs/traverser'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Fs
|
7
|
+
module Traversable
|
8
|
+
PROP_METHOD_PREFIX = 'traverser_'
|
9
|
+
BOOLEAN_PROPS = %i[hidden_directories recursive sort].freeze
|
10
|
+
PATH_PROPS = %i[check_directory check_file].freeze
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def prop_method_name(prop)
|
14
|
+
"#{PROP_METHOD_PREFIX}#{prop}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
PATH_PROPS.each do |method|
|
19
|
+
define_method(::EacRubyUtils::Fs::Traversable.prop_method_name(method)) do |_path|
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
BOOLEAN_PROPS.each do |method|
|
25
|
+
define_method(::EacRubyUtils::Fs::Traversable.prop_method_name(method)) do
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
define_method("#{::EacRubyUtils::Fs::Traversable.prop_method_name(method)}?") do
|
30
|
+
send(method_name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def traverser_check_path(path)
|
35
|
+
traverser_new.check_path(path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def traverser_new
|
39
|
+
r = ::EacRubyUtils::Fs::Traverser.new
|
40
|
+
(BOOLEAN_PROPS + PATH_PROPS).each do |prop|
|
41
|
+
r.send("#{prop}=", method(::EacRubyUtils::Fs::Traversable.prop_method_name(prop)))
|
42
|
+
end
|
43
|
+
r
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Fs
|
5
|
+
class Traverser
|
6
|
+
attr_accessor :check_directory, :check_file, :recursive, :hidden_directories, :sort
|
7
|
+
|
8
|
+
def check_path(path)
|
9
|
+
path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
|
10
|
+
internal_check_path(path, 0)
|
11
|
+
end
|
12
|
+
|
13
|
+
def hidden_directories?
|
14
|
+
boolean_value(hidden_directories)
|
15
|
+
end
|
16
|
+
|
17
|
+
def recursive?
|
18
|
+
boolean_value(recursive)
|
19
|
+
end
|
20
|
+
|
21
|
+
def sort?
|
22
|
+
boolean_value(sort)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def boolean_value(source_value)
|
28
|
+
source_value = source_value.call if source_value.respond_to?(:call)
|
29
|
+
source_value ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def each_child(dir, &block)
|
33
|
+
if sort?
|
34
|
+
dir.each_child.sort_by { |p| [p.to_s] }.each(&block)
|
35
|
+
else
|
36
|
+
dir.each_child(&block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def process_directory?(level)
|
41
|
+
level.zero? || recursive?
|
42
|
+
end
|
43
|
+
|
44
|
+
def inner_check_directory(dir, level)
|
45
|
+
return unless process_directory?(level)
|
46
|
+
|
47
|
+
user_check_directory(dir)
|
48
|
+
each_child(dir) do |e|
|
49
|
+
next unless !e.basename.to_s.start_with?('.') || hidden_directories?
|
50
|
+
|
51
|
+
internal_check_path(e, level + 1)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def internal_check_path(path, level)
|
56
|
+
if path.file?
|
57
|
+
user_check_file(path)
|
58
|
+
elsif path.directory?
|
59
|
+
inner_check_directory(path, level)
|
60
|
+
else
|
61
|
+
raise "Unknown filesystem object: #{path}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def user_check_file(path)
|
66
|
+
check_file&.call(path)
|
67
|
+
end
|
68
|
+
|
69
|
+
def user_check_directory(path)
|
70
|
+
check_directory&.call(path)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'eac_ruby_utils/common_constructor'
|
4
4
|
|
5
5
|
class Class
|
6
|
-
def common_constructor(*args)
|
7
|
-
::EacRubyUtils::CommonConstructor.new(*args).setup_class(self)
|
6
|
+
def common_constructor(*args, &block)
|
7
|
+
::EacRubyUtils::CommonConstructor.new(*args, &block).setup_class(self)
|
8
8
|
end
|
9
9
|
end
|
data/lib/eac_ruby_utils.rb
CHANGED
@@ -1,24 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module EacRubyUtils
|
4
|
-
require 'eac_ruby_utils/arguments_consumer'
|
5
|
-
require 'eac_ruby_utils/by_reference'
|
6
|
-
require 'eac_ruby_utils/configs'
|
7
|
-
require 'eac_ruby_utils/console'
|
8
|
-
require 'eac_ruby_utils/contextualizable'
|
9
|
-
require 'eac_ruby_utils/core_ext'
|
10
|
-
require 'eac_ruby_utils/envs'
|
11
|
-
require 'eac_ruby_utils/filesystem_cache'
|
12
|
-
require 'eac_ruby_utils/filesystem_traverser'
|
13
|
-
require 'eac_ruby_utils/fs_cache'
|
14
|
-
require 'eac_ruby_utils/listable'
|
15
|
-
require 'eac_ruby_utils/options_consumer'
|
16
|
-
require 'eac_ruby_utils/settings_provider'
|
17
|
-
require 'eac_ruby_utils/patch'
|
18
|
-
require 'eac_ruby_utils/patches'
|
19
|
-
require 'eac_ruby_utils/paths_hash'
|
20
4
|
require 'eac_ruby_utils/require_sub'
|
21
|
-
|
22
|
-
require 'eac_ruby_utils/simple_cache'
|
23
|
-
require 'eac_ruby_utils/yaml'
|
5
|
+
::EacRubyUtils.require_sub __FILE__
|
24
6
|
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.
|
4
|
+
version: 0.28.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: 2020-04-
|
11
|
+
date: 2020-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/eac_ruby_utils/console/speaker/node.rb
|
122
122
|
- lib/eac_ruby_utils/contextualizable.rb
|
123
123
|
- lib/eac_ruby_utils/core_ext.rb
|
124
|
+
- lib/eac_ruby_utils/custom_format.rb
|
124
125
|
- lib/eac_ruby_utils/envs.rb
|
125
126
|
- lib/eac_ruby_utils/envs/base_env.rb
|
126
127
|
- lib/eac_ruby_utils/envs/command.rb
|
@@ -132,7 +133,9 @@ files:
|
|
132
133
|
- lib/eac_ruby_utils/envs/spawn.rb
|
133
134
|
- lib/eac_ruby_utils/envs/ssh_env.rb
|
134
135
|
- lib/eac_ruby_utils/filesystem_cache.rb
|
135
|
-
- lib/eac_ruby_utils/
|
136
|
+
- lib/eac_ruby_utils/fs.rb
|
137
|
+
- lib/eac_ruby_utils/fs/traversable.rb
|
138
|
+
- lib/eac_ruby_utils/fs/traverser.rb
|
136
139
|
- lib/eac_ruby_utils/fs_cache.rb
|
137
140
|
- lib/eac_ruby_utils/listable.rb
|
138
141
|
- lib/eac_ruby_utils/listable/class_methods.rb
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EacRubyUtils
|
4
|
-
class FilesystemTraverser
|
5
|
-
attr_accessor :check_directory, :check_file, :recursive, :hidden_directories, :sort
|
6
|
-
|
7
|
-
def check_path(path)
|
8
|
-
path = ::Pathname.new(path.to_s) unless path.is_a?(::Pathname)
|
9
|
-
internal_check_path(path, 0)
|
10
|
-
end
|
11
|
-
|
12
|
-
def hidden_directories?
|
13
|
-
hidden_directories ? true : false
|
14
|
-
end
|
15
|
-
|
16
|
-
def recursive?
|
17
|
-
recursive ? true : false
|
18
|
-
end
|
19
|
-
|
20
|
-
def sort?
|
21
|
-
sort ? true : false
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def each_child(dir, &block)
|
27
|
-
if sort?
|
28
|
-
dir.each_child.sort_by { |p| [p.to_s] }.each(&block)
|
29
|
-
else
|
30
|
-
dir.each_child(&block)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def process_directory?(level)
|
35
|
-
level.zero? || recursive?
|
36
|
-
end
|
37
|
-
|
38
|
-
def inner_check_directory(dir, level)
|
39
|
-
return unless process_directory?(level)
|
40
|
-
|
41
|
-
user_check_directory(dir)
|
42
|
-
each_child(dir) do |e|
|
43
|
-
next unless !e.basename.to_s.start_with?('.') || hidden_directories?
|
44
|
-
|
45
|
-
internal_check_path(dir.join(e), level + 1)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def internal_check_path(path, level)
|
50
|
-
if path.file?
|
51
|
-
user_check_file(path)
|
52
|
-
elsif path.directory?
|
53
|
-
inner_check_directory(path, level)
|
54
|
-
else
|
55
|
-
raise "Unknown filesystem object: #{path}"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def user_check_file(path)
|
60
|
-
check_file&.call(path)
|
61
|
-
end
|
62
|
-
|
63
|
-
def user_check_directory(path)
|
64
|
-
check_directory&.call(path)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|