avm-tools 0.84.0 → 0.87.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/git/file_auto_fixup.rb +22 -3
- data/lib/avm/instances/base/auto_values/database.rb +10 -0
- data/lib/avm/instances/base/auto_values/filesystem.rb +12 -0
- data/lib/avm/instances/entry_keys.rb +1 -1
- data/lib/avm/instances/runner.rb +2 -4
- data/lib/avm/projects/stereotypes/git/update.rb +42 -0
- data/lib/avm/projects/stereotypes/git/update/subrepo.rb +85 -0
- data/lib/avm/tools/runner.rb +2 -4
- data/lib/avm/tools/runner/eac_rails_base0.rb +1 -1
- data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +1 -1
- data/lib/avm/tools/runner/eac_redmine_base0.rb +1 -1
- data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +1 -1
- data/lib/avm/tools/runner/eac_redmine_base0/docker.rb +1 -1
- data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +1 -1
- data/lib/avm/tools/runner/eac_wordpress_base0.rb +1 -1
- data/lib/avm/tools/runner/eac_writings_base0.rb +1 -1
- data/lib/avm/tools/runner/eac_writings_base1.rb +1 -1
- data/lib/avm/tools/runner/files.rb +7 -15
- data/lib/avm/tools/runner/files/format.rb +18 -27
- data/lib/avm/tools/runner/files/rotate.rb +11 -21
- data/lib/avm/tools/runner/git.rb +10 -15
- data/lib/avm/tools/runner/git/auto_commit.rb +2 -2
- data/lib/avm/tools/runner/git/auto_fixup.rb +23 -16
- data/lib/avm/tools/runner/git/commit.rb +2 -2
- data/lib/avm/tools/runner/git/deploy.rb +18 -28
- data/lib/avm/tools/runner/git/dirty_files.rb +2 -2
- data/lib/avm/tools/runner/git/issue.rb +2 -2
- data/lib/avm/tools/runner/git/organize.rb +2 -2
- data/lib/avm/tools/runner/git/revisions_test.rb +2 -2
- data/lib/avm/tools/runner/git/subrepo.rb +2 -2
- data/lib/avm/tools/runner/git/subrepo/check.rb +2 -2
- data/lib/avm/tools/runner/git/subrepo/clone.rb +2 -2
- data/lib/avm/tools/runner/git/subrepo/fix.rb +4 -3
- data/lib/avm/tools/runner/instance.rb +1 -1
- data/lib/avm/tools/runner/instance/info.rb +1 -1
- data/lib/avm/tools/runner/launcher.rb +1 -1
- data/lib/avm/tools/runner/launcher/instances.rb +1 -1
- data/lib/avm/tools/runner/launcher/projects.rb +1 -1
- data/lib/avm/tools/runner/launcher/publish.rb +1 -1
- data/lib/avm/tools/runner/local_project.rb +5 -8
- data/lib/avm/tools/runner/local_project/eac_writings_base0.rb +5 -6
- data/lib/avm/tools/runner/local_project/eac_writings_base0/build_chapters.rb +4 -6
- data/lib/avm/tools/runner/local_project/eac_writings_base0/build_single.rb +4 -5
- data/lib/avm/tools/runner/local_project/eac_writings_base0/info.rb +4 -5
- data/lib/avm/tools/runner/local_project/eac_writings_base1.rb +2 -2
- data/lib/avm/tools/runner/local_project/eac_writings_base1/build.rb +2 -2
- data/lib/avm/tools/runner/local_project/info.rb +2 -2
- data/lib/avm/tools/runner/local_project/ruby.rb +2 -2
- data/lib/avm/tools/runner/local_project/ruby/bundler.rb +2 -2
- data/lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb +2 -2
- data/lib/avm/tools/runner/local_project/test.rb +2 -2
- data/lib/avm/tools/runner/local_project/update.rb +2 -2
- data/lib/avm/tools/runner/local_project/version_bump.rb +10 -13
- data/lib/avm/tools/runner/ruby.rb +1 -1
- data/lib/avm/tools/runner/ruby/gems.rb +1 -1
- data/lib/avm/tools/runner/ruby/gems/generate.rb +1 -1
- data/lib/avm/tools/runner/ruby/rubocop.rb +1 -1
- data/lib/avm/tools/runner/self.rb +1 -1
- data/lib/avm/tools/runner/self/docker.rb +1 -1
- data/lib/avm/tools/version.rb +1 -1
- data/template/avm/eac_rails_base0/deploy/config/database.yml.template +3 -2
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_context_replacement.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +4 -4
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/long_options.rb +37 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/option_argument.rb +29 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +7 -36
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +45 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +0 -48
- data/vendor/eac_cli/lib/eac_cli/runner/after_class_methods.rb +29 -0
- data/vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb +31 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +15 -3
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +22 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +1 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +9 -6
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb +4 -9
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +16 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +2 -99
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb +29 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb +54 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +10 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb +0 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +4 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +38 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/template.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +1 -8
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +8 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +14 -4
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +30 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +2 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/local_time_zone_spec.rb +17 -0
- metadata +18 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +0 -25
@@ -4,49 +4,20 @@ module EacCli
|
|
4
4
|
class Parser
|
5
5
|
class Alternative
|
6
6
|
module Options
|
7
|
-
DOUBLE_DASH = '--'
|
8
|
-
|
9
7
|
private
|
10
8
|
|
11
|
-
attr_accessor :argument_option, :double_dash
|
12
|
-
|
13
|
-
def argument_option_collect_argv(option)
|
14
|
-
self.argument_option = option
|
15
|
-
self.phase = PHASE_OPTION_ARGUMENT
|
16
|
-
end
|
17
|
-
|
18
|
-
def argv_current_option?
|
19
|
-
phase == PHASE_ANY && argv_enum.peek.start_with?('-')
|
20
|
-
end
|
21
|
-
|
22
|
-
def argv_current_double_dash?
|
23
|
-
argv_enum.peek == DOUBLE_DASH && !double_dash
|
24
|
-
end
|
25
|
-
|
26
9
|
def boolean_option_collect_argv(option)
|
27
10
|
collector.collect(option, true)
|
28
11
|
end
|
29
12
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def option_collect_argv_value
|
37
|
-
return double_dash_collect_argv_value if argv_current_double_dash?
|
38
|
-
|
39
|
-
alternative.options.any? do |option|
|
40
|
-
next false unless [option.short, option.long].include?(argv_enum.peek)
|
41
|
-
|
42
|
-
if option.argument?
|
43
|
-
argument_option_collect_argv(option)
|
44
|
-
else
|
45
|
-
boolean_option_collect_argv(option)
|
46
|
-
end
|
13
|
+
def option_collect_option(option)
|
14
|
+
if option.argument?
|
15
|
+
argument_option_collect_argv(option)
|
16
|
+
else
|
17
|
+
boolean_option_collect_argv(option)
|
18
|
+
end
|
47
19
|
|
48
|
-
|
49
|
-
end || raise_argv_current_invalid_option
|
20
|
+
option
|
50
21
|
end
|
51
22
|
|
52
23
|
def raise_argv_current_invalid_option
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module ShortOptions
|
7
|
+
SHORT_OPTION_PREFIX = '-'
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def argv_current_short_option?
|
12
|
+
phase == PHASE_ANY && argv_enum.peek.start_with?(SHORT_OPTION_PREFIX) &&
|
13
|
+
!argv_current_long_option?
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_short_option(char)
|
17
|
+
alternative.options.find { |option| short_without_prefix(option.short) == char }
|
18
|
+
end
|
19
|
+
|
20
|
+
def short_option_collect_argv_value
|
21
|
+
last_option = nil
|
22
|
+
short_without_prefix(argv_enum.peek).each_char do |char|
|
23
|
+
raise_error "Option \"#{last_option}\" requires a argument not provided" if
|
24
|
+
last_option.present?
|
25
|
+
|
26
|
+
collected_option = short_option_collect_char(char)
|
27
|
+
last_option = collected_option if collected_option.argument?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [EacCli::Definition::BaseOption] The option collected.
|
32
|
+
def short_option_collect_char(char)
|
33
|
+
option = find_short_option(char)
|
34
|
+
raise_error "Invalid short option \"#{char}\"" unless option
|
35
|
+
|
36
|
+
option_collect_option(option)
|
37
|
+
end
|
38
|
+
|
39
|
+
def short_without_prefix(short)
|
40
|
+
short.gsub(/\A#{::Regexp.quote(SHORT_OPTION_PREFIX)}/, '')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -47,53 +47,5 @@ module EacCli
|
|
47
47
|
include ActiveSupport::Callbacks
|
48
48
|
define_callbacks :run
|
49
49
|
end
|
50
|
-
|
51
|
-
module AfterClassMethods
|
52
|
-
def create(*runner_context_args)
|
53
|
-
r = new
|
54
|
-
r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
|
55
|
-
r
|
56
|
-
end
|
57
|
-
|
58
|
-
def run(*runner_context_args)
|
59
|
-
r = create(*runner_context_args)
|
60
|
-
r.run_run
|
61
|
-
r
|
62
|
-
end
|
63
|
-
|
64
|
-
def runner_definition(&block)
|
65
|
-
@runner_definition ||= super_runner_definition
|
66
|
-
@runner_definition.instance_eval(&block) if block
|
67
|
-
@runner_definition
|
68
|
-
end
|
69
|
-
|
70
|
-
def super_runner_definition
|
71
|
-
superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
module InstanceMethods
|
76
|
-
def run_run
|
77
|
-
parsed
|
78
|
-
run_callbacks(:run) { run }
|
79
|
-
rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
|
80
|
-
# Do nothing
|
81
|
-
end
|
82
|
-
|
83
|
-
def runner_context
|
84
|
-
return @runner_context if @runner_context
|
85
|
-
|
86
|
-
raise 'Context was required, but was not set yet'
|
87
|
-
end
|
88
|
-
|
89
|
-
def runner_context=(new_runner_context)
|
90
|
-
@runner_context = new_runner_context
|
91
|
-
@parsed = nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def parsed
|
95
|
-
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
96
|
-
end
|
97
|
-
end
|
98
50
|
end
|
99
51
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
module Runner
|
5
|
+
module AfterClassMethods
|
6
|
+
def create(*runner_context_args)
|
7
|
+
r = new
|
8
|
+
r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
|
9
|
+
r
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(*runner_context_args)
|
13
|
+
r = create(*runner_context_args)
|
14
|
+
r.run_run
|
15
|
+
r
|
16
|
+
end
|
17
|
+
|
18
|
+
def runner_definition(&block)
|
19
|
+
@runner_definition ||= super_runner_definition
|
20
|
+
@runner_definition.instance_eval(&block) if block
|
21
|
+
@runner_definition
|
22
|
+
end
|
23
|
+
|
24
|
+
def super_runner_definition
|
25
|
+
superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
module Runner
|
5
|
+
module InstanceMethods
|
6
|
+
def run_run
|
7
|
+
parsed
|
8
|
+
run_callbacks(:run) { run }
|
9
|
+
rescue ::EacCli::Parser::Error => e
|
10
|
+
$stderr.write("#{e}\n")
|
11
|
+
rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
|
12
|
+
# Do nothing
|
13
|
+
end
|
14
|
+
|
15
|
+
def runner_context
|
16
|
+
return @runner_context if @runner_context
|
17
|
+
|
18
|
+
raise 'Context was required, but was not set yet'
|
19
|
+
end
|
20
|
+
|
21
|
+
def runner_context=(new_runner_context)
|
22
|
+
@runner_context = new_runner_context
|
23
|
+
@parsed = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def parsed
|
27
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -6,6 +6,14 @@ require 'eac_ruby_utils/core_ext'
|
|
6
6
|
module EacCli
|
7
7
|
module RunnerWith
|
8
8
|
module Subcommands
|
9
|
+
class << self
|
10
|
+
def runner?(object)
|
11
|
+
::EacCli::Runner.runner?(object) || (
|
12
|
+
object.is_a?(::Class) && object < ::EacRubyUtils::Console::DocoptRunner
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
9
17
|
common_concern do
|
10
18
|
include ::EacCli::Runner
|
11
19
|
end
|
@@ -19,7 +27,7 @@ module EacCli
|
|
19
27
|
def available_subcommands_auto
|
20
28
|
self.class.constants
|
21
29
|
.map { |name| [name.to_s.underscore.gsub('_', '-'), self.class.const_get(name)] }
|
22
|
-
.select { |c| ::EacCli::
|
30
|
+
.select { |c| ::EacCli::RunnerWith::Subcommands.runner?(c[1]) }
|
23
31
|
.to_h.with_indifferent_access
|
24
32
|
end
|
25
33
|
|
@@ -32,7 +40,7 @@ module EacCli
|
|
32
40
|
end
|
33
41
|
|
34
42
|
def help_extra_text
|
35
|
-
(['Subcommands:'] + available_subcommands.keys.map { |s| " #{s}" })
|
43
|
+
(['Subcommands:'] + available_subcommands.keys.sort.map { |s| " #{s}" })
|
36
44
|
.map { |v| "#{v}\n" }.join
|
37
45
|
end
|
38
46
|
|
@@ -49,7 +57,11 @@ module EacCli
|
|
49
57
|
|
50
58
|
def run_with_subcommand
|
51
59
|
if subcommand_name
|
52
|
-
subcommand_runner.run_run
|
60
|
+
if subcommand_runner.respond_to?(:run_run)
|
61
|
+
subcommand_runner.run_run
|
62
|
+
else
|
63
|
+
subcommand_runner.run
|
64
|
+
end
|
53
65
|
else
|
54
66
|
run_without_subcommand
|
55
67
|
end
|
@@ -11,7 +11,7 @@ RSpec.describe ::EacCli::Runner do
|
|
11
11
|
|
12
12
|
runner_definition do
|
13
13
|
arg_opt '-o', '--opt1', 'A arg option.'
|
14
|
-
bool_opt '-
|
14
|
+
bool_opt '-p', '--opt2', 'A boolean option'
|
15
15
|
pos_arg :pos1
|
16
16
|
pos_arg :pos2, repeat: true, optional: true
|
17
17
|
alt do
|
@@ -40,6 +40,27 @@ RSpec.describe ::EacCli::Runner do
|
|
40
40
|
it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
|
41
41
|
end
|
42
42
|
|
43
|
+
context 'with long option and argument in same position' do
|
44
|
+
let(:argv) { %w[--opt1=aaa pos1] }
|
45
|
+
|
46
|
+
it { expect(instance.parsed.opt1).to eq('aaa') }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with valid grouped short options' do
|
50
|
+
let(:argv) { %w[-po aaa pos1] }
|
51
|
+
|
52
|
+
it { expect(instance.parsed.opt1).to eq('aaa') }
|
53
|
+
it { expect(instance.parsed.opt2?).to eq(true) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with invalid grouped short options' do
|
57
|
+
let(:argv) { %w[-op aaa pos1] }
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
43
64
|
context 'when only required args are supplied' do
|
44
65
|
let(:argv) { %w[bbb] }
|
45
66
|
let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
|
@@ -1,13 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_cli/
|
3
|
+
require 'eac_cli/runner_with/help'
|
4
|
+
require 'eac_cli/runner_with/subcommands'
|
4
5
|
require 'eac_ruby_utils/core_ext'
|
5
6
|
|
6
7
|
module EacRubyBase0
|
7
8
|
module Runner
|
8
9
|
require_sub __FILE__
|
10
|
+
enable_console_speaker
|
9
11
|
common_concern do
|
10
|
-
include ::EacCli::
|
12
|
+
include ::EacCli::RunnerWith::Help
|
13
|
+
include ::EacCli::RunnerWith::Subcommands
|
11
14
|
runner_definition do
|
12
15
|
bool_opt '-q', '--quiet', 'Quiet mode.'
|
13
16
|
bool_opt '-I', '--no-input', 'Fail if a input is requested.'
|
@@ -20,9 +23,9 @@ module EacRubyBase0
|
|
20
23
|
|
21
24
|
def run
|
22
25
|
on_speaker_node do |node|
|
23
|
-
node.stderr = ::StringIO.new if
|
24
|
-
node.stdin = FailIfRequestInput.new if
|
25
|
-
if
|
26
|
+
node.stderr = ::StringIO.new if parsed.quiet?
|
27
|
+
node.stdin = FailIfRequestInput.new if parsed.no_input?
|
28
|
+
if parsed.version?
|
26
29
|
show_version
|
27
30
|
else
|
28
31
|
run_with_subcommand
|
@@ -31,7 +34,7 @@ module EacRubyBase0
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def application_version
|
34
|
-
|
37
|
+
runner_context.call(:application).version.to_s
|
35
38
|
end
|
36
39
|
|
37
40
|
def show_version
|
@@ -1,17 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_cli/
|
4
|
-
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
-
require 'eac_ruby_utils/core_ext'
|
3
|
+
require 'eac_cli/core_ext'
|
6
4
|
require 'eac_ruby_gems_utils/tests/multiple'
|
7
5
|
|
8
6
|
module EacRubyBase0
|
9
7
|
module Runner
|
10
|
-
class TestAll
|
11
|
-
|
12
|
-
include ::EacCli::DefaultRunner
|
13
|
-
|
14
|
-
runner_definition do
|
8
|
+
class TestAll
|
9
|
+
runner_with :help do
|
15
10
|
desc 'Test core and local gems.'
|
16
11
|
end
|
17
12
|
|
@@ -20,7 +15,7 @@ module EacRubyBase0
|
|
20
15
|
end
|
21
16
|
|
22
17
|
def tests_uncached
|
23
|
-
::EacRubyGemsUtils::Tests::Multiple.new(
|
18
|
+
::EacRubyGemsUtils::Tests::Multiple.new(runner_context.call(:application).all_gems)
|
24
19
|
end
|
25
20
|
end
|
26
21
|
end
|
@@ -17,15 +17,25 @@ module EacRubyUtils
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def run
|
20
|
-
setup = self
|
21
20
|
a_module.extend(::ActiveSupport::Concern)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
include_or_prepend(:included, :include)
|
22
|
+
include_or_prepend(:prepended, :prepend)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def include_or_prepend(module_method, class_setup_method)
|
28
|
+
setup = self
|
29
|
+
a_module.send(module_method, *a_module_method_args(module_method)) do
|
30
|
+
::EacRubyUtils::CommonConcern::ClassSetup.new(setup, self, class_setup_method).run
|
27
31
|
end
|
28
32
|
end
|
33
|
+
|
34
|
+
def a_module_method_args(module_method)
|
35
|
+
method_arity = a_module.method(module_method).arity
|
36
|
+
method_arity = -method_arity - 1 if method_arity.negative?
|
37
|
+
method_arity.times.map { |_n| a_module }
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_support/callbacks'
|
4
4
|
require 'eac_ruby_utils/arguments_consumer'
|
5
|
+
require 'eac_ruby_utils/common_constructor/class_initialize'
|
5
6
|
require 'ostruct'
|
6
7
|
|
7
8
|
module EacRubyUtils
|
@@ -76,111 +77,13 @@ module EacRubyUtils
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def setup_class_initialize(klass)
|
79
|
-
common_constructor = self
|
80
80
|
klass.include(::ActiveSupport::Callbacks)
|
81
81
|
klass.define_callbacks :initialize
|
82
|
-
|
83
|
-
Initialize.new(common_constructor, args, self).run
|
84
|
-
super(*SuperArgs.new(common_constructor, args, self).result)
|
85
|
-
end
|
82
|
+
::EacRubyUtils::CommonConstructor::ClassInitialize.new(self, klass).run
|
86
83
|
end
|
87
84
|
|
88
85
|
def super_args
|
89
86
|
options[:super_args]
|
90
87
|
end
|
91
|
-
|
92
|
-
class Initialize
|
93
|
-
attr_reader :common_constructor, :args, :object
|
94
|
-
|
95
|
-
def initialize(common_constructor, args, object)
|
96
|
-
@common_constructor = common_constructor
|
97
|
-
@args = args
|
98
|
-
@object = object
|
99
|
-
end
|
100
|
-
|
101
|
-
def run
|
102
|
-
validate_args_count
|
103
|
-
object.run_callbacks :initialize do
|
104
|
-
object_attributes_set
|
105
|
-
object_after_callback
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def arg_value(arg_name)
|
112
|
-
arg_index = common_constructor.args.index(arg_name)
|
113
|
-
if arg_index < args.count
|
114
|
-
args[arg_index]
|
115
|
-
else
|
116
|
-
common_constructor.default_values[arg_index - common_constructor.args_count_min]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def object_after_callback
|
121
|
-
return unless common_constructor.after_set_block
|
122
|
-
|
123
|
-
object.instance_eval(&common_constructor.after_set_block)
|
124
|
-
end
|
125
|
-
|
126
|
-
def object_attributes_set
|
127
|
-
common_constructor.args.each do |arg_name|
|
128
|
-
object.send("#{arg_name}=", arg_value(arg_name))
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def validate_args_count
|
133
|
-
return if common_constructor.args_count.include?(args.count)
|
134
|
-
|
135
|
-
raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
|
136
|
-
" (given #{args.count}, expected #{common_constructor.args_count})"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
class SuperArgs
|
141
|
-
attr_reader :common_constructor, :args, :object
|
142
|
-
|
143
|
-
def initialize(common_constructor, args, object)
|
144
|
-
@common_constructor = common_constructor
|
145
|
-
@args = args
|
146
|
-
@object = object
|
147
|
-
end
|
148
|
-
|
149
|
-
def auto_result
|
150
|
-
r = []
|
151
|
-
sub_args.each do |name, value|
|
152
|
-
i = super_arg_index(name)
|
153
|
-
r[i] = value if i
|
154
|
-
end
|
155
|
-
r
|
156
|
-
end
|
157
|
-
|
158
|
-
def result
|
159
|
-
result_from_options || auto_result
|
160
|
-
end
|
161
|
-
|
162
|
-
def result_from_options
|
163
|
-
return unless common_constructor.super_args
|
164
|
-
|
165
|
-
object.instance_exec(&common_constructor.super_args)
|
166
|
-
end
|
167
|
-
|
168
|
-
def sub_args
|
169
|
-
common_constructor.args.each_with_index.map do |name, index|
|
170
|
-
[name, args[index]]
|
171
|
-
end.to_h
|
172
|
-
end
|
173
|
-
|
174
|
-
def super_arg_index(name)
|
175
|
-
super_method.parameters.each_with_index do |arg, index|
|
176
|
-
return index if arg[1] == name
|
177
|
-
end
|
178
|
-
nil
|
179
|
-
end
|
180
|
-
|
181
|
-
def super_method
|
182
|
-
object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil
|
183
|
-
end
|
184
|
-
end
|
185
88
|
end
|
186
89
|
end
|