eac_tools 0.65.1 → 0.67.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +32 -32
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +3 -3
- data/sub/avm/lib/avm/data/clearer.rb +20 -0
- data/sub/avm/lib/avm/data/package/base_performer.rb +38 -0
- data/sub/avm/lib/avm/data/package/clear.rb +22 -0
- data/sub/avm/lib/avm/data/package/dump.rb +0 -10
- data/sub/avm/lib/avm/data/package.rb +8 -1
- data/sub/avm/lib/avm/data/performer.rb +49 -0
- data/sub/avm/lib/avm/docker/runner.rb +0 -4
- data/sub/avm/lib/avm/instances/base/auto_values/data.rb +1 -2
- data/sub/avm/lib/avm/instances/base.rb +10 -0
- data/sub/avm/lib/avm/instances/runner.rb +1 -1
- data/sub/avm/lib/avm/sources/runner.rb +2 -0
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +3 -3
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base.rb +2 -0
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +1 -1
- data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +4 -4
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/provider.rb +2 -2
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/base.rb +0 -10
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
- data/sub/avm-tools/avm-tools.gemspec +4 -4
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/clear.rb +18 -0
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/dump.rb +1 -5
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/clear.rb +1 -5
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/dump.rb +2 -2
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/load.rb +1 -1
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit.rb +3 -1
- data/sub/avm-tools/lib/avm/tools/runner/instance/data.rb +7 -0
- data/sub/avm-tools/lib/avm/tools/runner/launcher.rb +0 -1
- data/sub/avm-tools/lib/avm/tools/runner/launcher_stereotypes/list.rb +0 -1
- data/sub/avm-tools/lib/avm/tools/runner_with/include_exclude.rb +23 -0
- data/sub/avm-tools/lib/avm/tools/runner_with/instance_data_clear.rb +30 -0
- data/sub/avm-tools/lib/avm/tools/runner_with.rb +11 -0
- data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
- data/sub/eac_cli/eac_cli.gemspec +1 -1
- data/sub/eac_cli/lib/eac_cli/definition/alternative.rb +11 -7
- data/sub/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb +2 -1
- data/sub/eac_cli/lib/eac_cli/definition/base_option.rb +1 -1
- data/sub/eac_cli/lib/eac_cli/definition/boolean_option.rb +2 -1
- data/sub/eac_cli/lib/eac_cli/definition/error.rb +8 -0
- data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +6 -1
- data/sub/eac_cli/lib/eac_cli/runner/context.rb +29 -7
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/base.rb +24 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/parent.rb +27 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner.rb +20 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner_missing_method.rb +32 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb +44 -0
- data/sub/eac_cli/lib/eac_cli/runner/context_responders.rb +11 -0
- data/sub/eac_cli/lib/eac_cli/runner/for_context.rb +40 -0
- data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +5 -3
- data/sub/eac_cli/lib/eac_cli/runner.rb +1 -0
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_cli/spec/lib/eac_cli/runner/for_context_spec.rb +79 -0
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +11 -1
- data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb +52 -0
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/prepend.rb +17 -4
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -39
- data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_abstract.rb +17 -6
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/array_accessor.rb +25 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb +57 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/boolean_accessor.rb +3 -3
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/class_methods.rb +2 -2
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/common_accessor.rb +5 -5
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable/array_accessor.rb → acts_as_immutable/enumerable_accessor.rb} +11 -8
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor.rb +5 -5
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/instance_methods.rb +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/set_accessor.rb +25 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable.rb → acts_as_immutable.rb} +1 -1
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/enumerables_methods.rb +42 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/base.rb +34 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/hash.rb +20 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/set.rb +19 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable.rb +9 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/acts_as_immutable.rb +10 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +3 -2
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +9 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/unimplemented_method_error.rb +6 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_abstract_spec.rb +73 -7
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/array_accessor_spec.rb +11 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/common_accessor_spec.rb +57 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor_spec.rb +3 -3
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/set_accessor_spec.rb +43 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/enumerables_methods_spec.rb +50 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/hash_spec.rb +57 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/set_spec.rb +57 -0
- metadata +56 -20
- data/sub/avm-tools/lib/avm/projects/stereotypes.rb +0 -15
- data/sub/avm-tools/lib/avm/projects.rb +0 -9
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +0 -23
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/node'
|
4
|
+
require 'eac_fs/contexts'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'eac_ruby_utils/speaker'
|
7
|
+
|
8
|
+
module EacRubyBase0
|
9
|
+
module Runner
|
10
|
+
module Contexts
|
11
|
+
def on_context(&block)
|
12
|
+
top_block = block
|
13
|
+
available_contexts.each do |context|
|
14
|
+
next if context.object.any?
|
15
|
+
|
16
|
+
last_block = top_block
|
17
|
+
top_block = ::Proc.new { context.object.on(context.builder.call, &last_block) }
|
18
|
+
end
|
19
|
+
top_block.call
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @return [Array<EacRubyUtils::Struct>]
|
25
|
+
def available_contexts
|
26
|
+
(filesystem_available_contexts + [
|
27
|
+
[:config, ::EacConfig::Node.context,
|
28
|
+
-> { runner_context.call(:application).build_config }],
|
29
|
+
[:speaker, ::EacRubyUtils::Speaker.context, -> { build_speaker }]
|
30
|
+
]).map { |row| available_context_row_to_struct(row) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def available_context_row_to_struct(row)
|
34
|
+
%i[type object builder].zip(row).to_h.to_struct
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_speaker
|
38
|
+
options = {}
|
39
|
+
options[:err_out] = ::StringIO.new if parsed.quiet?
|
40
|
+
options[:in_in] = ::EacCli::Speaker::InputBlocked.new if parsed.no_input?
|
41
|
+
::EacCli::Speaker.new(options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def filesystem_available_contexts
|
45
|
+
::EacFs::Contexts::TYPES.map do |type|
|
46
|
+
key = "fs_#{type}".to_sym
|
47
|
+
[key, ::EacFs::Contexts.send(type), -> { application.send("self_#{key}") }]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -10,17 +10,30 @@ require 'eac_ruby_utils/speaker'
|
|
10
10
|
module EacRubyBase0
|
11
11
|
module Runner
|
12
12
|
module Prepend
|
13
|
+
SYSTEM_STACK_ERROR_FILE = 'system_stack_error'
|
14
|
+
|
13
15
|
def run
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
on_rescue_stack_overflow do
|
17
|
+
if parsed.version?
|
18
|
+
show_version
|
19
|
+
else
|
20
|
+
run_with_subcommand
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
def run_run
|
22
26
|
on_context { super }
|
23
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def on_rescue_stack_overflow
|
32
|
+
yield
|
33
|
+
rescue ::SystemStackError => e
|
34
|
+
SYSTEM_STACK_ERROR_FILE.to_pathname.write(e.backtrace.map { |v| "#{v}\n" }.join)
|
35
|
+
raise e
|
36
|
+
end
|
24
37
|
end
|
25
38
|
end
|
26
39
|
end
|
@@ -14,6 +14,7 @@ module EacRubyBase0
|
|
14
14
|
common_concern do
|
15
15
|
include ::EacCli::RunnerWith::Help
|
16
16
|
include ::EacCli::RunnerWith::Subcommands
|
17
|
+
include ::EacRubyBase0::Runner::Contexts
|
17
18
|
prepend ::EacRubyBase0::Runner::Prepend
|
18
19
|
runner_definition do
|
19
20
|
bool_opt '-q', '--quiet', 'Quiet mode.'
|
@@ -29,47 +30,8 @@ module EacRubyBase0
|
|
29
30
|
runner_context.call(:application).version.to_s
|
30
31
|
end
|
31
32
|
|
32
|
-
def on_context(&block)
|
33
|
-
top_block = block
|
34
|
-
available_contexts.each do |context|
|
35
|
-
next if context.object.any?
|
36
|
-
|
37
|
-
last_block = top_block
|
38
|
-
top_block = ::Proc.new { context.object.on(context.builder.call, &last_block) }
|
39
|
-
end
|
40
|
-
top_block.call
|
41
|
-
end
|
42
|
-
|
43
33
|
def show_version
|
44
34
|
out("#{application_version}\n")
|
45
35
|
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# @return [Array<EacRubyUtils::Struct>]
|
50
|
-
def available_contexts
|
51
|
-
(filesystem_available_contexts + [
|
52
|
-
[:config, ::EacConfig::Node.context, -> { runner_context.call(:application).build_config }],
|
53
|
-
[:speaker, ::EacRubyUtils::Speaker.context, -> { build_speaker }]
|
54
|
-
]).map { |row| available_context_row_to_struct(row) }
|
55
|
-
end
|
56
|
-
|
57
|
-
def available_context_row_to_struct(row)
|
58
|
-
%i[type object builder].zip(row).to_h.to_struct
|
59
|
-
end
|
60
|
-
|
61
|
-
def build_speaker
|
62
|
-
options = {}
|
63
|
-
options[:err_out] = ::StringIO.new if parsed.quiet?
|
64
|
-
options[:in_in] = ::EacCli::Speaker::InputBlocked.new if parsed.no_input?
|
65
|
-
::EacCli::Speaker.new(options)
|
66
|
-
end
|
67
|
-
|
68
|
-
def filesystem_available_contexts
|
69
|
-
::EacFs::Contexts::TYPES.map do |type|
|
70
|
-
key = "fs_#{type}".to_sym
|
71
|
-
[key, ::EacFs::Contexts.send(type), -> { application.send("self_#{key}") }]
|
72
|
-
end
|
73
|
-
end
|
74
36
|
end
|
75
37
|
end
|
@@ -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
|
data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/boolean_accessor.rb
RENAMED
@@ -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
|
|
data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/common_accessor.rb
RENAMED
@@ -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
|
@@ -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
|
@@ -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
|
|