avm-tools 0.81.0 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/avm/data/unit.rb +8 -3
- data/lib/avm/eac_rails_base0/apache_host.rb +2 -9
- data/lib/avm/eac_rails_base1/apache_host.rb +17 -0
- data/lib/avm/eac_redmine_base0/apache_host.rb +10 -0
- data/lib/avm/eac_redmine_base0/data_unit.rb +29 -1
- data/lib/avm/eac_writings_base1.rb +9 -0
- data/lib/avm/eac_writings_base1/apache_host.rb +17 -0
- data/lib/avm/eac_writings_base1/build.rb +45 -0
- data/lib/avm/eac_writings_base1/build/file.rb +28 -0
- data/lib/avm/eac_writings_base1/deploy.rb +26 -0
- data/lib/avm/eac_writings_base1/instance.rb +11 -0
- data/lib/avm/eac_writings_base1/project.rb +13 -0
- data/lib/avm/executables.rb +1 -1
- data/lib/avm/instances/base/auto_values/database.rb +10 -0
- data/lib/avm/instances/entry_keys.rb +1 -1
- data/lib/avm/tools/runner/eac_writings_base1.rb +15 -0
- data/lib/avm/tools/runner/local_project/eac_writings_base1.rb +32 -0
- data/lib/avm/tools/runner/local_project/eac_writings_base1/build.rb +48 -0
- 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/runner_with/help.rb +3 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -0
- 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/patches/pathname/basename_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- 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
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe892c043aa5fed89006bb8f334e2bdb5994c1c2db3ee6a76ad362a82c8f644
|
4
|
+
data.tar.gz: 2acb25eb3be3deac7ebfdb28626d0caf71bfff9efb6d4c17bb18001c6d346bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeffe8cb49bb3c5c5368b921c02f0ab3e135c1036f7e81512fbfee6fe4d6b72f5fd2448ae550b97b2df654dadc2e90f0a937f89397208e7c3ee92b3569524777
|
7
|
+
data.tar.gz: 7691b14f456391f2e1f3d015c6f90c88859f27abe5faf5460537471c5bc2eed4d9876c4a7794398ba319ab9a2558cfa8edf175c983217c0362a7692f42e6fbd7
|
data/lib/avm/data/unit.rb
CHANGED
@@ -12,11 +12,12 @@ module Avm
|
|
12
12
|
enable_console_speaker
|
13
13
|
|
14
14
|
%w[dump load].each do |action|
|
15
|
+
method_name = "#{action}_command"
|
15
16
|
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
16
17
|
# Should be overrided.
|
17
18
|
# @return [EacRubyUtils::Envs::Command]
|
18
|
-
def #{
|
19
|
-
fail "
|
19
|
+
def #{method_name}
|
20
|
+
fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
|
20
21
|
end
|
21
22
|
CODE
|
22
23
|
|
@@ -69,7 +70,7 @@ module Avm
|
|
69
70
|
def load(data_path)
|
70
71
|
run_callbacks :load do
|
71
72
|
infom "Loading unit \"#{name}\" from \"#{data_path}\"..."
|
72
|
-
|
73
|
+
do_load(data_path)
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -79,6 +80,10 @@ module Avm
|
|
79
80
|
dump_command.execute!(output_file: data_path)
|
80
81
|
end
|
81
82
|
|
83
|
+
def do_load(data_path)
|
84
|
+
load_command.execute!(input_file: data_path)
|
85
|
+
end
|
86
|
+
|
82
87
|
private
|
83
88
|
|
84
89
|
def unit_on_directory_path(directory, identifier)
|
@@ -1,17 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'avm/
|
3
|
+
require 'avm/eac_rails_base1/apache_host'
|
4
4
|
|
5
5
|
module Avm
|
6
6
|
module EacRailsBase0
|
7
|
-
class ApacheHost < ::Avm::
|
8
|
-
def document_root
|
9
|
-
"#{instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)}/public"
|
10
|
-
end
|
11
|
-
|
12
|
-
def extra_content
|
13
|
-
'PassengerEnabled On'
|
14
|
-
end
|
7
|
+
class ApacheHost < ::Avm::EacRailsBase1::ApacheHost
|
15
8
|
end
|
16
9
|
end
|
17
10
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/eac_webapp_base0/apache_host'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module EacRailsBase1
|
7
|
+
class ApacheHost < ::Avm::EacWebappBase0::ApacheHost
|
8
|
+
def document_root
|
9
|
+
"#{instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)}/public"
|
10
|
+
end
|
11
|
+
|
12
|
+
def extra_content
|
13
|
+
'PassengerEnabled On'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'avm/data/instance/unit'
|
4
4
|
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'curb'
|
5
6
|
require 'open-uri'
|
6
7
|
|
7
8
|
module Avm
|
@@ -17,8 +18,35 @@ module Avm
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def do_load(data_path)
|
22
|
+
do_load_by_web(data_path) || do_load_by_rake(data_path) || raise('Failed to load')
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_load_by_web(data_path)
|
26
|
+
c = Curl::Easy.new(import_url)
|
27
|
+
c.multipart_form_post = true
|
28
|
+
c.http_post(Curl::PostField.file('redmine_with_git_tableless_load[path]', data_path))
|
29
|
+
c.perform
|
30
|
+
true
|
31
|
+
rescue Curl::Err::ConnectionFailedError
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def do_load_by_rake(data_path)
|
36
|
+
instance.bundle('exec', 'rake', "redmine_with_git:load:all[#{data_path}]").system
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
20
40
|
def export_url
|
21
|
-
|
41
|
+
url('/backup/export')
|
42
|
+
end
|
43
|
+
|
44
|
+
def import_url
|
45
|
+
url('/backup/import.json')
|
46
|
+
end
|
47
|
+
|
48
|
+
def url(path)
|
49
|
+
uri = ::Addressable::URI.parse(instance.read_entry('web.url')) + path
|
22
50
|
uri.query_values = { key: instance.read_entry('admin.api_key') }
|
23
51
|
uri.to_s
|
24
52
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/eac_webapp_base0/apache_host'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module EacWritingsBase1
|
7
|
+
class ApacheHost < ::Avm::EacWebappBase0::ApacheHost
|
8
|
+
def document_root
|
9
|
+
instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)
|
10
|
+
end
|
11
|
+
|
12
|
+
def extra_content
|
13
|
+
''
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/fs/clearable_directory'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module EacWritingsBase1
|
8
|
+
class Build
|
9
|
+
require_sub __FILE__
|
10
|
+
enable_console_speaker
|
11
|
+
enable_simple_cache
|
12
|
+
enable_listable
|
13
|
+
lists.add_symbol :option, :target_directory
|
14
|
+
common_constructor :project, :options, default: [{}] do
|
15
|
+
self.options = self.class.lists.option.hash_keys_validate!(options.symbolize_keys)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
infov 'Files to build', source_files.count
|
20
|
+
target_directory.clear
|
21
|
+
source_files.each(&:run)
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_target_directory
|
25
|
+
project.root.join('build')
|
26
|
+
end
|
27
|
+
|
28
|
+
def target_directory
|
29
|
+
::EacRubyUtils::Fs::ClearableDirectory.new(
|
30
|
+
options[OPTION_TARGET_DIRECTORY] || default_target_directory
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def source_files_uncached
|
35
|
+
r = []
|
36
|
+
project.root.children.each do |child|
|
37
|
+
next unless child.extname == '.asc'
|
38
|
+
|
39
|
+
r << ::Avm::EacWritingsBase1::Build::File.new(self, child.basename)
|
40
|
+
end
|
41
|
+
r
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/executables'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module EacWritingsBase1
|
7
|
+
class Build
|
8
|
+
class File
|
9
|
+
enable_console_speaker
|
10
|
+
common_constructor :build, :subpath
|
11
|
+
|
12
|
+
def run
|
13
|
+
infov 'Building', subpath
|
14
|
+
target_path.parent.mkpath
|
15
|
+
::Avm::Executables.asciidoc.command('--out-file', target_path, source_path).system!
|
16
|
+
end
|
17
|
+
|
18
|
+
def source_path
|
19
|
+
build.project.root.join(subpath)
|
20
|
+
end
|
21
|
+
|
22
|
+
def target_path
|
23
|
+
build.target_directory.join(subpath).basename_sub('.*') { |b| "#{b}.html" }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/eac_webapp_base0/deploy'
|
4
|
+
require 'avm/eac_writings_base1/project'
|
5
|
+
require 'avm/eac_writings_base1/build'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module EacWritingsBase1
|
9
|
+
class Deploy < ::Avm::EacWebappBase0::Deploy
|
10
|
+
def build_content
|
11
|
+
::Avm::EacWritingsBase1::Build.new(
|
12
|
+
project,
|
13
|
+
::Avm::EacWritingsBase1::Build::OPTION_TARGET_DIRECTORY => build_dir
|
14
|
+
).run
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def project_uncached
|
20
|
+
::Avm::EacWritingsBase1::Project.new(
|
21
|
+
instance.source_instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/avm/executables.rb
CHANGED
@@ -14,7 +14,7 @@ module Avm
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
%w[docker file git latex php-cs-fixer tidy yapf xdg-open].each do |program|
|
17
|
+
%w[asciidoc docker file git latex php-cs-fixer tidy yapf xdg-open].each do |program|
|
18
18
|
define_method(program.underscore + '_uncached') do
|
19
19
|
env.executable(program, '--version')
|
20
20
|
end
|
@@ -8,6 +8,7 @@ module Avm
|
|
8
8
|
module AutoValues
|
9
9
|
module Database
|
10
10
|
DEFAULT_HOSTNAME = '127.0.0.1'
|
11
|
+
DEFAULT_LIMIT = 5
|
11
12
|
DEFAULT_PORTS = {
|
12
13
|
'postgresql' => 5432,
|
13
14
|
'mysql' => 3306,
|
@@ -15,6 +16,7 @@ module Avm
|
|
15
16
|
'sqlserver' => 1433
|
16
17
|
}.freeze
|
17
18
|
DEFAULT_SYSTEM = 'postgresql'
|
19
|
+
DEFAULT_TIMEOUT = 5000
|
18
20
|
|
19
21
|
def auto_database_name
|
20
22
|
inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID,
|
@@ -25,6 +27,10 @@ module Avm
|
|
25
27
|
database_auto_common('hostname') || DEFAULT_HOSTNAME
|
26
28
|
end
|
27
29
|
|
30
|
+
def auto_database_limit
|
31
|
+
database_auto_common('limit') || DEFAULT_LIMIT
|
32
|
+
end
|
33
|
+
|
28
34
|
def auto_database_password
|
29
35
|
database_auto_common('password')
|
30
36
|
end
|
@@ -41,6 +47,10 @@ module Avm
|
|
41
47
|
database_auto_common('system') || DEFAULT_SYSTEM
|
42
48
|
end
|
43
49
|
|
50
|
+
def auto_database_timeout
|
51
|
+
database_auto_common('timeout') || DEFAULT_TIMEOUT
|
52
|
+
end
|
53
|
+
|
44
54
|
private
|
45
55
|
|
46
56
|
def database_auto_common(suffix)
|
@@ -41,7 +41,7 @@ module Avm
|
|
41
41
|
|
42
42
|
{
|
43
43
|
'' => %w[fs_path host_id source_instance_id],
|
44
|
-
database: %w[id hostname name password port system username],
|
44
|
+
database: %w[id hostname limit name password port system timeout username],
|
45
45
|
mailer: {
|
46
46
|
'' => %w[id from reply_to],
|
47
47
|
smtp: %w[address port domain username password authentication starttls_auto]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/eac_webapp_base0/runner'
|
4
|
+
require 'avm/eac_writings_base1'
|
5
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Tools
|
9
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class EacWritingsBase1 < ::Avm::EacWebappBase0::Runner
|
11
|
+
require_sub __FILE__
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Tools
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class LocalProject < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class EacWritingsBase1
|
11
|
+
require_sub __FILE__
|
12
|
+
|
13
|
+
runner_with :help, :subcommands do
|
14
|
+
desc 'EacWritingsBase0 utitilies for local projects.'
|
15
|
+
subcommands
|
16
|
+
end
|
17
|
+
|
18
|
+
def project_banner
|
19
|
+
infov 'Project', project.name
|
20
|
+
infov 'Path', project.root
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def project_uncached
|
26
|
+
::Avm::EacWritingsBase0::Project.new(runner_context.call(:instance_path))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/eac_writings_base1/build'
|
4
|
+
require 'avm/eac_writings_base1/project'
|
5
|
+
require 'eac_cli/core_ext'
|
6
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
7
|
+
|
8
|
+
module Avm
|
9
|
+
module Tools
|
10
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
class LocalProject < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
class EacWritingsBase1
|
13
|
+
class Build
|
14
|
+
runner_with :help do
|
15
|
+
desc 'Build the project'
|
16
|
+
arg_opt '-d', '--target-dir', 'Directory to build'
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
start_banner
|
21
|
+
build.run
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_uncached
|
27
|
+
::Avm::EacWritingsBase1::Build.new(runner_context.call(:project),
|
28
|
+
target_directory: parsed.target_dir)
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_target_directory
|
32
|
+
runner_context.call(:project).root.join('build')
|
33
|
+
end
|
34
|
+
|
35
|
+
def start_banner
|
36
|
+
runner_context.call(:project_banner)
|
37
|
+
infov 'Target directory', build.target_directory
|
38
|
+
end
|
39
|
+
#
|
40
|
+
# def target_directory_uncached
|
41
|
+
# .if_present(default_target_directory).to_pathname
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/avm/tools/version.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
default: &default
|
2
2
|
adapter: %%DATABASE.SYSTEM%%
|
3
|
-
pool:
|
4
|
-
timeout:
|
3
|
+
pool: %%DATABASE.LIMIT%%
|
4
|
+
timeout: %%DATABASE.TIMEOUT%%
|
5
5
|
encoding: unicode
|
6
6
|
username: %%DATABASE.USERNAME%%
|
7
7
|
password: %%DATABASE.PASSWORD%%
|
8
8
|
host: %%DATABASE.HOSTNAME%%
|
9
9
|
port: %%DATABASE.PORT%%
|
10
|
+
reconnect: true
|
10
11
|
|
11
12
|
development: &development
|
12
13
|
<<: *default
|
@@ -27,7 +27,9 @@ module EacCli
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def help_text
|
30
|
-
::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
30
|
+
r = ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
31
|
+
r += help_extra_text if respond_to?(:help_extra_text)
|
32
|
+
r
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -31,6 +31,11 @@ module EacCli
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def help_extra_text
|
35
|
+
(['Subcommands:'] + available_subcommands.keys.map { |s| " #{s}" })
|
36
|
+
.map { |v| "#{v}\n" }.join
|
37
|
+
end
|
38
|
+
|
34
39
|
def method_missing(method_name, *arguments, &block)
|
35
40
|
return run_with_subcommand(*arguments, &block) if
|
36
41
|
run_with_subcommand_alias_run?(method_name)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_cli/runner'
|
4
|
+
require 'eac_cli/runner_with/help'
|
4
5
|
require 'eac_cli/runner_with/subcommands'
|
5
6
|
|
6
7
|
RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
@@ -53,4 +54,32 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
|
53
54
|
expect { instance.run }.to raise_error(::EacCli::Parser::Error)
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
context 'with help' do
|
59
|
+
let(:instance) { parent_runner.create(%w[--help]) }
|
60
|
+
let(:expected_output) do
|
61
|
+
<<~OUTPUT
|
62
|
+
A stub root runner.
|
63
|
+
|
64
|
+
Usage:
|
65
|
+
__PROGRAM__ [options] __SUBCOMMANDS__ [<subcommand_args>...]
|
66
|
+
__PROGRAM__ --help
|
67
|
+
|
68
|
+
Options:
|
69
|
+
-r --root-var=<value> A root variable.
|
70
|
+
-h --help Show help.
|
71
|
+
|
72
|
+
Subcommands:
|
73
|
+
child-cmd
|
74
|
+
OUTPUT
|
75
|
+
end
|
76
|
+
|
77
|
+
before do
|
78
|
+
parent_runner.include(::EacCli::RunnerWith::Help)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'show help text' do
|
82
|
+
expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
|
83
|
+
end
|
84
|
+
end
|
56
85
|
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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/common_constructor/instance_initialize'
|
4
|
+
require 'eac_ruby_utils/common_constructor/super_args'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
class CommonConstructor
|
8
|
+
class ClassInitialize
|
9
|
+
attr_reader :common_constructor, :klass
|
10
|
+
|
11
|
+
def initialize(common_constructor, klass)
|
12
|
+
@common_constructor = common_constructor
|
13
|
+
@klass = klass
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
class_initialize = self
|
18
|
+
klass.send(:define_method, :initialize) do |*args|
|
19
|
+
::EacRubyUtils::CommonConstructor::InstanceInitialize.new(
|
20
|
+
class_initialize.common_constructor, args, self
|
21
|
+
).run
|
22
|
+
super(*::EacRubyUtils::CommonConstructor::SuperArgs.new(
|
23
|
+
class_initialize, args, self
|
24
|
+
).result)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class CommonConstructor
|
5
|
+
class InstanceInitialize
|
6
|
+
attr_reader :common_constructor, :args, :object
|
7
|
+
|
8
|
+
def initialize(common_constructor, args, object)
|
9
|
+
@common_constructor = common_constructor
|
10
|
+
@args = args
|
11
|
+
@object = object
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
validate_args_count
|
16
|
+
object.run_callbacks :initialize do
|
17
|
+
object_attributes_set
|
18
|
+
object_after_callback
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def arg_value(arg_name)
|
25
|
+
arg_index = common_constructor.args.index(arg_name)
|
26
|
+
if arg_index < args.count
|
27
|
+
args[arg_index]
|
28
|
+
else
|
29
|
+
common_constructor.default_values[arg_index - common_constructor.args_count_min]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def object_after_callback
|
34
|
+
return unless common_constructor.after_set_block
|
35
|
+
|
36
|
+
object.instance_eval(&common_constructor.after_set_block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def object_attributes_set
|
40
|
+
common_constructor.args.each do |arg_name|
|
41
|
+
object.send("#{arg_name}=", arg_value(arg_name))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_args_count
|
46
|
+
return if common_constructor.args_count.include?(args.count)
|
47
|
+
|
48
|
+
raise ArgumentError, "#{object.class}.initialize: wrong number of arguments" \
|
49
|
+
" (given #{args.count}, expected #{common_constructor.args_count})"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
class CommonConstructor
|
7
|
+
class SuperArgs
|
8
|
+
attr_reader :class_initialize, :args, :object
|
9
|
+
delegate :common_constructor, to: :class_initialize
|
10
|
+
|
11
|
+
def initialize(class_initialize, args, object)
|
12
|
+
@class_initialize = class_initialize
|
13
|
+
@args = args
|
14
|
+
@object = object
|
15
|
+
end
|
16
|
+
|
17
|
+
def auto_result
|
18
|
+
r = []
|
19
|
+
sub_args.each do |name, value|
|
20
|
+
i = super_arg_index(name)
|
21
|
+
r[i] = value if i
|
22
|
+
end
|
23
|
+
r
|
24
|
+
end
|
25
|
+
|
26
|
+
def result
|
27
|
+
result_from_options || auto_result
|
28
|
+
end
|
29
|
+
|
30
|
+
def result_from_options
|
31
|
+
return unless common_constructor.super_args
|
32
|
+
|
33
|
+
object.instance_exec(&common_constructor.super_args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def sub_args
|
37
|
+
common_constructor.args.each_with_index.map do |name, index|
|
38
|
+
[name, args[index]]
|
39
|
+
end.to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
def super_arg_index(name)
|
43
|
+
super_method.parameters.each_with_index do |arg, index|
|
44
|
+
return index if arg[1] == name
|
45
|
+
end
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def super_method
|
50
|
+
class_initialize.klass.superclass&.instance_method(:initialize)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -38,7 +38,7 @@ module EacRubyUtils
|
|
38
38
|
def run_with_subcommand
|
39
39
|
if subcommand_name
|
40
40
|
check_valid_subcommand
|
41
|
-
|
41
|
+
subcommand_run
|
42
42
|
else
|
43
43
|
run_without_subcommand
|
44
44
|
end
|
@@ -52,6 +52,15 @@ module EacRubyUtils
|
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
+
def subcommand_run
|
56
|
+
if !subcommand.is_a?(::EacRubyUtils::Console::DocoptRunner) &&
|
57
|
+
subcommand.respond_to?(:run_run)
|
58
|
+
subcommand.run_run
|
59
|
+
else
|
60
|
+
subcommand.run
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
55
64
|
def target_doc
|
56
65
|
super.gsub(SUBCOMMANDS_MACRO,
|
57
66
|
"#{target_doc_subcommand_arg} [#{SUBCOMMAND_ARGS_ARG}...]") +
|
@@ -19,7 +19,7 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
|
|
19
19
|
|
20
20
|
module InstanceMethods # rubocop:disable RSpec/LeakyConstantDeclaration
|
21
21
|
def my_instance_method
|
22
|
-
'
|
22
|
+
'from_module'
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -31,8 +31,8 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
|
|
31
31
|
attr_accessor :valor
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
'
|
34
|
+
def my_instance_method
|
35
|
+
'from_class'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -48,7 +48,17 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
|
|
48
48
|
stub_class.include stub_module
|
49
49
|
end
|
50
50
|
|
51
|
-
it { expect(stub_class_instance.my_instance_method).to eq('
|
51
|
+
it { expect(stub_class_instance.my_instance_method).to eq('from_class') }
|
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
|
55
|
+
|
56
|
+
context 'when prepended' do
|
57
|
+
before do
|
58
|
+
stub_class.prepend stub_module
|
59
|
+
end
|
60
|
+
|
61
|
+
it { expect(stub_class_instance.my_instance_method).to eq('from_module') }
|
52
62
|
it { expect(stub_class_instance.class.my_class_method).to eq('class') }
|
53
63
|
it { expect(stub_class_instance.class.valor).to eq('changed') }
|
54
64
|
end
|
@@ -92,4 +92,34 @@ RSpec.describe ::EacRubyUtils::CommonConstructor do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
context 'with class hierarchy mixed with and without common_constructor' do
|
97
|
+
let(:klass_0) do
|
98
|
+
described_class.new(:a_param).setup_class(::Class.new)
|
99
|
+
end
|
100
|
+
|
101
|
+
let(:klass_1) do
|
102
|
+
::Class.new(klass_0) do
|
103
|
+
def initialize(a_param)
|
104
|
+
super(a_param)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
let(:klass_2) do
|
110
|
+
::Class.new(klass_1)
|
111
|
+
end
|
112
|
+
|
113
|
+
let(:klass_3) do
|
114
|
+
described_class.new(:a_param).setup_class(::Class.new(klass_2))
|
115
|
+
end
|
116
|
+
|
117
|
+
4.times.each do |i|
|
118
|
+
context "wit #{i}-th class" do
|
119
|
+
let(:class_instance) { send("klass_#{i}").new(:a) }
|
120
|
+
|
121
|
+
it { expect(class_instance.a_param).to eq(:a) }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
95
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avm-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.85.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha-parsers
|
@@ -296,6 +296,7 @@ files:
|
|
296
296
|
- lib/avm/eac_rails_base0/deploy.rb
|
297
297
|
- lib/avm/eac_rails_base0/instance.rb
|
298
298
|
- lib/avm/eac_rails_base1.rb
|
299
|
+
- lib/avm/eac_rails_base1/apache_host.rb
|
299
300
|
- lib/avm/eac_rails_base1/instance.rb
|
300
301
|
- lib/avm/eac_rails_base1/runner.rb
|
301
302
|
- lib/avm/eac_rails_base1/runner/bundle.rb
|
@@ -303,6 +304,7 @@ files:
|
|
303
304
|
- lib/avm/eac_rails_base1/runner/rails_server.rb
|
304
305
|
- lib/avm/eac_rails_base1/runner_with/bundle.rb
|
305
306
|
- lib/avm/eac_redmine_base0.rb
|
307
|
+
- lib/avm/eac_redmine_base0/apache_host.rb
|
306
308
|
- lib/avm/eac_redmine_base0/core_update.rb
|
307
309
|
- lib/avm/eac_redmine_base0/data_unit.rb
|
308
310
|
- lib/avm/eac_redmine_base0/deploy.rb
|
@@ -344,6 +346,13 @@ files:
|
|
344
346
|
- lib/avm/eac_writings_base0/project_build.rb
|
345
347
|
- lib/avm/eac_writings_base0/project_build/chapters_content.rb
|
346
348
|
- lib/avm/eac_writings_base0/project_build/copy_files.rb
|
349
|
+
- lib/avm/eac_writings_base1.rb
|
350
|
+
- lib/avm/eac_writings_base1/apache_host.rb
|
351
|
+
- lib/avm/eac_writings_base1/build.rb
|
352
|
+
- lib/avm/eac_writings_base1/build/file.rb
|
353
|
+
- lib/avm/eac_writings_base1/deploy.rb
|
354
|
+
- lib/avm/eac_writings_base1/instance.rb
|
355
|
+
- lib/avm/eac_writings_base1/project.rb
|
347
356
|
- lib/avm/executables.rb
|
348
357
|
- lib/avm/files.rb
|
349
358
|
- lib/avm/files/appendable.rb
|
@@ -493,6 +502,7 @@ files:
|
|
493
502
|
- lib/avm/tools/runner/eac_redmine_base0/project_rename.rb
|
494
503
|
- lib/avm/tools/runner/eac_wordpress_base0.rb
|
495
504
|
- lib/avm/tools/runner/eac_writings_base0.rb
|
505
|
+
- lib/avm/tools/runner/eac_writings_base1.rb
|
496
506
|
- lib/avm/tools/runner/files.rb
|
497
507
|
- lib/avm/tools/runner/files/format.rb
|
498
508
|
- lib/avm/tools/runner/files/rotate.rb
|
@@ -520,6 +530,8 @@ files:
|
|
520
530
|
- lib/avm/tools/runner/local_project/eac_writings_base0/build_chapters.rb
|
521
531
|
- lib/avm/tools/runner/local_project/eac_writings_base0/build_single.rb
|
522
532
|
- lib/avm/tools/runner/local_project/eac_writings_base0/info.rb
|
533
|
+
- lib/avm/tools/runner/local_project/eac_writings_base1.rb
|
534
|
+
- lib/avm/tools/runner/local_project/eac_writings_base1/build.rb
|
523
535
|
- lib/avm/tools/runner/local_project/info.rb
|
524
536
|
- lib/avm/tools/runner/local_project/ruby.rb
|
525
537
|
- lib/avm/tools/runner/local_project/ruby/bundler.rb
|
@@ -908,6 +920,9 @@ files:
|
|
908
920
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb
|
909
921
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb
|
910
922
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb
|
923
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb
|
924
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb
|
925
|
+
- vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/super_args.rb
|
911
926
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb
|
912
927
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb
|
913
928
|
- vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb
|