eac_tools 0.66.0 → 0.67.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +32 -32
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +2 -2
  5. data/sub/avm/lib/avm/data/clearer.rb +8 -6
  6. data/sub/avm/lib/avm/data/package/base_performer.rb +38 -0
  7. data/sub/avm/lib/avm/data/package/clear.rb +3 -4
  8. data/sub/avm/lib/avm/data/performer.rb +49 -0
  9. data/sub/avm/lib/avm/instances/base/subcommand_parent.rb +5 -5
  10. data/sub/avm/lib/avm/instances/runner.rb +1 -1
  11. data/sub/avm/lib/avm/scms/auto_commit/for_file.rb +12 -2
  12. data/sub/avm/lib/avm/sources/runner.rb +2 -0
  13. data/sub/avm/lib/avm/version.rb +1 -1
  14. data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +3 -3
  15. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/runners/base.rb +2 -0
  16. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +1 -1
  17. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +3 -3
  18. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/file_formats/provider.rb +2 -2
  19. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  20. data/sub/avm-git/avm-git.gemspec +2 -2
  21. data/sub/avm-git/lib/avm/git/scms/git/commit_dirty.rb +35 -0
  22. data/sub/avm-git/lib/avm/git/scms/git/commits.rb +0 -14
  23. data/sub/avm-git/lib/avm/git/scms/git/run_commit.rb +1 -1
  24. data/sub/avm-git/lib/avm/git/scms/git_sub_base/changed_file.rb +21 -0
  25. data/sub/avm-git/lib/avm/git/scms/git_sub_base/commit.rb +1 -3
  26. data/sub/avm-git/lib/avm/git/scms/git_sub_base.rb +8 -1
  27. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  28. data/sub/avm-tools/avm-tools.gemspec +2 -2
  29. data/sub/avm-tools/lib/avm/tools/runner/instance/data/clear.rb +1 -1
  30. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/dump.rb +2 -2
  31. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/load.rb +1 -1
  32. data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit.rb +2 -5
  33. data/sub/avm-tools/lib/avm/tools/runner/instance/data.rb +2 -0
  34. data/sub/avm-tools/lib/avm/tools/runner_with/include_exclude.rb +23 -0
  35. data/sub/avm-tools/lib/avm/tools/runner_with/instance_data_clear.rb +11 -1
  36. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  37. data/sub/eac_cli/eac_cli.gemspec +1 -1
  38. data/sub/eac_cli/lib/eac_cli/definition/alternative.rb +11 -7
  39. data/sub/eac_cli/lib/eac_cli/definition/base_option/initialize_args_parser.rb +2 -1
  40. data/sub/eac_cli/lib/eac_cli/definition/base_option.rb +1 -1
  41. data/sub/eac_cli/lib/eac_cli/definition/boolean_option.rb +2 -1
  42. data/sub/eac_cli/lib/eac_cli/definition/error.rb +8 -0
  43. data/sub/eac_cli/lib/eac_cli/runner/after_class_methods.rb +6 -1
  44. data/sub/eac_cli/lib/eac_cli/runner/context.rb +22 -3
  45. data/sub/eac_cli/lib/eac_cli/runner/context_responders/base.rb +24 -0
  46. data/sub/eac_cli/lib/eac_cli/runner/context_responders/parent.rb +27 -0
  47. data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner.rb +20 -0
  48. data/sub/eac_cli/lib/eac_cli/runner/context_responders/runner_missing_method.rb +32 -0
  49. data/sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb +44 -0
  50. data/sub/eac_cli/lib/eac_cli/runner/context_responders.rb +11 -0
  51. data/sub/eac_cli/lib/eac_cli/runner/for_context.rb +40 -0
  52. data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +5 -3
  53. data/sub/eac_cli/lib/eac_cli/runner.rb +1 -0
  54. data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
  55. data/sub/eac_cli/spec/lib/eac_cli/runner/for_context_spec.rb +79 -0
  56. data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +1 -0
  57. data/sub/eac_ruby_base0/eac_ruby_base0.gemspec +3 -3
  58. data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb +52 -0
  59. data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner/prepend.rb +17 -4
  60. data/sub/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -39
  61. data/sub/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  62. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_abstract.rb +17 -6
  63. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/array_accessor.rb +25 -0
  64. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb +57 -0
  65. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/boolean_accessor.rb +3 -3
  66. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/class_methods.rb +2 -2
  67. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/common_accessor.rb +5 -5
  68. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable/array_accessor.rb → acts_as_immutable/enumerable_accessor.rb} +11 -8
  69. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor.rb +5 -5
  70. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable → acts_as_immutable}/instance_methods.rb +1 -1
  71. data/sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/set_accessor.rb +25 -0
  72. data/sub/eac_ruby_utils/lib/eac_ruby_utils/{immutable.rb → acts_as_immutable.rb} +1 -1
  73. data/sub/eac_ruby_utils/lib/eac_ruby_utils/enumerables_methods.rb +42 -0
  74. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/base.rb +34 -0
  75. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/hash.rb +20 -0
  76. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable/set.rb +19 -0
  77. data/sub/eac_ruby_utils/lib/eac_ruby_utils/module_ancestors_variable.rb +9 -0
  78. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/acts_as_immutable.rb +10 -0
  79. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +3 -2
  80. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +9 -0
  81. data/sub/eac_ruby_utils/lib/eac_ruby_utils/unimplemented_method_error.rb +6 -0
  82. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  83. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_abstract_spec.rb +73 -7
  84. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/array_accessor_spec.rb +11 -3
  85. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/common_accessor_spec.rb +57 -0
  86. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{immutable → acts_as_immutable}/hash_accessor_spec.rb +3 -3
  87. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/acts_as_immutable/set_accessor_spec.rb +43 -0
  88. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/enumerables_methods_spec.rb +50 -0
  89. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/hash_spec.rb +57 -0
  90. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/module_ancestors_variable/set_spec.rb +57 -0
  91. metadata +57 -22
  92. data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +0 -23
@@ -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
- if parsed.version?
15
- show_version
16
- else
17
- run_with_subcommand
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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.18.0'
4
+ VERSION = '0.19.0'
5
5
  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
- define_method name.to_sym do |*_the_args|
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.abstract_methods.include?(method_name.to_sym)
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 ::NoMethodError, "Abstract method #{method_name}(#{arguments.join(', ')}) hit in " \
85
- "#{self}\" (Class: #{self.class})"
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/immutable/common_accessor'
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 Immutable
8
- class BooleanAccessor < ::EacRubyUtils::Immutable::CommonAccessor
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 Immutable
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::Immutable.const_get(class_name).new(name).apply(self)
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/immutable/base_accessor'
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 Immutable
8
- class CommonAccessor < ::EacRubyUtils::Immutable::BaseAccessor
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.immutable_value_get(self)
14
- when 1 then next accessor.immutable_value_set(self, args.first)
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/immutable/base_accessor'
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 Immutable
9
- class ArrayAccessor < ::EacRubyUtils::Immutable::BaseAccessor
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.immutable_value_get(self)
20
- when 1 then next accessor.immutable_value_set(self, args.first)
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 || []) + [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/immutable/base_accessor'
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 Immutable
8
- class HashAccessor < ::EacRubyUtils::Immutable::BaseAccessor
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.immutable_value_get(self)
37
- when 1 then next accessor.immutable_value_set(self, args[0])
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- module Immutable
4
+ module ActsAsImmutable
5
5
  module InstanceMethods
6
6
  def immutable_constructor_args
7
7
  []
@@ -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
@@ -4,7 +4,7 @@ require 'eac_ruby_utils/patches/module/common_concern'
4
4
  require 'eac_ruby_utils/require_sub'
5
5
 
6
6
  module EacRubyUtils
7
- module Immutable
7
+ module ActsAsImmutable
8
8
  ::EacRubyUtils.require_sub __FILE__
9
9
 
10
10
  common_concern do
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/module/require_sub'
4
+
5
+ module EacRubyUtils
6
+ class ModuleAncestorsHash
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patch'
4
+ require 'eac_ruby_utils/acts_as_immutable'
5
+
6
+ class Module
7
+ def acts_as_immutable
8
+ ::EacRubyUtils.patch(self, ::EacRubyUtils::ActsAsImmutable)
9
+ end
10
+ 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/immutable'
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::Immutable)
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
 
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class UnimplementedMethodError < ::StandardError
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.116.0'
4
+ VERSION = '0.117.0'
5
5
  end