avm 0.56.1 → 0.57.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3fbdddcdbc848524b57336f7c1ac341950a1f725d4de87a64dde6951499d835
4
- data.tar.gz: bf01ee819ed341084e1dea109d318d0275d1661a3228048d98e873df544eacb9
3
+ metadata.gz: 563904ca1b51a6a150dea04c0b6ae22e465fdd51ab6528743e33d62a6565b92c
4
+ data.tar.gz: 0b81dcf8b1b4f1442141d464ed4f4f94cbaa889f61cb386dada4cd31e81093c1
5
5
  SHA512:
6
- metadata.gz: 22a5f8d897b2eeb7e19ca82e4f1e50c864a97ff08936a83dfcf4ede15d8510650ce8beb69b300d5800b7c825825cf200a9e1eb6672c4a097028857ec7b6384c3
7
- data.tar.gz: b3956dc0425e73d3a4579d1d50d9ad9704adc41079ba4fbf779d2f52edd31055ea255ee47bb8d88a52351124c583cc4b33ff0857ef65d1f57eb85ace1abdfef9
6
+ metadata.gz: a4cb6348291b7ae8c74957a6cfa9448a034077e6ea755ed49079e991be4abce66c33ad55983faa452ced6d28ce294e0f6d787caf2edc634f0d9edf6317e5c9c5
7
+ data.tar.gz: 07525e34146d9e712aaa8157cbafb8e9c2fdd83aa2b381931399306aa0592d8d839c272b0851eb8fa0d5bc46538f350e2367da48d1821d00413873f2524772fb
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/callbacks'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Data
8
+ module Callbacks
9
+ common_concern do
10
+ include ::ActiveSupport::Callbacks
11
+
12
+ %i[dump load].each do |action|
13
+ define_callbacks action
14
+
15
+ %i[before after].each do |callback|
16
+ method_name = "#{callback}_#{action}"
17
+ singleton_class.class_eval do
18
+ define_method method_name do |callback_method = nil, &block|
19
+ if callback_method
20
+ set_callback action, callback, callback_method
21
+ else
22
+ set_callback action, callback, &block
23
+ end
24
+ self
25
+ end
26
+ end
27
+
28
+ define_method method_name do |callback_method = nil, &block|
29
+ singleton_class.send(method_name, callback_method, &block)
30
+ self
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/data/package/dump'
4
- require 'avm/data/package/load'
3
+ require 'avm/data/callbacks'
4
+ require 'eac_ruby_utils/core_ext'
5
5
 
6
6
  module Avm
7
7
  module Data
8
8
  class Package
9
- attr_reader :units
9
+ require_sub __FILE__
10
+ include ::Avm::Data::Callbacks
10
11
 
11
12
  def initialize(options)
12
- @units = {}
13
13
  options = options.to_options_consumer
14
14
  units = options.consume(:units)
15
15
  options.validate
@@ -19,7 +19,7 @@ module Avm
19
19
  end
20
20
 
21
21
  def add_unit(identifier, unit)
22
- @units[identifier.to_sym] = unit
22
+ units[identifier.to_sym] = unit
23
23
  end
24
24
 
25
25
  def dump(data_path, options = {})
@@ -31,11 +31,19 @@ module Avm
31
31
  end
32
32
 
33
33
  def dump_units_to_directory(directory)
34
- @units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
34
+ run_callbacks :dump do
35
+ units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
36
+ end
35
37
  end
36
38
 
37
39
  def load_units_from_directory(directory)
38
- @units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
40
+ run_callbacks :load do
41
+ units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
42
+ end
43
+ end
44
+
45
+ def units
46
+ @units ||= {}
39
47
  end
40
48
  end
41
49
  end
data/lib/avm/data/unit.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/data/callbacks'
3
4
  require 'eac_ruby_utils/core_ext'
4
- require 'active_support/callbacks'
5
5
 
6
6
  module Avm
7
7
  module Data
8
8
  class Unit
9
- include ::ActiveSupport::Callbacks
9
+ include ::Avm::Data::Callbacks
10
10
 
11
- define_callbacks :dump, :load
12
11
  enable_speaker
13
12
 
14
13
  %w[dump load].each do |action|
@@ -20,26 +19,6 @@ module Avm
20
19
  fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
21
20
  end
22
21
  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
22
  end
44
23
 
45
24
  def extension
@@ -15,7 +15,7 @@ module Avm
15
15
  .if_present do |v|
16
16
  ::File.join(
17
17
  v,
18
- "#{id}#{::Avm::Data::Instance::Package::Dump::DEFAULT_FILE_EXTENSION}"
18
+ "#{id}#{::Avm::Instances::Data::Package::Dump::DEFAULT_FILE_EXTENSION}"
19
19
  )
20
20
  end
21
21
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/data/unit'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Data
8
+ class FilesUnit < ::Avm::Instances::Data::Unit
9
+ EXTENSION = '.tar.gz'
10
+
11
+ enable_listable
12
+ lists.add_symbol :option, :sudo_user
13
+
14
+ common_constructor :instance, :fs_path_subpath, :options, default: [{}],
15
+ super_args: -> { [instance] } do
16
+ self.fs_path_subpath = fs_path_subpath.to_pathname
17
+ self.options = self.class.lists.option.hash_keys_validate!(options)
18
+ end
19
+
20
+ before_load :clear_files
21
+
22
+ # @return [Pathname]
23
+ def files_path
24
+ fs_path_subpath
25
+ .expand_path(instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH))
26
+ end
27
+
28
+ def dump_command
29
+ instance_command('tar', '-czf', '-', '-C', files_path, '.')
30
+ end
31
+
32
+ def load_command
33
+ instance_command('tar', '-xzf', '-', '-C', files_path)
34
+ end
35
+
36
+ def clear_files
37
+ infom "Removing all files under #{files_path}..."
38
+ instance_command('mkdir', '-p', files_path).execute!
39
+ instance_command('find', files_path, '-mindepth', 1, '-delete').execute!
40
+ end
41
+
42
+ # @return [EacRubyUtils::Envs::Command]
43
+ def instance_command(*args)
44
+ args = ['sudo', '-Hu', sudo_user] + args if sudo_user.present?
45
+ instance.host_env.command(*args)
46
+ end
47
+
48
+ # @return [String, nil]
49
+ def sudo_user
50
+ options[OPTION_SUDO_USER]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,8 +3,8 @@
3
3
  require 'avm/data/package'
4
4
 
5
5
  module Avm
6
- module Data
7
- module Instance
6
+ module Instances
7
+ module Data
8
8
  class Package < ::Avm::Data::Package
9
9
  attr_reader :instance
10
10
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Instances
8
+ module Data
9
+ class Unit < ::Avm::Data::Unit
10
+ common_constructor :instance
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Data
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
data/lib/avm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.56.1'
4
+ VERSION = '0.57.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.56.1
4
+ version: 0.57.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-15 00:00:00.000000000 Z
11
+ date: 2022-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -263,10 +263,7 @@ files:
263
263
  - lib/avm/applications/base.rb
264
264
  - lib/avm/applications/base/publishing.rb
265
265
  - lib/avm/applications/base/stereotype.rb
266
- - lib/avm/data/instance.rb
267
- - lib/avm/data/instance/files_unit.rb
268
- - lib/avm/data/instance/package.rb
269
- - lib/avm/data/instance/unit.rb
266
+ - lib/avm/data/callbacks.rb
270
267
  - lib/avm/data/package.rb
271
268
  - lib/avm/data/package/dump.rb
272
269
  - lib/avm/data/package/load.rb
@@ -316,6 +313,10 @@ files:
316
313
  - lib/avm/instances/base/entry_keys.rb
317
314
  - lib/avm/instances/base/install.rb
318
315
  - lib/avm/instances/base/web.rb
316
+ - lib/avm/instances/data.rb
317
+ - lib/avm/instances/data/files_unit.rb
318
+ - lib/avm/instances/data/package.rb
319
+ - lib/avm/instances/data/unit.rb
319
320
  - lib/avm/instances/docker_image.rb
320
321
  - lib/avm/instances/entry_keys.rb
321
322
  - lib/avm/instances/ids.rb
@@ -1,41 +0,0 @@
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::INSTALL_PATH),
22
- fs_path_subpath)
23
- end
24
-
25
- def dump_command
26
- instance.host_env.command('tar', '-czf', '-', '-C', files_path, '.')
27
- end
28
-
29
- def load_command
30
- instance.host_env.command('tar', '-xzf', '-', '-C', files_path)
31
- end
32
-
33
- def clear_files
34
- infom "Removing all files under #{files_path}..."
35
- instance.host_env.command('mkdir', '-p', files_path).execute!
36
- instance.host_env.command('find', files_path, '-mindepth', 1, '-delete').execute!
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,17 +0,0 @@
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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub(__FILE__)
5
-
6
- module Avm
7
- module Data
8
- module Instance
9
- end
10
- end
11
- end