avm 0.3.2 → 0.6.1
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/instance/files_unit.rb +40 -0
- data/lib/avm/data/instance/package.rb +18 -0
- data/lib/avm/data/instance/unit.rb +17 -0
- data/lib/avm/{git/issue.rb → data/instance.rb} +2 -2
- data/lib/avm/data/package/dump.rb +119 -0
- data/lib/avm/data/package/load.rb +48 -0
- data/lib/avm/data/package.rb +42 -0
- data/lib/avm/data/unit.rb +94 -0
- data/lib/avm/jobs/base.rb +63 -0
- data/lib/avm/jobs/variables_source.rb +22 -0
- data/lib/avm/{git/organize.rb → jobs.rb} +2 -4
- data/lib/avm/path_string.rb +27 -0
- data/lib/avm/registry/base.rb +65 -0
- data/lib/avm/registry.rb +29 -0
- data/lib/avm/rspec/setup.rb +22 -0
- data/lib/avm/rspec/shared_examples/in_avm_registry.rb +11 -0
- data/lib/avm/rspec/shared_examples/not_in_avm_registry.rb +14 -0
- data/lib/avm/rspec.rb +9 -0
- data/lib/avm/scms/base.rb +28 -0
- data/lib/avm/scms/commit.rb +43 -0
- data/lib/avm/source_stereotypes/base.rb +21 -0
- data/lib/avm/sources/base.rb +67 -0
- data/lib/avm/sources/configuration/_locale.rb +16 -0
- data/lib/avm/sources/configuration/_rubocop.rb +24 -0
- data/lib/avm/sources/configuration/_tests.rb +27 -0
- data/lib/avm/sources/configuration.rb +55 -0
- data/lib/avm/sources.rb +9 -0
- data/lib/avm/sync.rb +94 -0
- data/lib/avm/version.rb +1 -1
- metadata +80 -68
- data/lib/avm/files/appendable/file_content.rb +0 -24
- data/lib/avm/files/appendable/plain_directory.rb +0 -25
- data/lib/avm/files/appendable/resource_base.rb +0 -13
- data/lib/avm/files/appendable/tar_output_command.rb +0 -26
- data/lib/avm/files/appendable/templatized_directory.rb +0 -29
- data/lib/avm/files/appendable.rb +0 -55
- data/lib/avm/files/appender.rb +0 -11
- data/lib/avm/files/deploy.rb +0 -71
- data/lib/avm/files/formatter/formats/base.rb +0 -62
- data/lib/avm/files/formatter/formats/generic_plain.rb +0 -34
- data/lib/avm/files/formatter/formats/html.rb +0 -45
- data/lib/avm/files/formatter/formats/javascript.rb +0 -23
- data/lib/avm/files/formatter/formats/json.rb +0 -27
- data/lib/avm/files/formatter/formats/php.rb +0 -21
- data/lib/avm/files/formatter/formats/python.rb +0 -21
- data/lib/avm/files/formatter/formats/ruby.rb +0 -22
- data/lib/avm/files/formatter/formats/xml.rb +0 -27
- data/lib/avm/files/formatter/formats.rb +0 -13
- data/lib/avm/files/formatter/utf8_assert.rb +0 -74
- data/lib/avm/files/formatter.rb +0 -90
- data/lib/avm/files/info.rb +0 -24
- data/lib/avm/files/rotate.rb +0 -107
- data/lib/avm/files.rb +0 -9
- data/lib/avm/git/auto_commit/commit_info.rb +0 -23
- data/lib/avm/git/auto_commit/rules/base.rb +0 -39
- data/lib/avm/git/auto_commit/rules/last.rb +0 -19
- data/lib/avm/git/auto_commit/rules/manual.rb +0 -45
- data/lib/avm/git/auto_commit/rules/new.rb +0 -24
- data/lib/avm/git/auto_commit/rules/nth.rb +0 -31
- data/lib/avm/git/auto_commit/rules/unique.rb +0 -21
- data/lib/avm/git/auto_commit/rules.rb +0 -31
- data/lib/avm/git/auto_commit_path/ruby.rb +0 -20
- data/lib/avm/git/auto_commit_path.rb +0 -28
- data/lib/avm/git/commit/class_methods.rb +0 -31
- data/lib/avm/git/commit/deploy.rb +0 -38
- data/lib/avm/git/commit/deploy_methods.rb +0 -19
- data/lib/avm/git/commit/diff_tree_line.rb +0 -32
- data/lib/avm/git/commit/file.rb +0 -46
- data/lib/avm/git/commit.rb +0 -59
- data/lib/avm/git/file_auto_fixup.rb +0 -83
- data/lib/avm/git/issue/complete/commits.rb +0 -42
- data/lib/avm/git/issue/complete/git_subrepos.rb +0 -23
- data/lib/avm/git/issue/complete/local_branch.rb +0 -54
- data/lib/avm/git/issue/complete/local_tag.rb +0 -39
- data/lib/avm/git/issue/complete/push.rb +0 -54
- data/lib/avm/git/issue/complete/remote.rb +0 -33
- data/lib/avm/git/issue/complete/test.rb +0 -45
- data/lib/avm/git/issue/complete/tracker.rb +0 -28
- data/lib/avm/git/issue/complete/validation.rb +0 -31
- data/lib/avm/git/issue/complete/validations.rb +0 -53
- data/lib/avm/git/issue/complete/working_tree.rb +0 -19
- data/lib/avm/git/issue/complete.rb +0 -51
- data/lib/avm/git/issue/deliver.rb +0 -56
- data/lib/avm/git/organize/reference_update.rb +0 -34
- data/lib/avm/git/organize/repository.rb +0 -76
- data/lib/avm/git/revision_test.rb +0 -106
- data/lib/avm/git/subrepo_check/parent.rb +0 -51
- data/lib/avm/git/subrepo_check/remote.rb +0 -89
- data/lib/avm/git/subrepo_check/show_result.rb +0 -32
- data/lib/avm/git/subrepo_check.rb +0 -38
- data/lib/avm/git/subrepo_checks.rb +0 -59
- data/lib/avm/git.rb +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a8d74639333b0b7c2b8f8e171c22dd6184ec276653bfe46ac84cbddfdf05d0c
|
|
4
|
+
data.tar.gz: f897626773b7aa103b80347a7b41740c6a5c66c3aee68e7834ee80e44263fc3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9122946512714522606f24e5e3c79f64b773a7f4229ed25cb8c3a7e2e82b62e86a3ec4354230fdb2bce366bb36ad0e27593cd42e3e9380ab5eb82854eafbff55
|
|
7
|
+
data.tar.gz: 71b9e84a0416b0bcefccbbd283d78b5da476e1d5e366746e245eb75eb6c5f22752ef3871a4f571363554f0f99354c366823193dd6a84d3f92faa981b82299d52
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/data/instance/unit'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
module Data
|
|
7
|
+
module Instance
|
|
8
|
+
class FilesUnit < ::Avm::Data::Instance::Unit
|
|
9
|
+
EXTENSION = '.tar.gz'
|
|
10
|
+
|
|
11
|
+
attr_reader :fs_path_subpath
|
|
12
|
+
|
|
13
|
+
def initialize(instance, fs_path_subpath)
|
|
14
|
+
super(instance)
|
|
15
|
+
@fs_path_subpath = fs_path_subpath
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before_load :clear_files
|
|
19
|
+
|
|
20
|
+
def files_path
|
|
21
|
+
::File.join(instance.read_entry(::Avm::Instances::EntryKeys::FS_PATH), fs_path_subpath)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def dump_command
|
|
25
|
+
instance.host_env.command('tar', '-czf', '-', '-C', files_path, '.')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def load_command
|
|
29
|
+
instance.host_env.command('tar', '-xzf', '-', '-C', files_path)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def clear_files
|
|
33
|
+
infom "Removing all files under #{files_path}..."
|
|
34
|
+
instance.host_env.command('mkdir', '-p', files_path).execute!
|
|
35
|
+
instance.host_env.command('find', files_path, '-mindepth', 1, '-delete').execute!
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/data/package'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
module Data
|
|
7
|
+
module Instance
|
|
8
|
+
class Package < ::Avm::Data::Package
|
|
9
|
+
attr_reader :instance
|
|
10
|
+
|
|
11
|
+
def initialize(instance, options = {})
|
|
12
|
+
@instance = instance
|
|
13
|
+
super options
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/data/unit'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
module Data
|
|
7
|
+
module Instance
|
|
8
|
+
class Unit < ::Avm::Data::Unit
|
|
9
|
+
attr_reader :instance
|
|
10
|
+
|
|
11
|
+
def initialize(instance)
|
|
12
|
+
@instance = instance
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/tools/core_ext'
|
|
4
|
+
require 'avm/files/rotate'
|
|
5
|
+
require 'minitar'
|
|
6
|
+
|
|
7
|
+
module Avm
|
|
8
|
+
module Data
|
|
9
|
+
class Package
|
|
10
|
+
class Dump
|
|
11
|
+
enable_speaker
|
|
12
|
+
enable_listable
|
|
13
|
+
|
|
14
|
+
DEFAULT_EXPIRE_TIME = 1.day
|
|
15
|
+
DEFAULT_FILE_EXTENSION = '.tar'
|
|
16
|
+
|
|
17
|
+
attr_reader :package, :data_file_path, :existing
|
|
18
|
+
|
|
19
|
+
lists.add_string :existing, :denied, :overwrite, :rotate, :rotate_expired
|
|
20
|
+
|
|
21
|
+
def initialize(package, data_file_path, options = {})
|
|
22
|
+
@package = package
|
|
23
|
+
@data_file_path = data_file_path
|
|
24
|
+
options = options.to_options_consumer
|
|
25
|
+
@existing, @expire_time = options.consume(:existing, :expire_time)
|
|
26
|
+
options.validate
|
|
27
|
+
self.class.lists.existing.value_validate!(@existing)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def runnable?
|
|
31
|
+
cannot_run_reason.blank?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def cannot_run_reason
|
|
35
|
+
return nil if !data_file_exist? ||
|
|
36
|
+
[EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)
|
|
37
|
+
|
|
38
|
+
if existing == EXISTING_DENIED
|
|
39
|
+
'Data exist and overwriting is denied'
|
|
40
|
+
elsif existing == EXISTING_ROTATE_EXPIRED && !data_file_expired?
|
|
41
|
+
'Data exist and yet is not expired'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def run
|
|
46
|
+
raise "Cannot run: #{cannot_run_reason}" unless runnable?
|
|
47
|
+
|
|
48
|
+
build_dir = dump_units_to_build_directory
|
|
49
|
+
package_file = create_package_file(build_dir)
|
|
50
|
+
rotate
|
|
51
|
+
move_download_to_final_dest(package_file)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def data_file_exist?
|
|
55
|
+
::File.exist?(data_file_path)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def data_file_time
|
|
59
|
+
data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def data_file_expired?
|
|
63
|
+
data_file_time.if_present(false) { |v| v >= expire_time }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def expire_time
|
|
67
|
+
@expire_time || DEFAULT_EXPIRE_TIME
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def download
|
|
73
|
+
infom 'Downloading dump...'
|
|
74
|
+
download_path = find_download_path
|
|
75
|
+
dump_command.system!(output_file: download_path)
|
|
76
|
+
fatal_error "File \"#{download_path}\" not saved" unless ::File.exist?(download_path)
|
|
77
|
+
fatal_error "File \"#{download_path}\" is empty" if ::File.zero?(download_path)
|
|
78
|
+
download_path
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def move_download_to_final_dest(download_path)
|
|
82
|
+
::FileUtils.mkdir_p(::File.dirname(data_file_path))
|
|
83
|
+
::FileUtils.mv(download_path, data_file_path)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def rotate
|
|
87
|
+
return unless data_file_exist?
|
|
88
|
+
return unless existing == EXISTING_ROTATE
|
|
89
|
+
|
|
90
|
+
infom "Rotating \"#{data_file_path}\"..."
|
|
91
|
+
::Avm::Files::Rotate.new(data_file_path).run
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def new_build_path
|
|
95
|
+
f = ::Tempfile.new(self.class.name.parameterize + '-download')
|
|
96
|
+
path = f.path
|
|
97
|
+
f.close
|
|
98
|
+
f.unlink
|
|
99
|
+
path
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def dump_units_to_build_directory
|
|
103
|
+
dir = ::Dir.mktmpdir
|
|
104
|
+
package.dump_units_to_directory(dir)
|
|
105
|
+
dir
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def create_package_file(build_dir)
|
|
109
|
+
package_path = new_build_path
|
|
110
|
+
infom "Creating package \"#{package_path}\" from \"#{build_dir}\"..."
|
|
111
|
+
Dir.chdir(build_dir) do
|
|
112
|
+
::Minitar.pack('.', File.open(::File.expand_path(package_path), 'wb'))
|
|
113
|
+
end
|
|
114
|
+
package_path
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
require 'minitar'
|
|
5
|
+
|
|
6
|
+
module Avm
|
|
7
|
+
module Data
|
|
8
|
+
class Package
|
|
9
|
+
class Load
|
|
10
|
+
enable_speaker
|
|
11
|
+
|
|
12
|
+
attr_reader :package, :data_file_path
|
|
13
|
+
|
|
14
|
+
def initialize(package, data_file_path)
|
|
15
|
+
@package = package
|
|
16
|
+
@data_file_path = data_file_path
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def runnable?
|
|
20
|
+
cannot_run_reason.blank?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def cannot_run_reason
|
|
24
|
+
return nil if data_file_exist?
|
|
25
|
+
|
|
26
|
+
"Data file \"#{data_file_path}\" does not exist"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run
|
|
30
|
+
raise "Cannot run: #{cannot_run_reason}" unless runnable?
|
|
31
|
+
|
|
32
|
+
build_dir = extract_packages_to_build_directory
|
|
33
|
+
package.load_units_from_directory(build_dir)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def data_file_exist?
|
|
37
|
+
::File.exist?(data_file_path)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def extract_packages_to_build_directory
|
|
41
|
+
dir = ::Dir.mktmpdir
|
|
42
|
+
::Minitar.unpack(data_file_path, dir)
|
|
43
|
+
dir
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/data/package/dump'
|
|
4
|
+
require 'avm/data/package/load'
|
|
5
|
+
|
|
6
|
+
module Avm
|
|
7
|
+
module Data
|
|
8
|
+
class Package
|
|
9
|
+
attr_reader :units
|
|
10
|
+
|
|
11
|
+
def initialize(options)
|
|
12
|
+
@units = {}
|
|
13
|
+
options = options.to_options_consumer
|
|
14
|
+
units = options.consume(:units)
|
|
15
|
+
options.validate
|
|
16
|
+
units.if_present do |v|
|
|
17
|
+
v.each { |identifier, unit| add_unit(identifier, unit) }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_unit(identifier, unit)
|
|
22
|
+
@units[identifier.to_sym] = unit
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def dump(data_path, options = {})
|
|
26
|
+
::Avm::Data::Package::Dump.new(self, data_path, options)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def load(data_path)
|
|
30
|
+
::Avm::Data::Package::Load.new(self, data_path)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dump_units_to_directory(directory)
|
|
34
|
+
@units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def load_units_from_directory(directory)
|
|
38
|
+
@units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
require 'active_support/callbacks'
|
|
5
|
+
|
|
6
|
+
module Avm
|
|
7
|
+
module Data
|
|
8
|
+
class Unit
|
|
9
|
+
include ::ActiveSupport::Callbacks
|
|
10
|
+
|
|
11
|
+
define_callbacks :dump, :load
|
|
12
|
+
enable_speaker
|
|
13
|
+
|
|
14
|
+
%w[dump load].each do |action|
|
|
15
|
+
method_name = "#{action}_command"
|
|
16
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
|
17
|
+
# Should be overrided.
|
|
18
|
+
# @return [EacRubyUtils::Envs::Command]
|
|
19
|
+
def #{method_name}
|
|
20
|
+
fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
|
|
21
|
+
end
|
|
22
|
+
CODE
|
|
23
|
+
|
|
24
|
+
# Callbacks
|
|
25
|
+
%w[before after].each do |callback|
|
|
26
|
+
method = "#{callback}_#{action}"
|
|
27
|
+
class_eval <<~CODE, __FILE__, __LINE__ + 1
|
|
28
|
+
def self.#{method}(callback_method = nil, &block)
|
|
29
|
+
if callback_method
|
|
30
|
+
set_callback :#{action}, :#{callback}, callback_method
|
|
31
|
+
else
|
|
32
|
+
set_callback :#{action}, :#{callback}, &block
|
|
33
|
+
end
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def #{method}(callback_method = nil, &block)
|
|
38
|
+
singleton_class.#{method}(callback_method, &block)
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
CODE
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def extension
|
|
46
|
+
singleton_class.const_get('EXTENSION')
|
|
47
|
+
rescue NameError
|
|
48
|
+
''
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def name
|
|
52
|
+
self.class
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def load_from_directory(directory, identifier)
|
|
56
|
+
load(unit_on_directory_path(directory, identifier))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def dump_to_directory(directory, identifier)
|
|
60
|
+
dump(unit_on_directory_path(directory, identifier))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def dump(data_path)
|
|
64
|
+
run_callbacks :dump do
|
|
65
|
+
infom "Dumping unit \"#{name}\" to \"#{data_path}\"..."
|
|
66
|
+
do_dump(data_path)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def load(data_path)
|
|
71
|
+
run_callbacks :load do
|
|
72
|
+
infom "Loading unit \"#{name}\" from \"#{data_path}\"..."
|
|
73
|
+
do_load(data_path)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
protected
|
|
78
|
+
|
|
79
|
+
def do_dump(data_path)
|
|
80
|
+
dump_command.execute!(output_file: data_path)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def do_load(data_path)
|
|
84
|
+
load_command.execute!(input_file: data_path)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def unit_on_directory_path(directory, identifier)
|
|
90
|
+
::File.join(directory, "#{identifier}#{extension}")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/jobs/variables_source'
|
|
4
|
+
require 'avm/result'
|
|
5
|
+
require 'eac_cli/core_ext'
|
|
6
|
+
|
|
7
|
+
module Avm
|
|
8
|
+
module Jobs
|
|
9
|
+
module Base
|
|
10
|
+
common_concern do
|
|
11
|
+
include ::ActiveSupport::Callbacks
|
|
12
|
+
|
|
13
|
+
enable_speaker
|
|
14
|
+
enable_simple_cache
|
|
15
|
+
enable_listable
|
|
16
|
+
common_constructor :instance, :options, default: [{}] do
|
|
17
|
+
if option_list.present?
|
|
18
|
+
self.options = option_list.hash_keys_validate!(options.symbolize_keys)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
define_callbacks(*jobs)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module ClassMethods
|
|
25
|
+
def jobs
|
|
26
|
+
const_get('JOBS').dup
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module InstanceMethods
|
|
31
|
+
def option_list
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def run
|
|
36
|
+
start_banner if respond_to?(:start_banner)
|
|
37
|
+
run_jobs
|
|
38
|
+
::Avm::Result.success('Done!')
|
|
39
|
+
rescue ::Avm::Result::Error => e
|
|
40
|
+
e.to_result
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def variables_source
|
|
44
|
+
::Avm::Jobs::VariablesSource.new(self, instance)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def run_jobs
|
|
50
|
+
jobs.each do |job|
|
|
51
|
+
run_callbacks job do
|
|
52
|
+
send(job)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def jobs
|
|
58
|
+
self.class.jobs
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
module Jobs
|
|
7
|
+
class VariablesSource
|
|
8
|
+
common_constructor :job, :instance
|
|
9
|
+
|
|
10
|
+
def read_entry(path, options = {})
|
|
11
|
+
entry_from_job(path) || instance.read_entry(path, options)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def entry_from_job(path)
|
|
17
|
+
method = path.gsub('.', '_').underscore
|
|
18
|
+
return job.send(method) if job.respond_to?(method, true)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support/core_ext/object/blank'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
# String with paths like PATH variable.
|
|
7
|
+
# Note: the separator is not system dependent.
|
|
8
|
+
class PathString < String
|
|
9
|
+
SEPARATOR = ':'
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
# Shortcut for [Avm::Paths.new(string).paths].
|
|
13
|
+
def paths(string)
|
|
14
|
+
new(string).paths
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(string = nil)
|
|
19
|
+
super(string.to_s)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @return [Array] List of paths. Blank paths are rejected.
|
|
23
|
+
def paths
|
|
24
|
+
split(SEPARATOR).reject(&:blank?)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
require 'eac_ruby_utils/gems_registry'
|
|
5
|
+
|
|
6
|
+
module Avm
|
|
7
|
+
module Registry
|
|
8
|
+
class Base
|
|
9
|
+
enable_simple_cache
|
|
10
|
+
common_constructor :module_suffix
|
|
11
|
+
|
|
12
|
+
def detect(*registered_initialize_args)
|
|
13
|
+
detect_optional(*registered_initialize_args) ||
|
|
14
|
+
raise("No registered module valid for #{registered_initialize_args}" \
|
|
15
|
+
" (Module suffix: #{module_suffix})")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def detect_optional(*registered_initialize_args)
|
|
19
|
+
registered_modules.lazy.map { |klass| klass.new(*registered_initialize_args) }
|
|
20
|
+
.find(&:valid?)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def provider_module_suffix
|
|
24
|
+
"#{module_suffix}::Provider"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def single_module_suffix
|
|
28
|
+
"#{module_suffix}::Base"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_s
|
|
32
|
+
"#{self.class}[#{module_suffix}]"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def valid_registered_module?(a_module)
|
|
36
|
+
a_module.is_a?(::Class) && !a_module.abstract?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def registered_modules_uncached
|
|
42
|
+
(single_registered_modules + provider_registered_modules)
|
|
43
|
+
.select { |v| valid_registered_module?(v) }.uniq.sort_by { |s| [s.name] }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def single_registered_modules
|
|
47
|
+
single_instance_registry.registered.map(&:registered_module)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def provider_registered_modules
|
|
51
|
+
provider_registry.registered.map(&:registered_module).flat_map do |provider_class|
|
|
52
|
+
provider_class.new.all
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def single_instance_registry_uncached
|
|
57
|
+
::EacRubyUtils::GemsRegistry.new(single_module_suffix)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def provider_registry_uncached
|
|
61
|
+
::EacRubyUtils::GemsRegistry.new(provider_module_suffix)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/avm/registry.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
require 'eac_ruby_utils/gems_registry'
|
|
5
|
+
|
|
6
|
+
module Avm
|
|
7
|
+
module Registry
|
|
8
|
+
require_sub __FILE__
|
|
9
|
+
enable_listable
|
|
10
|
+
lists.add_symbol :category, :instance_stereotypes, :scms, :source_stereotypes
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
enable_simple_cache
|
|
14
|
+
|
|
15
|
+
# @return [Array<Avm::Registry::Base>]
|
|
16
|
+
def registries
|
|
17
|
+
lists.category.values.map { |c| send(c) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
::Avm::Registry.lists.category.each_value do |category|
|
|
23
|
+
define_method "#{category}_uncached" do
|
|
24
|
+
::Avm::Registry::Base.new(category.to_s.camelize)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
|
4
|
+
|
|
5
|
+
module Avm
|
|
6
|
+
module Rspec
|
|
7
|
+
module Setup
|
|
8
|
+
def self.extended(obj)
|
|
9
|
+
obj.setup_in_avm_registry_example
|
|
10
|
+
obj.setup_not_in_avm_registry_example
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def setup_in_avm_registry_example
|
|
14
|
+
require 'avm/rspec/shared_examples/in_avm_registry'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def setup_not_in_avm_registry_example
|
|
18
|
+
require 'avm/rspec/shared_examples/not_in_avm_registry'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/registry'
|
|
4
|
+
|
|
5
|
+
::RSpec.shared_examples 'in_avm_registry' do |registry_method|
|
|
6
|
+
let(:avm_registry) { ::Avm::Registry.send(registry_method) }
|
|
7
|
+
|
|
8
|
+
it 'is in the avm registry' do
|
|
9
|
+
expect(avm_registry.registered_modules).to include(described_class)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'avm/registry'
|
|
4
|
+
|
|
5
|
+
::RSpec.shared_examples 'not_in_avm_registry' do |registry_method = nil|
|
|
6
|
+
registry_method.if_present(::Avm::Registry.registries) { |v| [::Avm::Registry.send(v)] }
|
|
7
|
+
.each do |registry|
|
|
8
|
+
context "when registry is #{registry}" do
|
|
9
|
+
it 'is not in the avm registry' do
|
|
10
|
+
expect(registry.registered_modules).not_to include(described_class)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|