eac_ruby_utils 0.115.0 → 0.117.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/acts_as_abstract.rb +17 -6
- data/lib/eac_ruby_utils/acts_as_immutable/array_accessor.rb +25 -0
- data/lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb +57 -0
- data/lib/eac_ruby_utils/{immutable → acts_as_immutable}/boolean_accessor.rb +3 -3
- data/lib/eac_ruby_utils/{immutable → acts_as_immutable}/class_methods.rb +2 -2
- data/lib/eac_ruby_utils/{immutable → acts_as_immutable}/common_accessor.rb +5 -5
- data/lib/eac_ruby_utils/{immutable/array_accessor.rb → acts_as_immutable/enumerable_accessor.rb} +11 -8
- data/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor.rb +5 -5
- data/lib/eac_ruby_utils/{immutable → acts_as_immutable}/instance_methods.rb +1 -1
- data/lib/eac_ruby_utils/acts_as_immutable/set_accessor.rb +25 -0
- data/lib/eac_ruby_utils/{immutable.rb → acts_as_immutable.rb} +1 -1
- data/lib/eac_ruby_utils/enumerables_methods.rb +42 -0
- data/lib/eac_ruby_utils/envs/executable.rb +14 -2
- data/lib/eac_ruby_utils/module_ancestors_variable/base.rb +34 -0
- data/lib/eac_ruby_utils/module_ancestors_variable/hash.rb +20 -0
- data/lib/eac_ruby_utils/module_ancestors_variable/set.rb +19 -0
- data/lib/eac_ruby_utils/module_ancestors_variable.rb +9 -0
- data/lib/eac_ruby_utils/patches/module/acts_as_immutable.rb +10 -0
- data/lib/eac_ruby_utils/patches/module/immutable.rb +3 -2
- data/lib/eac_ruby_utils/patches/object/debug.rb +9 -0
- data/lib/eac_ruby_utils/unimplemented_method_error.rb +6 -0
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +19 -10
- data/lib/eac_ruby_utils/immutable/base_accessor.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82c2a8a36a2f001a3de7c0512e08f4fa9ca7b26b690cc264a682c52b5dc7e1fd
|
4
|
+
data.tar.gz: 605b80b24ca686a9d6775fe19a3652619817dc075eb0d6285621bbe4abdabf0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00179145dcc8ebc905fe2a8a06b72a27c9d97fed906205c39d30f7de8719262d65f1fde1aec6e585d9d19e916c050302ad0e138dacb6a383ee1ac50b916f7851'
|
7
|
+
data.tar.gz: 81d90fa7a83eff36436bc30951ff163a3edb23a8f86e0fe020e2abb7bf4bdba08de459c12bb90022cf0f615a8857786934dc17fa8594ba86f22f397961db1f34
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/module_ancestors_variable/hash'
|
3
4
|
require 'eac_ruby_utils/patches/class/self_included_modules'
|
4
5
|
require 'eac_ruby_utils/patches/module/common_concern'
|
6
|
+
require 'eac_ruby_utils/unimplemented_method_error'
|
5
7
|
|
6
8
|
module EacRubyUtils
|
7
9
|
# Support to abstract methods.
|
@@ -39,9 +41,7 @@ module EacRubyUtils
|
|
39
41
|
# @param arguments [Enumerable<Symbol>]
|
40
42
|
# @return [void]
|
41
43
|
def abstract_method(name, *arguments)
|
42
|
-
|
43
|
-
raise_abstract_method(name.to_sym, arguments)
|
44
|
-
end
|
44
|
+
abstract_methods_hash[name.to_sym] = arguments
|
45
45
|
end
|
46
46
|
|
47
47
|
# @param methods_names [Enumerable<Object>] Each item can be a symbolizable or a hash.
|
@@ -63,6 +63,12 @@ module EacRubyUtils
|
|
63
63
|
def abstract_methods_from_hash(hash)
|
64
64
|
hash.each { |name, arguments| abstract_method(name, *arguments) }
|
65
65
|
end
|
66
|
+
|
67
|
+
# @return [Hash<Symbol, Array]
|
68
|
+
def abstract_methods_hash
|
69
|
+
@abstract_methods_hash ||=
|
70
|
+
::EacRubyUtils::ModuleAncestorsVariable::Hash.new(self, __method__)
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
74
|
module InstanceMethods
|
@@ -76,13 +82,18 @@ module EacRubyUtils
|
|
76
82
|
super
|
77
83
|
end
|
78
84
|
|
85
|
+
# @param method_name [Symbol]
|
86
|
+
# @return [Boolean]
|
79
87
|
def abstract_method?(method_name)
|
80
|
-
self.class.
|
88
|
+
return false if self.class.method_defined?(method_name)
|
89
|
+
|
90
|
+
self.class.send(:abstract_methods_hash).key?(method_name.to_sym)
|
81
91
|
end
|
82
92
|
|
83
93
|
def raise_abstract_method(method_name, arguments = [])
|
84
|
-
raise ::
|
85
|
-
|
94
|
+
raise ::EacRubyUtils::UnimplementedMethodError,
|
95
|
+
"Abstract method #{method_name}(#{arguments.join(', ')}) hit in " \
|
96
|
+
"#{self}\" (Class: #{self.class})"
|
86
97
|
end
|
87
98
|
end
|
88
99
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/acts_as_immutable/enumerable_accessor'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module ActsAsImmutable
|
7
|
+
class ArrayAccessor < ::EacRubyUtils::ActsAsImmutable::EnumerableAccessor
|
8
|
+
INITIAL_VALUE = [].freeze
|
9
|
+
|
10
|
+
# @param value [Object]
|
11
|
+
# @return [Array]
|
12
|
+
def immutable_value_set_assert(value)
|
13
|
+
return value if value.is_a?(::Array)
|
14
|
+
return value.to_a if value.respond_to?(:to_a)
|
15
|
+
|
16
|
+
Array(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array] A empty array.
|
20
|
+
def initial_value
|
21
|
+
INITIAL_VALUE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/object/if_respond'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module ActsAsImmutable
|
7
|
+
class BaseAccessor
|
8
|
+
FILTER_GET_METHOD_NAME_FORMAT = '%s_get_filter'
|
9
|
+
FILTER_SET_METHOD_NAME_FORMAT = '%s_set_filter'
|
10
|
+
|
11
|
+
common_constructor :name do
|
12
|
+
self.name = name.to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
def duplicate_object(object)
|
16
|
+
accessor_new_value = yield(immutable_value_get(object))
|
17
|
+
new_values = object.send(:immutable_values_get).merge(name => accessor_new_value)
|
18
|
+
r = object.class.new(*object.immutable_constructor_args)
|
19
|
+
r.send(:immutable_values_set, new_values)
|
20
|
+
r
|
21
|
+
end
|
22
|
+
|
23
|
+
def immutable_value_get(object)
|
24
|
+
object.send(:immutable_values_get)[name]
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param object [Object]
|
28
|
+
# @return [Object]
|
29
|
+
def immutable_value_get_filtered(object)
|
30
|
+
r = immutable_value_get(object)
|
31
|
+
if object.respond_to?(immutable_value_get_filtered_method_name, true)
|
32
|
+
r = object.send(immutable_value_get_filtered_method_name, r)
|
33
|
+
end
|
34
|
+
r
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Symbol]
|
38
|
+
def immutable_value_get_filtered_method_name
|
39
|
+
format(FILTER_GET_METHOD_NAME_FORMAT, name)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param object [Object]
|
43
|
+
# @return [Object]
|
44
|
+
def immutable_value_set_filtered(object, value)
|
45
|
+
if object.respond_to?(immutable_value_set_filtered_method_name, true)
|
46
|
+
value = object.send(immutable_value_set_filtered_method_name, value)
|
47
|
+
end
|
48
|
+
immutable_value_set(object, value)
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Symbol]
|
52
|
+
def immutable_value_set_filtered_method_name
|
53
|
+
format(FILTER_SET_METHOD_NAME_FORMAT, name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_ruby_utils/
|
3
|
+
require 'eac_ruby_utils/acts_as_immutable/common_accessor'
|
4
4
|
require 'eac_ruby_utils/patches/class/common_constructor'
|
5
5
|
|
6
6
|
module EacRubyUtils
|
7
|
-
module
|
8
|
-
class BooleanAccessor < ::EacRubyUtils::
|
7
|
+
module ActsAsImmutable
|
8
|
+
class BooleanAccessor < ::EacRubyUtils::ActsAsImmutable::CommonAccessor
|
9
9
|
def apply(klass)
|
10
10
|
super
|
11
11
|
accessor = self
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module EacRubyUtils
|
4
|
-
module
|
4
|
+
module ActsAsImmutable
|
5
5
|
module ClassMethods
|
6
6
|
def immutable_accessor(*accessors)
|
7
7
|
options = accessors.extract_options!
|
8
8
|
options[:type] ||= const_get('TYPE_COMMON')
|
9
9
|
accessors.each do |name|
|
10
10
|
class_name = options.fetch(:type).to_s.camelize + 'Accessor'
|
11
|
-
::EacRubyUtils::
|
11
|
+
::EacRubyUtils::ActsAsImmutable.const_get(class_name).new(name).apply(self)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_ruby_utils/
|
3
|
+
require 'eac_ruby_utils/acts_as_immutable/base_accessor'
|
4
4
|
require 'eac_ruby_utils/patches/class/common_constructor'
|
5
5
|
|
6
6
|
module EacRubyUtils
|
7
|
-
module
|
8
|
-
class CommonAccessor < ::EacRubyUtils::
|
7
|
+
module ActsAsImmutable
|
8
|
+
class CommonAccessor < ::EacRubyUtils::ActsAsImmutable::BaseAccessor
|
9
9
|
def apply(klass)
|
10
10
|
accessor = self
|
11
11
|
klass.send(:define_method, name) do |*args|
|
12
12
|
case args.count
|
13
|
-
when 0 then next accessor.
|
14
|
-
when 1 then next accessor.
|
13
|
+
when 0 then next accessor.immutable_value_get_filtered(self)
|
14
|
+
when 1 then next accessor.immutable_value_set_filtered(self, args.first)
|
15
15
|
else
|
16
16
|
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
|
17
17
|
end
|
data/lib/eac_ruby_utils/{immutable/array_accessor.rb → acts_as_immutable/enumerable_accessor.rb}
RENAMED
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/inflector'
|
4
|
-
require 'eac_ruby_utils/
|
4
|
+
require 'eac_ruby_utils/acts_as_immutable/base_accessor'
|
5
5
|
require 'eac_ruby_utils/patches/class/common_constructor'
|
6
6
|
|
7
7
|
module EacRubyUtils
|
8
|
-
module
|
9
|
-
|
8
|
+
module ActsAsImmutable
|
9
|
+
# Should implement in concrect classes:
|
10
|
+
# * immutable_value_set_assert(value)
|
11
|
+
# * initial_value()
|
12
|
+
class EnumerableAccessor < ::EacRubyUtils::ActsAsImmutable::BaseAccessor
|
10
13
|
def apply(klass)
|
11
14
|
apply_singular(klass)
|
12
15
|
apply_plural(klass)
|
@@ -16,8 +19,8 @@ module EacRubyUtils
|
|
16
19
|
accessor = self
|
17
20
|
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do |*args|
|
18
21
|
case args.count
|
19
|
-
when 0 then next accessor.
|
20
|
-
when 1 then next accessor.
|
22
|
+
when 0 then next accessor.immutable_value_get_filtered(self)
|
23
|
+
when 1 then next accessor.immutable_value_set_filtered(self, args.first)
|
21
24
|
else
|
22
25
|
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
|
23
26
|
end
|
@@ -32,17 +35,17 @@ module EacRubyUtils
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def immutable_value_get(object)
|
35
|
-
super ||
|
38
|
+
super || initial_value.dup
|
36
39
|
end
|
37
40
|
|
38
41
|
def immutable_value_push(object, value)
|
39
42
|
duplicate_object(object) do |old_value|
|
40
|
-
(old_value ||
|
43
|
+
(old_value || initial_value.dup) + [value]
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
47
|
def immutable_value_set(object, value)
|
45
|
-
duplicate_object(object) { |_old_value| value }
|
48
|
+
duplicate_object(object) { |_old_value| immutable_value_set_assert(value) }
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_ruby_utils/
|
3
|
+
require 'eac_ruby_utils/acts_as_immutable/base_accessor'
|
4
4
|
require 'eac_ruby_utils/patches/class/common_constructor'
|
5
5
|
|
6
6
|
module EacRubyUtils
|
7
|
-
module
|
8
|
-
class HashAccessor < ::EacRubyUtils::
|
7
|
+
module ActsAsImmutable
|
8
|
+
class HashAccessor < ::EacRubyUtils::ActsAsImmutable::BaseAccessor
|
9
9
|
def apply(klass)
|
10
10
|
apply_plural(klass)
|
11
11
|
apply_singular(klass)
|
@@ -33,8 +33,8 @@ module EacRubyUtils
|
|
33
33
|
accessor = self
|
34
34
|
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do |*args|
|
35
35
|
case args.count
|
36
|
-
when 0 then next accessor.
|
37
|
-
when 1 then next accessor.
|
36
|
+
when 0 then next accessor.immutable_value_get_filtered(self)
|
37
|
+
when 1 then next accessor.immutable_value_set_filtered(self, args[0])
|
38
38
|
else
|
39
39
|
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
|
40
40
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/acts_as_immutable/enumerable_accessor'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module ActsAsImmutable
|
7
|
+
class SetAccessor < ::EacRubyUtils::ActsAsImmutable::EnumerableAccessor
|
8
|
+
INITIAL_VALUE = ::Set.new.freeze
|
9
|
+
|
10
|
+
# @param value [Object]
|
11
|
+
# @return [Set]
|
12
|
+
def immutable_value_set_assert(value)
|
13
|
+
return value if value.is_a?(::Set)
|
14
|
+
return value.to_set if value.respond_to?(:to_set)
|
15
|
+
|
16
|
+
::Set.new(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Set] A empty Set.
|
20
|
+
def initial_value
|
21
|
+
INITIAL_VALUE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/object/debug'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module EnumerablesMethods
|
7
|
+
class << self
|
8
|
+
WRITE_METHOD_PATTERNS = [/\A[a-z].*[\!\=]\z/i] +
|
9
|
+
%i[\[\]= <<].map { |m| /\A#{::Regexp.quote(m)}\z/ } +
|
10
|
+
%i[add clear delete divide keep reset shift subtract]
|
11
|
+
.map { |m| /\A#{::Regexp.quote(m)}.*\z/ }
|
12
|
+
|
13
|
+
# @param klass [Klass]
|
14
|
+
# @return [Enumerable<Symbol>]
|
15
|
+
def self_methods_names(klass)
|
16
|
+
(klass.public_instance_methods - klass.superclass.public_instance_methods).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param method_name [Symbol]
|
20
|
+
# @return [Boolean]
|
21
|
+
def write_method?(method_name)
|
22
|
+
WRITE_METHOD_PATTERNS.any? { |pattern| pattern.match?(method_name.to_s) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ARRAY_METHODS = self_methods_names(::Array)
|
27
|
+
ARRAY_WRITE_METHODS = ARRAY_METHODS.select { |m| write_method?(m) }
|
28
|
+
ARRAY_READ_METHODS = ARRAY_METHODS - ARRAY_WRITE_METHODS
|
29
|
+
|
30
|
+
ENUMERABLE_METHODS = ::Enumerable.public_instance_methods.sort
|
31
|
+
ENUMERABLE_WRITE_METHODS = ENUMERABLE_METHODS.select { |m| write_method?(m) }
|
32
|
+
ENUMERABLE_READ_METHODS = ENUMERABLE_METHODS - ENUMERABLE_WRITE_METHODS
|
33
|
+
|
34
|
+
HASH_METHODS = self_methods_names(::Hash)
|
35
|
+
HASH_WRITE_METHODS = HASH_METHODS.select { |m| write_method?(m) }
|
36
|
+
HASH_READ_METHODS = HASH_METHODS - HASH_WRITE_METHODS
|
37
|
+
|
38
|
+
SET_METHODS = self_methods_names(::Set)
|
39
|
+
SET_WRITE_METHODS = SET_METHODS.select { |m| write_method?(m) } + [:merge]
|
40
|
+
SET_READ_METHODS = SET_METHODS - SET_WRITE_METHODS
|
41
|
+
end
|
42
|
+
end
|
@@ -9,7 +9,7 @@ module EacRubyUtils
|
|
9
9
|
include ::EacRubyUtils::Listable
|
10
10
|
include ::EacRubyUtils::SimpleCache
|
11
11
|
|
12
|
-
lists.add_symbol :option, :check_args, :auto_validate
|
12
|
+
lists.add_symbol :option, :check_args, :exec_args, :auto_validate
|
13
13
|
|
14
14
|
DEFAULT_AUTO_VALIDATE = true
|
15
15
|
|
@@ -53,7 +53,7 @@ module EacRubyUtils
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def executable_args
|
56
|
-
executable_args_from_envvar ||
|
56
|
+
executable_args_from_envvar || executable_args_from_options || executable_args_from_name
|
57
57
|
end
|
58
58
|
|
59
59
|
def executable_args_envvar
|
@@ -64,6 +64,18 @@ module EacRubyUtils
|
|
64
64
|
ENV[executable_args_envvar].if_present { |v| ::Shellwords.split(v) }
|
65
65
|
end
|
66
66
|
|
67
|
+
# @return [Enumerable<String>]
|
68
|
+
def executable_args_from_name
|
69
|
+
::Shellwords.split(name)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [Enumerable<String>]
|
73
|
+
def executable_args_from_options
|
74
|
+
options[OPTION_EXEC_ARGS].if_present do |v|
|
75
|
+
v.is_a?(::Enumerable) ? v.map(&:to_s) : ::Shellwords.split(v.to_s)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
67
79
|
private
|
68
80
|
|
69
81
|
attr_writer :options
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/class/common_constructor'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module ModuleAncestorsVariable
|
7
|
+
class Base
|
8
|
+
common_constructor :the_module, :method_name, :initial_value
|
9
|
+
|
10
|
+
# @param current [Object]
|
11
|
+
# @param other [Object]
|
12
|
+
# @return [Object]
|
13
|
+
def merge_operation(current, other)
|
14
|
+
current.merge(other)
|
15
|
+
end
|
16
|
+
|
17
|
+
# return [Hash]
|
18
|
+
def ancestors_variable
|
19
|
+
the_module.ancestors.inject(initial_value.dup) do |a, e|
|
20
|
+
if e.respond_to?(method_name, true)
|
21
|
+
merge_operation(a, e.send(method_name).send(:self_variable))
|
22
|
+
else
|
23
|
+
a
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Hash]
|
29
|
+
def self_variable
|
30
|
+
@self_variable ||= initial_value.dup
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
require 'eac_ruby_utils/module_ancestors_variable/base'
|
5
|
+
require 'eac_ruby_utils/enumerables_methods'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
module ModuleAncestorsVariable
|
9
|
+
class Hash < ::EacRubyUtils::ModuleAncestorsVariable::Base
|
10
|
+
INITIAL_VALUE = {}.freeze
|
11
|
+
|
12
|
+
def initialize(the_module, method_name)
|
13
|
+
super(the_module, method_name, INITIAL_VALUE)
|
14
|
+
end
|
15
|
+
|
16
|
+
delegate(*::EacRubyUtils::EnumerablesMethods::HASH_READ_METHODS, to: :ancestors_variable)
|
17
|
+
delegate(*::EacRubyUtils::EnumerablesMethods::HASH_WRITE_METHODS, to: :self_variable)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
require 'eac_ruby_utils/module_ancestors_variable/base'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module ModuleAncestorsVariable
|
8
|
+
class Set < ::EacRubyUtils::ModuleAncestorsVariable::Base
|
9
|
+
INITIAL_VALUE = ::Set.new
|
10
|
+
|
11
|
+
def initialize(the_module, method_name)
|
12
|
+
super(the_module, method_name, INITIAL_VALUE)
|
13
|
+
end
|
14
|
+
|
15
|
+
delegate(*::EacRubyUtils::EnumerablesMethods::SET_READ_METHODS, to: :ancestors_variable)
|
16
|
+
delegate(*::EacRubyUtils::EnumerablesMethods::SET_WRITE_METHODS, to: :self_variable)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/patch'
|
4
|
-
require 'eac_ruby_utils/
|
4
|
+
require 'eac_ruby_utils/acts_as_immutable'
|
5
5
|
|
6
6
|
class Module
|
7
|
+
# @deprecated Use {#acts_as_immutable} instead.
|
7
8
|
def enable_immutable
|
8
|
-
::EacRubyUtils.patch(self, ::EacRubyUtils::
|
9
|
+
::EacRubyUtils.patch(self, ::EacRubyUtils::ActsAsImmutable)
|
9
10
|
end
|
10
11
|
end
|
@@ -1,6 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
4
|
+
require 'pp'
|
5
|
+
|
3
6
|
class Object
|
7
|
+
def compact_debug(*methods_names)
|
8
|
+
methods_names.each do |method_name|
|
9
|
+
send(method_name).print_debug(label: method_name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
def pretty_debug(options = {})
|
5
14
|
print_debug_options(options)
|
6
15
|
|
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.117.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: 2023-05-
|
11
|
+
date: 2023-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -129,6 +129,16 @@ files:
|
|
129
129
|
- README.rdoc
|
130
130
|
- lib/eac_ruby_utils.rb
|
131
131
|
- lib/eac_ruby_utils/acts_as_abstract.rb
|
132
|
+
- lib/eac_ruby_utils/acts_as_immutable.rb
|
133
|
+
- lib/eac_ruby_utils/acts_as_immutable/array_accessor.rb
|
134
|
+
- lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb
|
135
|
+
- lib/eac_ruby_utils/acts_as_immutable/boolean_accessor.rb
|
136
|
+
- lib/eac_ruby_utils/acts_as_immutable/class_methods.rb
|
137
|
+
- lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
|
138
|
+
- lib/eac_ruby_utils/acts_as_immutable/enumerable_accessor.rb
|
139
|
+
- lib/eac_ruby_utils/acts_as_immutable/hash_accessor.rb
|
140
|
+
- lib/eac_ruby_utils/acts_as_immutable/instance_methods.rb
|
141
|
+
- lib/eac_ruby_utils/acts_as_immutable/set_accessor.rb
|
132
142
|
- lib/eac_ruby_utils/arguments_consumer.rb
|
133
143
|
- lib/eac_ruby_utils/bit.rb
|
134
144
|
- lib/eac_ruby_utils/bit_array.rb
|
@@ -152,6 +162,7 @@ files:
|
|
152
162
|
- lib/eac_ruby_utils/core_ext.rb
|
153
163
|
- lib/eac_ruby_utils/custom_format.rb
|
154
164
|
- lib/eac_ruby_utils/enum.rb
|
165
|
+
- lib/eac_ruby_utils/enumerables_methods.rb
|
155
166
|
- lib/eac_ruby_utils/envs.rb
|
156
167
|
- lib/eac_ruby_utils/envs/base_command.rb
|
157
168
|
- lib/eac_ruby_utils/envs/base_command/append_command_options.rb
|
@@ -184,14 +195,6 @@ files:
|
|
184
195
|
- lib/eac_ruby_utils/fs/temp/file.rb
|
185
196
|
- lib/eac_ruby_utils/gems_registry.rb
|
186
197
|
- lib/eac_ruby_utils/gems_registry/gem.rb
|
187
|
-
- lib/eac_ruby_utils/immutable.rb
|
188
|
-
- lib/eac_ruby_utils/immutable/array_accessor.rb
|
189
|
-
- lib/eac_ruby_utils/immutable/base_accessor.rb
|
190
|
-
- lib/eac_ruby_utils/immutable/boolean_accessor.rb
|
191
|
-
- lib/eac_ruby_utils/immutable/class_methods.rb
|
192
|
-
- lib/eac_ruby_utils/immutable/common_accessor.rb
|
193
|
-
- lib/eac_ruby_utils/immutable/hash_accessor.rb
|
194
|
-
- lib/eac_ruby_utils/immutable/instance_methods.rb
|
195
198
|
- lib/eac_ruby_utils/inflector.rb
|
196
199
|
- lib/eac_ruby_utils/listable.rb
|
197
200
|
- lib/eac_ruby_utils/listable/class_methods.rb
|
@@ -208,6 +211,10 @@ files:
|
|
208
211
|
- lib/eac_ruby_utils/locales/from_gem.rb
|
209
212
|
- lib/eac_ruby_utils/locales/module_i18n_translate.rb
|
210
213
|
- lib/eac_ruby_utils/method_class.rb
|
214
|
+
- lib/eac_ruby_utils/module_ancestors_variable.rb
|
215
|
+
- lib/eac_ruby_utils/module_ancestors_variable/base.rb
|
216
|
+
- lib/eac_ruby_utils/module_ancestors_variable/hash.rb
|
217
|
+
- lib/eac_ruby_utils/module_ancestors_variable/set.rb
|
211
218
|
- lib/eac_ruby_utils/options_consumer.rb
|
212
219
|
- lib/eac_ruby_utils/patch.rb
|
213
220
|
- lib/eac_ruby_utils/patches.rb
|
@@ -235,6 +242,7 @@ files:
|
|
235
242
|
- lib/eac_ruby_utils/patches/module.rb
|
236
243
|
- lib/eac_ruby_utils/patches/module/abstract_methods.rb
|
237
244
|
- lib/eac_ruby_utils/patches/module/acts_as_abstract.rb
|
245
|
+
- lib/eac_ruby_utils/patches/module/acts_as_immutable.rb
|
238
246
|
- lib/eac_ruby_utils/patches/module/common_concern.rb
|
239
247
|
- lib/eac_ruby_utils/patches/module/compare_by.rb
|
240
248
|
- lib/eac_ruby_utils/patches/module/context.rb
|
@@ -302,6 +310,7 @@ files:
|
|
302
310
|
- lib/eac_ruby_utils/static_method_class.rb
|
303
311
|
- lib/eac_ruby_utils/string_delimited.rb
|
304
312
|
- lib/eac_ruby_utils/struct.rb
|
313
|
+
- lib/eac_ruby_utils/unimplemented_method_error.rb
|
305
314
|
- lib/eac_ruby_utils/version.rb
|
306
315
|
- lib/eac_ruby_utils/yaml.rb
|
307
316
|
homepage:
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EacRubyUtils
|
4
|
-
module Immutable
|
5
|
-
class BaseAccessor
|
6
|
-
common_constructor :name do
|
7
|
-
self.name = name.to_sym
|
8
|
-
end
|
9
|
-
|
10
|
-
def duplicate_object(object)
|
11
|
-
accessor_new_value = yield(immutable_value_get(object))
|
12
|
-
new_values = object.send(:immutable_values_get).merge(name => accessor_new_value)
|
13
|
-
r = object.class.new(*object.immutable_constructor_args)
|
14
|
-
r.send(:immutable_values_set, new_values)
|
15
|
-
r
|
16
|
-
end
|
17
|
-
|
18
|
-
def immutable_value_get(object)
|
19
|
-
object.send(:immutable_values_get)[name]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|