eac_ruby_utils 0.77.0 → 0.80.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/compare_by.rb +28 -0
- data/lib/eac_ruby_utils/core_ext.rb +1 -0
- data/lib/eac_ruby_utils/enum.rb +102 -0
- data/lib/eac_ruby_utils/gems_registry/gem.rb +4 -0
- data/lib/eac_ruby_utils/gems_registry.rb +1 -1
- data/lib/eac_ruby_utils/patches/module/compare_by.rb +9 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +5 -5
- data/lib/eac_ruby_utils/fs/traversable.rb +0 -47
- data/lib/eac_ruby_utils/fs/traverser.rb +0 -72
- data/lib/eac_ruby_utils/on_clean_ruby_environment.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6933141ed3e3fd7368dadec28e6fbb7dce7510f90e8938f721c8ad19550ca68
|
|
4
|
+
data.tar.gz: 2f0aae05e9b1ec61dea7b9f0ae4894bcf4f3f6ffef5bf3169fc3397dc99a3dc0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3329528886bd52798bf9773dd13bf76e8fd8cb932fd152755ca5537a5da7b14a92139ddab81ab2e45357e6063608ba9c1eb5e1dd83306f297799755d4e2ad5f
|
|
7
|
+
data.tar.gz: 419c602edc61ef54f06004298ecae4c8c9c29c3419b96b9a335fd2804e554dc97b170a25c3a66ff4a79c0c433357309d8d958632ecb22f1c8c883ffab1a806f7
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/common_concern/module_setup'
|
|
4
|
+
|
|
5
|
+
module EacRubyUtils
|
|
6
|
+
class CompareBy
|
|
7
|
+
attr_reader :fields
|
|
8
|
+
|
|
9
|
+
def initialize(fields)
|
|
10
|
+
@fields = fields
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def apply(klass)
|
|
14
|
+
pself = self
|
|
15
|
+
klass.include(::Comparable)
|
|
16
|
+
%i[<=> eql?].each do |cmp_method|
|
|
17
|
+
klass.define_method(cmp_method) do |other|
|
|
18
|
+
pself.object_values(self).send(cmp_method, pself.object_values(other))
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
klass.define_method(:hash) { pself.object_values(self).hash }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def object_values(object)
|
|
25
|
+
fields.map { |field| object.send(field) }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/inflector'
|
|
4
|
+
|
|
5
|
+
module EacRubyUtils
|
|
6
|
+
# Similar to Java's enum type (https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html).
|
|
7
|
+
class Enum
|
|
8
|
+
class << self
|
|
9
|
+
def enum(key, *args, &block)
|
|
10
|
+
value = Value.new(self, key, args, &block)
|
|
11
|
+
raise ::ArgumentError, "#{self} already has a value with key=#{value.key}" if
|
|
12
|
+
value_set.include?(value)
|
|
13
|
+
|
|
14
|
+
value_set << value.apply
|
|
15
|
+
|
|
16
|
+
self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def values
|
|
20
|
+
value_set.map(&:value)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def value_set
|
|
26
|
+
@value_set ||= []
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
attr_reader :key
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
|
|
34
|
+
def initialize(key)
|
|
35
|
+
@key = key
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Value
|
|
39
|
+
include ::Comparable
|
|
40
|
+
|
|
41
|
+
attr_reader :klass, :key, :args, :block
|
|
42
|
+
|
|
43
|
+
def initialize(klass, key, args, &block)
|
|
44
|
+
@klass = klass
|
|
45
|
+
@key = ::EacRubyUtils::Inflector.variableize(key.to_s).to_sym
|
|
46
|
+
@args = args
|
|
47
|
+
@block = block
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def <=>(other)
|
|
51
|
+
key <=> other.key
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def apply
|
|
55
|
+
define_constant
|
|
56
|
+
define_class_method
|
|
57
|
+
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @return [String]
|
|
62
|
+
def class_method_name
|
|
63
|
+
key.to_s
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @return [String]
|
|
67
|
+
def constant_name
|
|
68
|
+
class_method_name.upcase
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def value
|
|
72
|
+
@value ||= uncached_value
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def define_class_method
|
|
78
|
+
the_value = self
|
|
79
|
+
klass.define_singleton_method(class_method_name) { the_value.value }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def define_constant
|
|
83
|
+
klass.const_set(constant_name, value)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def uncached_value
|
|
87
|
+
klass.new(key, *value_args)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def value_args
|
|
91
|
+
r = if block
|
|
92
|
+
block.call
|
|
93
|
+
elsif args.count == 1 && args.first.is_a?(::Enumerable)
|
|
94
|
+
args.first
|
|
95
|
+
else
|
|
96
|
+
args
|
|
97
|
+
end
|
|
98
|
+
r.is_a?(::Enumerable) ? r : [r]
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
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.80.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-
|
|
11
|
+
date: 2021-11-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -107,10 +107,12 @@ files:
|
|
|
107
107
|
- lib/eac_ruby_utils/common_constructor/instance_initialize.rb
|
|
108
108
|
- lib/eac_ruby_utils/common_constructor/super_args.rb
|
|
109
109
|
- lib/eac_ruby_utils/compact.rb
|
|
110
|
+
- lib/eac_ruby_utils/compare_by.rb
|
|
110
111
|
- lib/eac_ruby_utils/context.rb
|
|
111
112
|
- lib/eac_ruby_utils/contextualizable.rb
|
|
112
113
|
- lib/eac_ruby_utils/core_ext.rb
|
|
113
114
|
- lib/eac_ruby_utils/custom_format.rb
|
|
115
|
+
- lib/eac_ruby_utils/enum.rb
|
|
114
116
|
- lib/eac_ruby_utils/envs.rb
|
|
115
117
|
- lib/eac_ruby_utils/envs/base_env.rb
|
|
116
118
|
- lib/eac_ruby_utils/envs/command.rb
|
|
@@ -134,8 +136,6 @@ files:
|
|
|
134
136
|
- lib/eac_ruby_utils/fs/temp.rb
|
|
135
137
|
- lib/eac_ruby_utils/fs/temp/directory.rb
|
|
136
138
|
- lib/eac_ruby_utils/fs/temp/file.rb
|
|
137
|
-
- lib/eac_ruby_utils/fs/traversable.rb
|
|
138
|
-
- lib/eac_ruby_utils/fs/traverser.rb
|
|
139
139
|
- lib/eac_ruby_utils/gems_registry.rb
|
|
140
140
|
- lib/eac_ruby_utils/gems_registry/gem.rb
|
|
141
141
|
- lib/eac_ruby_utils/immutable.rb
|
|
@@ -157,7 +157,6 @@ files:
|
|
|
157
157
|
- lib/eac_ruby_utils/listable/symbol_list.rb
|
|
158
158
|
- lib/eac_ruby_utils/listable/value.rb
|
|
159
159
|
- lib/eac_ruby_utils/local_time_zone.rb
|
|
160
|
-
- lib/eac_ruby_utils/on_clean_ruby_environment.rb
|
|
161
160
|
- lib/eac_ruby_utils/options_consumer.rb
|
|
162
161
|
- lib/eac_ruby_utils/patch.rb
|
|
163
162
|
- lib/eac_ruby_utils/patches.rb
|
|
@@ -179,6 +178,7 @@ files:
|
|
|
179
178
|
- lib/eac_ruby_utils/patches/module.rb
|
|
180
179
|
- lib/eac_ruby_utils/patches/module/abstract_methods.rb
|
|
181
180
|
- lib/eac_ruby_utils/patches/module/common_concern.rb
|
|
181
|
+
- lib/eac_ruby_utils/patches/module/compare_by.rb
|
|
182
182
|
- lib/eac_ruby_utils/patches/module/context.rb
|
|
183
183
|
- lib/eac_ruby_utils/patches/module/i18n_translate.rb
|
|
184
184
|
- lib/eac_ruby_utils/patches/module/immutable.rb
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def user_check_file(path)
|
|
64
|
-
check_file&.call(path)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def user_check_directory(path)
|
|
68
|
-
check_directory&.call(path)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'eac_ruby_utils/ruby/on_clean_environment'
|
|
4
|
-
|
|
5
|
-
module EacRubyUtils
|
|
6
|
-
class << self
|
|
7
|
-
# <b>DEPRECATED:</b> Please use <tt>EacRubyUtils::Ruby.on_clean_environment</tt> instead.
|
|
8
|
-
def on_clean_ruby_environment(*args, &block)
|
|
9
|
-
::EacRubyUtils::Ruby.on_clean_environment(*args, &block)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|