avm-tools 0.76.1 → 0.81.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/eac_rails_base1/runner/code_runner.rb +1 -2
- data/lib/avm/eac_rails_base1/runner/rails_server.rb +33 -0
- data/lib/avm/patches/class/i18n.rb +31 -0
- data/lib/avm/patches/object/i18n.rb +2 -10
- data/lib/avm/projects/stereotypes/ruby_gem/update.rb +4 -1
- data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +1 -2
- data/lib/avm/tools/runner/git/subrepo/clone.rb +84 -0
- data/lib/avm/tools/runner/git/subrepo/fix.rb +65 -0
- data/lib/avm/tools/version.rb +1 -1
- data/template/avm/eac_redmine_base0/deploy/config/install.sh.template +12 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition.rb +34 -39
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +16 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +0 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +32 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
- metadata +28 -7
- data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +0 -36
- data/lib/avm/tools/runner/eac_rails_base0/runner.rb +0 -14
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -68
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/configs/read_entry_options'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module Console
|
8
|
+
class Configs
|
9
|
+
class EntryReader
|
10
|
+
enable_console_speaker
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def entry_key_to_envvar_name(entry_key)
|
14
|
+
path = if entry_key.is_a?(::Array)
|
15
|
+
entry_key
|
16
|
+
else
|
17
|
+
::EacRubyUtils::PathsHash.parse_entry_key(entry_key)
|
18
|
+
end
|
19
|
+
path.join('_').gsub(/[^a-z0-9_]/i, '').gsub(/\A_+/, '').gsub(/_+\z/, '')
|
20
|
+
.gsub(/_{2,}/, '_').upcase
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
common_constructor :console_configs, :entry_key, :options do
|
25
|
+
self.options = ::EacRubyUtils::Console::Configs::ReadEntryOptions.new(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def read
|
29
|
+
%w[envvars storage console].each do |suffix|
|
30
|
+
value = send("read_from_#{suffix}")
|
31
|
+
return value if value.present?
|
32
|
+
end
|
33
|
+
return nil unless options[:required]
|
34
|
+
|
35
|
+
raise "No value found for entry \"#{entry_key}\""
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_from_storage
|
39
|
+
console_configs.configs.read_entry(entry_key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_from_envvars
|
43
|
+
return if options[:noenv]
|
44
|
+
|
45
|
+
env_entry_key = self.class.entry_key_to_envvar_name(entry_key)
|
46
|
+
return unless ENV.key?(env_entry_key)
|
47
|
+
|
48
|
+
ENV.fetch(env_entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_from_console
|
52
|
+
return if options[:noinput]
|
53
|
+
|
54
|
+
options[:before_input].if_present(&:call)
|
55
|
+
entry_value = looped_entry_value_from_input
|
56
|
+
console_configs.configs.write_entry(entry_key, entry_value) if options[:store]
|
57
|
+
entry_value
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def looped_entry_value_from_input
|
63
|
+
loop do
|
64
|
+
entry_value = entry_value_from_input(entry_key, options)
|
65
|
+
next if entry_value.blank?
|
66
|
+
next if options[:validator] && !options[:validator].call(entry_value)
|
67
|
+
|
68
|
+
return entry_value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def entry_value_from_input(entry_key, options)
|
73
|
+
entry_value = request_input("Value for entry \"#{entry_key}\"",
|
74
|
+
options.request_input_options)
|
75
|
+
warn('Entered value is blank') if entry_value.blank?
|
76
|
+
entry_value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/configs/entry_reader'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Console
|
7
|
+
class Configs
|
8
|
+
class PasswordEntryReader < ::EacRubyUtils::Console::Configs::EntryReader
|
9
|
+
ENTRY_KEY = 'core.store_passwords'
|
10
|
+
|
11
|
+
def initialize(console_configs, entry_key, options = {})
|
12
|
+
super(console_configs, entry_key, options.merge(noecho: true,
|
13
|
+
store: console_configs.store_passwords?))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -7,13 +7,18 @@ module EacRubyUtils
|
|
7
7
|
class Configs
|
8
8
|
class ReadEntryOptions
|
9
9
|
enable_simple_cache
|
10
|
-
common_constructor :options
|
10
|
+
common_constructor :options do
|
11
|
+
self.options = options.to_h.symbolize_keys
|
12
|
+
.assert_valid_keys(DEFAULT_VALUES.keys).freeze
|
13
|
+
end
|
11
14
|
|
12
15
|
DEFAULT_VALUES = {
|
13
16
|
before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
|
14
|
-
required: true, validator: nil
|
17
|
+
required: true, store: true, validator: nil
|
15
18
|
}.freeze
|
16
19
|
|
20
|
+
delegate :to_h, to: :options
|
21
|
+
|
17
22
|
def [](key)
|
18
23
|
values.fetch(key.to_sym)
|
19
24
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/configs/entry_reader'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Console
|
7
|
+
class Configs
|
8
|
+
class StorePasswordsEntryReader < ::EacRubyUtils::Console::Configs::EntryReader
|
9
|
+
ENTRY_KEY = 'core.store_passwords'
|
10
|
+
|
11
|
+
def initialize(console_configs)
|
12
|
+
super(console_configs, ENTRY_KEY,
|
13
|
+
before_input: -> { banner },
|
14
|
+
validator: ->(entry_value) { %w[yes no].include?(entry_value) }
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def banner
|
19
|
+
infom 'Do you wanna to store passwords?'
|
20
|
+
infom 'Warning: the passwords will be store in clear text in ' \
|
21
|
+
"\"#{console_configs.configs.storage_path}\""
|
22
|
+
infom 'Enter "yes" or "no"'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'eac_ruby_utils/console/speaker'
|
5
|
-
require 'eac_ruby_utils/envs/command/extra_options'
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
6
4
|
require 'eac_ruby_utils/envs/process'
|
7
5
|
require 'eac_ruby_utils/envs/spawn'
|
8
6
|
require 'pp'
|
@@ -11,8 +9,8 @@ require 'shellwords'
|
|
11
9
|
module EacRubyUtils
|
12
10
|
module Envs
|
13
11
|
class Command
|
14
|
-
|
15
|
-
|
12
|
+
require_sub __FILE__, include_modules: true
|
13
|
+
enable_console_speaker
|
16
14
|
|
17
15
|
def initialize(env, command, extra_options = {})
|
18
16
|
@env = env
|
@@ -47,7 +45,7 @@ module EacRubyUtils
|
|
47
45
|
c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
|
48
46
|
append_command_options(
|
49
47
|
@env.command_line(
|
50
|
-
append_chdir(
|
48
|
+
append_chdir(append_concat(append_envvars(c)))
|
51
49
|
),
|
52
50
|
options
|
53
51
|
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/struct'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
module Envs
|
7
|
+
class Command
|
8
|
+
module Concat
|
9
|
+
def concat(operator, other_command)
|
10
|
+
duplicate_by_extra_options(concat: ::EacRubyUtils::Struct.new(
|
11
|
+
operator: operator, command: other_command
|
12
|
+
))
|
13
|
+
end
|
14
|
+
|
15
|
+
def or(other_command)
|
16
|
+
concat('||', other_command)
|
17
|
+
end
|
18
|
+
|
19
|
+
def pipe(other_command)
|
20
|
+
concat('|', other_command)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def append_concat(command)
|
26
|
+
extra_options[:concat].if_present(command) do |v|
|
27
|
+
"#{command} #{v.operator} #{v.command.command}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
module Envs
|
5
|
+
class Command
|
6
|
+
module Envvars
|
7
|
+
def envvar(name, value)
|
8
|
+
duplicate_by_extra_options(envvars: envvars.merge(name => value))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def append_envvars(command)
|
14
|
+
e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
|
15
|
+
e.present? ? "#{e} #{command}" : command
|
16
|
+
end
|
17
|
+
|
18
|
+
def envvars
|
19
|
+
extra_options[:envvars] ||= {}.with_indifferent_access
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -12,39 +12,18 @@ module EacRubyUtils
|
|
12
12
|
duplicate_by_extra_options(chdir: dir)
|
13
13
|
end
|
14
14
|
|
15
|
-
def envvar(name, value)
|
16
|
-
duplicate_by_extra_options(envvars: envvars.merge(name => value))
|
17
|
-
end
|
18
|
-
|
19
15
|
def status_result(status_code, result)
|
20
16
|
duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
|
21
17
|
end
|
22
18
|
|
23
|
-
def pipe(other_command)
|
24
|
-
duplicate_by_extra_options(pipe: other_command)
|
25
|
-
end
|
26
|
-
|
27
19
|
private
|
28
20
|
|
29
21
|
attr_reader :extra_options
|
30
22
|
|
31
|
-
def envvars
|
32
|
-
extra_options[:envvars] ||= {}.with_indifferent_access
|
33
|
-
end
|
34
|
-
|
35
23
|
def status_results
|
36
24
|
extra_options[:status_results] ||= {}.with_indifferent_access
|
37
25
|
end
|
38
26
|
|
39
|
-
def append_envvars(command)
|
40
|
-
e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
|
41
|
-
e.present? ? "#{e} #{command}" : command
|
42
|
-
end
|
43
|
-
|
44
|
-
def append_pipe(command)
|
45
|
-
extra_options[:pipe].present? ? "#{command} | #{extra_options[:pipe].command}" : command
|
46
|
-
end
|
47
|
-
|
48
27
|
def append_chdir(command)
|
49
28
|
extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
|
50
29
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/module/delegation'
|
4
5
|
require 'active_support/core_ext/object/blank'
|
5
6
|
|
6
7
|
module EacRubyUtils
|
7
8
|
class Struct
|
8
9
|
def initialize(initial_data = {})
|
9
|
-
self.data =
|
10
|
+
self.data = initial_data.symbolize_keys
|
10
11
|
end
|
11
12
|
|
12
13
|
def [](key)
|
@@ -19,6 +20,11 @@ module EacRubyUtils
|
|
19
20
|
bool ? fetch(key).present? : data.fetch(key)
|
20
21
|
end
|
21
22
|
|
23
|
+
def merge(other)
|
24
|
+
other = self.class.new(other) unless other.is_a?(self.class)
|
25
|
+
self.class.new(to_h.merge(other.to_h))
|
26
|
+
end
|
27
|
+
|
22
28
|
def method_missing(method_name, *arguments, &block)
|
23
29
|
property_method?(method_name) ? fetch(method_name) : super
|
24
30
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'date'
|
3
4
|
require 'yaml'
|
4
5
|
|
5
6
|
module EacRubyUtils
|
6
7
|
# A safe YAML loader/dumper with common types included.
|
7
8
|
class Yaml
|
8
9
|
class << self
|
9
|
-
DEFAULT_PERMITTED_CLASSES = [::Array, ::Date, ::FalseClass, ::Hash, ::NilClass,
|
10
|
-
::String, ::Symbol, ::Time, ::TrueClass].freeze
|
10
|
+
DEFAULT_PERMITTED_CLASSES = [::Array, ::Date, ::DateTime, ::FalseClass, ::Hash, ::NilClass,
|
11
|
+
::Numeric, ::String, ::Symbol, ::Time, ::TrueClass].freeze
|
11
12
|
|
12
13
|
def dump(object)
|
13
14
|
::YAML.dump(sanitize(object))
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/abstract_methods'
|
4
|
+
|
5
|
+
RSpec.describe(::EacRubyUtils::AbstractMethods) do
|
6
|
+
let(:base_class) do
|
7
|
+
the_module = described_class
|
8
|
+
::Class.new do
|
9
|
+
include the_module
|
10
|
+
|
11
|
+
abstract_methods :method1, :method2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
let(:base_instance) { base_class.new }
|
15
|
+
let(:sub_class) do
|
16
|
+
::Class.new(base_class) do
|
17
|
+
def method1
|
18
|
+
'a result'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
let(:sub_instance) { sub_class.new }
|
23
|
+
|
24
|
+
it { expect { base_instance.method1 }.to raise_error(::NoMethodError) }
|
25
|
+
it { expect { base_instance.method2 }.to raise_error(::NoMethodError) }
|
26
|
+
it { expect(sub_instance.method1).to eq('a result') }
|
27
|
+
it { expect { sub_instance.method2 }.to raise_error(::NoMethodError) }
|
28
|
+
end
|
@@ -9,34 +9,47 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
let(:stub_module) do
|
13
|
+
::Module.new do
|
14
|
+
module ClassMethods # rubocop:disable RSpec/LeakyConstantDeclaration
|
15
|
+
def my_class_method
|
16
|
+
'class'
|
17
|
+
end
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
module InstanceMethods # rubocop:disable RSpec/LeakyConstantDeclaration
|
21
|
+
def my_instance_method
|
22
|
+
'instance'
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
let(:stub_class) do
|
29
|
+
::Class.new do
|
30
|
+
class << self
|
31
|
+
attr_accessor :valor
|
32
|
+
end
|
33
|
+
|
34
|
+
def method1
|
35
|
+
'from_stub_module'
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
32
|
-
let(:
|
40
|
+
let(:stub_class_instance) { stub_class.new }
|
33
41
|
|
34
42
|
before do
|
35
|
-
instance.setup(
|
36
|
-
MyClass.include MyModule
|
43
|
+
instance.setup(stub_module)
|
37
44
|
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
context 'when included' do
|
47
|
+
before do
|
48
|
+
stub_class.include stub_module
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(stub_class_instance.my_instance_method).to eq('instance') }
|
52
|
+
it { expect(stub_class_instance.class.my_class_method).to eq('class') }
|
53
|
+
it { expect(stub_class_instance.class.valor).to eq('changed') }
|
54
|
+
end
|
42
55
|
end
|
@@ -3,34 +3,92 @@
|
|
3
3
|
require 'eac_ruby_utils/common_constructor'
|
4
4
|
|
5
5
|
RSpec.describe ::EacRubyUtils::CommonConstructor do
|
6
|
-
ARG_LIST = %i[a b c d].freeze
|
6
|
+
ARG_LIST = %i[a b c d].freeze # rubocop:disable RSpec/LeakyConstantDeclaration
|
7
|
+
|
7
8
|
let(:instance) do
|
8
9
|
described_class.new(*ARG_LIST, default: %w[Vcc Vd]) do
|
9
10
|
@z = 'Vz'
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
let(:a_class) do
|
15
|
+
::Class.new do
|
16
|
+
attr_reader :z
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
|
-
let(:
|
20
|
+
let(:a_class_instance) { a_class.new('Va', 'Vb', 'Vc') }
|
18
21
|
|
19
22
|
before do
|
20
|
-
instance.setup_class(
|
23
|
+
instance.setup_class(a_class)
|
21
24
|
end
|
22
25
|
|
23
|
-
it { expect(
|
26
|
+
it { expect(a_class_instance.z).to eq('Vz') }
|
24
27
|
|
25
28
|
ARG_LIST.each do |attr|
|
26
29
|
expected_value = "V#{attr}"
|
27
30
|
it "attribute \"#{attr}\" equal to \"#{expected_value}\"" do
|
28
|
-
expect(
|
31
|
+
expect(a_class_instance.send(attr)).to eq(expected_value)
|
29
32
|
end
|
30
33
|
|
31
34
|
[false, true].each do |include_all|
|
32
35
|
it "respond_to?('#{attr}', #{include_all}) == #{include_all}" do
|
33
|
-
expect(
|
36
|
+
expect(a_class_instance.respond_to?("#{attr}=", include_all)).to eq(include_all)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with super class' do
|
42
|
+
let(:super_class) do
|
43
|
+
::Class.new do
|
44
|
+
attr_reader :super_a, :super_b
|
45
|
+
|
46
|
+
def initialize(a, b) # rubocop:disable Naming/MethodParameterName
|
47
|
+
@super_a = a
|
48
|
+
@super_b = b
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:sub_class) do
|
54
|
+
sub_constructor.setup_class(::Class.new(super_class))
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:sub_object) { sub_class.new(1, 2, 3, 4) }
|
58
|
+
|
59
|
+
context 'with super_args parameter' do
|
60
|
+
let(:sub_constructor) do
|
61
|
+
described_class.new(:c, :a, :b, :d, super_args: -> { [c, a] })
|
62
|
+
end
|
63
|
+
|
64
|
+
it { expect(sub_object.a).to eq(2) }
|
65
|
+
it { expect(sub_object.b).to eq(3) }
|
66
|
+
it { expect(sub_object.c).to eq(1) }
|
67
|
+
it { expect(sub_object.d).to eq(4) }
|
68
|
+
it { expect(sub_object.super_a).to eq(1) }
|
69
|
+
it { expect(sub_object.super_b).to eq(2) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'without super_args parameter' do
|
73
|
+
let(:sub_constructor) do
|
74
|
+
described_class.new(:c, :a, :b, :d)
|
75
|
+
end
|
76
|
+
|
77
|
+
it { expect(sub_object.a).to eq(2) }
|
78
|
+
it { expect(sub_object.b).to eq(3) }
|
79
|
+
it { expect(sub_object.c).to eq(1) }
|
80
|
+
it { expect(sub_object.d).to eq(4) }
|
81
|
+
it { expect(sub_object.super_a).to eq(2) }
|
82
|
+
it { expect(sub_object.super_b).to eq(3) }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with undefined super arguments' do
|
86
|
+
let(:sub_constructor) do
|
87
|
+
described_class.new(:x, :y, :w, :a)
|
88
|
+
end
|
89
|
+
|
90
|
+
it do
|
91
|
+
expect { sub_object }.to raise_error(::ArgumentError)
|
34
92
|
end
|
35
93
|
end
|
36
94
|
end
|