avm 0.56.0 → 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: 2fe83959f89ed9d43c44578111aa230b740036e6d9231b5c80a6a59ba777d7cc
4
- data.tar.gz: 48911ce71466c63dbe3e8dd4ab84f0ecfa061a1c7c55103150ce325bcf745462
3
+ metadata.gz: 563904ca1b51a6a150dea04c0b6ae22e465fdd51ab6528743e33d62a6565b92c
4
+ data.tar.gz: 0b81dcf8b1b4f1442141d464ed4f4f94cbaa889f61cb386dada4cd31e81093c1
5
5
  SHA512:
6
- metadata.gz: 210f097d0c4f57a0fa0a1bbf64e83e9d4a116250ba552f477401fbc5064eaa7f781c7ff1a3115b5a42844299728578cc13508c663031c2e287994d0507f7b488
7
- data.tar.gz: 7b65907b3c3201914d97d1e3efa2a740b26dcb87cd820e689a81fdcfbb6e0e1d21619807a6a0f02759af964cae5f0278020eea4dce16672e8aad391bc6d8ee8d
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
@@ -46,8 +46,10 @@ module Avm
46
46
  field_get(translate_field(avm_field))
47
47
  end
48
48
 
49
+ # @return [String, nil]
49
50
  def field_get(name)
50
- data[name.to_sym].if_present(&:to_s)
51
+ v = data[name.to_sym]
52
+ v.nil? ? nil : v.to_s
51
53
  end
52
54
 
53
55
  def field_set(field, value)
@@ -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.0'
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.0
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-09 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
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.29'
39
+ version: '0.30'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.29'
46
+ version: '0.30'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: eac_config
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0.13'
95
+ version: '0.14'
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0.13'
102
+ version: '0.14'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: eac_ruby_utils
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -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