eac_ruby_utils 0.77.1 → 0.80.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: f1a79aa784bfe4145425cd5cca34210521f7b818b13bc65c1aa2c99c67e03051
4
- data.tar.gz: 42d937120bef307923cd21e98186969051b9c223e5cf7843f72a823839ca07a6
3
+ metadata.gz: 1179fc3ebeef4795b3750c2579c2a42610ddca10bb96319a2b0a0165ebff1442
4
+ data.tar.gz: 0cc302d2b05fb618ac4e92724390eaf2f4f9b52f17449991371ba53b8d15dcca
5
5
  SHA512:
6
- metadata.gz: 618a01a7a7ca796801a4373ce304940806cc9200bd0bf434f239743b329a99981c39fb44f7f4b5167174963a8e1c4ca34abec704f15574c63abd357d02878783
7
- data.tar.gz: 257ae2e8c83d1958ce533f55c9b6bd307ac414ff02e14064aa0a58bc5f63761bbc4ef7257b3442280f31aae998d18a6f3badc683d2f9806c459c03c983076b3b
6
+ metadata.gz: cde6c8f63172f39c586b4ce88f9220b2c8cec78f06ae51118e4eda82938a2931e6c356f0017a69b53c2f48653970fccfa0e91ef533966a5b31d1de2b00612d73
7
+ data.tar.gz: 78b2de9f9f9b1e42a50d732e3ad6d5cbf1d7ee16ce210715344a6a2d7d2dc6795f0e2be8ab3e46aa180a50f4f15e8c7f1a536e2ba3ee91002a683d133fad2ab9
@@ -60,7 +60,8 @@ module EacRubyUtils
60
60
  end
61
61
 
62
62
  def raise_abstract_method(method_name)
63
- raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\""
63
+ raise ::NoMethodError, "Abstract method \"#{method_name}\" hit in \"#{self}\"" \
64
+ " (Class: #{self.class})"
64
65
  end
65
66
  end
66
67
  end
@@ -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
@@ -3,3 +3,4 @@
3
3
  require 'eac_ruby_utils/patches'
4
4
  require 'active_support/dependencies/autoload'
5
5
  require 'active_support/core_ext'
6
+ require 'active_support/json'
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/compare_by'
4
+
5
+ class Module
6
+ def compare_by(*fields)
7
+ ::EacRubyUtils::CompareBy.new(fields).apply(self)
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.77.1'
4
+ VERSION = '0.80.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.77.1
4
+ version: 0.80.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-10-15 00:00:00.000000000 Z
11
+ date: 2021-11-26 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