eac_tools 0.66.0 → 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 +28 -28
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +2 -2
- data/sub/avm/lib/avm/data/clearer.rb +8 -6
- data/sub/avm/lib/avm/data/package/base_performer.rb +38 -0
- data/sub/avm/lib/avm/data/package/clear.rb +3 -4
- data/sub/avm/lib/avm/data/performer.rb +49 -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 +3 -3
- 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/version.rb +1 -1
- data/sub/avm-tools/avm-tools.gemspec +2 -2
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/clear.rb +1 -1
- 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 +2 -5
- data/sub/avm-tools/lib/avm/tools/runner/instance/data.rb +2 -0
- 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 +11 -1
- 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 +22 -3
- 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 +1 -0
- 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 +47 -20
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +0 -23
@@ -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
|
|
@@ -1,28 +1,94 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/acts_as_abstract'
|
4
|
+
require 'eac_ruby_utils/unimplemented_method_error'
|
4
5
|
|
5
|
-
RSpec.describe(::EacRubyUtils::ActsAsAbstract) do
|
6
|
+
::RSpec.describe(::EacRubyUtils::ActsAsAbstract) do
|
6
7
|
let(:base_class) do
|
7
8
|
the_module = described_class
|
8
9
|
::Class.new do
|
9
10
|
include the_module
|
10
11
|
|
11
12
|
abstract_methods :method1, :method2
|
13
|
+
|
14
|
+
def method3
|
15
|
+
'base result'
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
|
-
let(:base_instance) { base_class.new }
|
15
19
|
let(:sub_class) do
|
16
20
|
::Class.new(base_class) do
|
17
21
|
def method1
|
18
22
|
'a result'
|
19
23
|
end
|
24
|
+
|
25
|
+
def method4
|
26
|
+
'sub result'
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
|
-
let(:sub_instance) { sub_class.new }
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
class << self
|
32
|
+
def specs_for_target(test_target, instances_hash)
|
33
|
+
describe "\##{test_target}" do # rubocop:disable RSpec/EmptyExampleGroup
|
34
|
+
specs_for_instances(test_target, instances_hash)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def specs_for_instances(test_target, instances_hash)
|
39
|
+
instances_hash.each do |instance_name, expected_values|
|
40
|
+
context "when instance is \"#{instance_name}\"" do # rubocop:disable RSpec/EmptyExampleGroup
|
41
|
+
let(:instance) { send("#{instance_name}_class").new }
|
42
|
+
|
43
|
+
specs_for_methods_values(test_target, expected_values)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def specs_for_methods_values(test_target, expected_values)
|
49
|
+
expected_values.each_with_index do |expected_value, method_index|
|
50
|
+
method_name = "method#{method_index + 1}"
|
51
|
+
context "when method is \"#{method_name}\"" do # rubocop:disable RSpec/EmptyExampleGroup
|
52
|
+
send("specs_for_#{test_target}", method_name, expected_value)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def specs_for_abstract_method(method_name, expected_value)
|
58
|
+
it { expect(instance.abstract_method?(method_name)).to eq(expected_value) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def specs_for_method_missing(method_name, expected_value)
|
62
|
+
if expected_value.is_a?(::Class) && expected_value < ::Exception
|
63
|
+
it do
|
64
|
+
expect { instance.send(method_name) }.to raise_error(expected_value)
|
65
|
+
end
|
66
|
+
else
|
67
|
+
it do
|
68
|
+
expect(instance.send(method_name)).to eq(expected_value)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def specs_for_respond_to_missing(method_name, expected_value)
|
74
|
+
it { expect(instance.respond_to?(method_name)).to eq(expected_value) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
{
|
78
|
+
abstract_method: {
|
79
|
+
base: [true, true, false, false],
|
80
|
+
sub: [false, true, false, false]
|
81
|
+
},
|
82
|
+
method_missing: {
|
83
|
+
base: [::EacRubyUtils::UnimplementedMethodError, ::EacRubyUtils::UnimplementedMethodError,
|
84
|
+
'base result', ::NoMethodError],
|
85
|
+
sub: ['a result', ::EacRubyUtils::UnimplementedMethodError, 'base result', 'sub result']
|
86
|
+
},
|
87
|
+
respond_to_missing: {
|
88
|
+
base: [true, true, true, false],
|
89
|
+
sub: [true, true, true, true]
|
90
|
+
}
|
91
|
+
}.each do |test_target, instances_hash|
|
92
|
+
specs_for_target(test_target, instances_hash)
|
93
|
+
end
|
28
94
|
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'
|
4
4
|
|
5
|
-
::RSpec.describe ::EacRubyUtils::
|
5
|
+
::RSpec.describe ::EacRubyUtils::ActsAsImmutable::ArrayAccessor do
|
6
6
|
let(:stub_class) do
|
7
7
|
::Class.new do
|
8
|
-
include ::EacRubyUtils::
|
8
|
+
include ::EacRubyUtils::ActsAsImmutable
|
9
9
|
|
10
10
|
immutable_accessor :array_attr, type: :array
|
11
11
|
end
|
@@ -31,5 +31,13 @@ require 'eac_ruby_utils/immutable'
|
|
31
31
|
it { expect(change2_instance.object_id).not_to eq(change1_instance.object_id) }
|
32
32
|
it { expect(change2_instance.array_attrs).to eq(%w[B]) }
|
33
33
|
end
|
34
|
+
|
35
|
+
context 'when array_attrs sets for a non array' do
|
36
|
+
let(:change2_instance) { initial_instance.array_attrs('B') }
|
37
|
+
|
38
|
+
it { expect(change2_instance).to be_a(initial_instance.class) }
|
39
|
+
it { expect(change2_instance.object_id).not_to eq(change1_instance.object_id) }
|
40
|
+
it { expect(change2_instance.array_attrs).to eq(%w[B]) }
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/acts_as_immutable'
|
4
|
+
|
5
|
+
::RSpec.describe ::EacRubyUtils::ActsAsImmutable::CommonAccessor do
|
6
|
+
let(:stub_class) do
|
7
|
+
::Class.new do
|
8
|
+
include ::EacRubyUtils::ActsAsImmutable
|
9
|
+
|
10
|
+
immutable_accessor :attr1, :attr2, :attr3
|
11
|
+
|
12
|
+
def attr1_get_filter(value)
|
13
|
+
value || 'DEFAULT'
|
14
|
+
end
|
15
|
+
|
16
|
+
def attr2_set_filter(value)
|
17
|
+
"#{value}_FILTERED"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:initial_instance) { stub_class.new }
|
23
|
+
|
24
|
+
it { expect(initial_instance.attr1).to eq('DEFAULT') }
|
25
|
+
it { expect(initial_instance.attr2).to eq(nil) }
|
26
|
+
it { expect(initial_instance.attr3).to eq(nil) }
|
27
|
+
|
28
|
+
context 'when attr1 is set' do
|
29
|
+
let(:change1_instance) { initial_instance.attr1('A') }
|
30
|
+
|
31
|
+
it { expect(change1_instance).to be_a(initial_instance.class) }
|
32
|
+
it { expect(change1_instance.object_id).not_to eq(initial_instance.object_id) }
|
33
|
+
it { expect(change1_instance.attr1).to eq('A') }
|
34
|
+
it { expect(change1_instance.attr2).to eq(nil) }
|
35
|
+
it { expect(change1_instance.attr3).to eq(nil) }
|
36
|
+
|
37
|
+
context 'when attr2 is set' do
|
38
|
+
let(:change2_instance) { change1_instance.attr2('B') }
|
39
|
+
|
40
|
+
it { expect(change2_instance).to be_a(change1_instance.class) }
|
41
|
+
it { expect(change2_instance.object_id).not_to eq(change1_instance.object_id) }
|
42
|
+
it { expect(change2_instance.attr1).to eq('A') }
|
43
|
+
it { expect(change2_instance.attr2).to eq('B_FILTERED') }
|
44
|
+
it { expect(change2_instance.attr3).to eq(nil) }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when attr3 is set' do
|
48
|
+
let(:change2_instance) { change1_instance.attr3('C') }
|
49
|
+
|
50
|
+
it { expect(change2_instance).to be_a(change1_instance.class) }
|
51
|
+
it { expect(change2_instance.object_id).not_to eq(change1_instance.object_id) }
|
52
|
+
it { expect(change2_instance.attr1).to eq('A') }
|
53
|
+
it { expect(change2_instance.attr2).to eq(nil) }
|
54
|
+
it { expect(change2_instance.attr3).to eq('C') }
|
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'
|
4
4
|
|
5
|
-
::RSpec.describe ::EacRubyUtils::
|
5
|
+
::RSpec.describe ::EacRubyUtils::ActsAsImmutable::HashAccessor do
|
6
6
|
let(:stub_class) do
|
7
7
|
::Class.new do
|
8
|
-
include ::EacRubyUtils::
|
8
|
+
include ::EacRubyUtils::ActsAsImmutable
|
9
9
|
|
10
10
|
immutable_accessor :the_hash, type: :hash
|
11
11
|
end
|