avm 0.73.1 → 0.74.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: 7982b293a654555c267bc2f3b8856a40e4e60a5ee2a9bcc08796d4814a811c15
4
- data.tar.gz: 6a8ade3bc981708360d1cecdb7e9ee1461d0fad4ff3daa0ae7de1f6636e99e9d
3
+ metadata.gz: 69fd41323b3ec2e08b3339520c7ac89b6a0a1f8504f662033e68f9a5f8d43eed
4
+ data.tar.gz: 32aa288f19bcfc07f494479e1c1fe04c660d77fdc3435e63c81ff9beb1ea97b2
5
5
  SHA512:
6
- metadata.gz: 32e5a58c320316929d9d954b98a284f40e4231af15b848513cdfcfc91364ad20362b95c05af1fe6c3f4822fc786a981129c8d3878d55104189f2d7af91c442f9
7
- data.tar.gz: de0f2e9f63d6bd9e3aac64f36ef505f028494462e6e734b42efc1c88be62bb77041e3c2a8ff31a92293884e4d3e73872a9c95e219fc7e3909d6308de124563cc
6
+ metadata.gz: 9fac0d42acc16cc1cf70b6c5331c20171356354400de3473aa5341d8b2c01d7b6c6ea168778359d50a867e6637678b5ad85f0f8ccc7aa5ff44f5c126728576a1
7
+ data.tar.gz: 36ae852382bacaeb8918cb351d3e9a7bff8db59476bd8ca3fa1ec88fcb20dbcad5546027b5b49a5789387017d59b1cc7b0d40fedb0c20c20f2234a0a3a28cf25
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/performer'
4
+ require 'avm/data/rotate'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_ruby_utils/fs/temp'
7
+
8
+ module Avm
9
+ module Data
10
+ class Dumper < ::Avm::Data::Performer
11
+ DEFAULT_EXPIRE_TIME = 1.day
12
+
13
+ enable_speaker
14
+ enable_listable
15
+ lists.add_symbol :existing, :denied, :overwrite, :rotate, :rotate_expired
16
+ immutable_accessor :existing, :expire_time, :target_path
17
+
18
+ # @return [String, nil]
19
+ def cannot_perform_reason
20
+ return nil if !target_path.exist? ||
21
+ [EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)
22
+
23
+ if existing == EXISTING_DENIED
24
+ 'Data exist and overwriting is denied'
25
+ elsif existing == EXISTING_ROTATE_EXPIRED && !target_path_expired?
26
+ 'Data exist and yet is not expired'
27
+ end
28
+ end
29
+
30
+ # @return [Pathname]
31
+ def default_dump_path
32
+ r = data_owner.data_default_dump_path
33
+ include_excludes_path_suffix.if_present(r) do |v|
34
+ r.basename_sub('.*') { |b| "#{b}#{v}#{r.extname}" }
35
+ end
36
+ end
37
+
38
+ # @return [Boolean]
39
+ def target_path_expired?
40
+ target_path_time.if_present(false) { |v| v >= expire_time }
41
+ end
42
+
43
+ # @return [ActiveSupport::Duration, nil]
44
+ def target_path_time
45
+ target_path.exist? ? ::Time.now - ::File.mtime(target_path) : nil
46
+ end
47
+
48
+ protected
49
+
50
+ attr_reader :temp_data_path
51
+
52
+ # @return [Array<Symbol>]
53
+ def all_units
54
+ data_owner.units.keys.sort
55
+ end
56
+
57
+ def build_temp_data_file
58
+ data_owner.dump(temp_data_path, *include_excludes_arguments)
59
+ raise "\"#{temp_data_path}\" do not exist" unless temp_data_path.exist?
60
+ raise "\"#{temp_data_path}\" is not a file" unless temp_data_path.file?
61
+ end
62
+
63
+ # @return [Array<Symbol>]
64
+ def excluded_units
65
+ excludes.map(&:to_sym).sort
66
+ end
67
+
68
+ # @return [Symbol, nil]
69
+ def existing_set_filter(value)
70
+ value.nil? ? nil : self.class.lists.existing.value_validate!(value)
71
+ end
72
+
73
+ # @return [ActiveSupport::Duration]
74
+ def expire_time_get_filter(value)
75
+ value || DEFAULT_EXPIRE_TIME
76
+ end
77
+
78
+ # @return [String]
79
+ def include_excludes_path_suffix
80
+ return nil unless data_owner.respond_to?(:units)
81
+
82
+ r = included_units.any? ? included_units : all_units
83
+ r -= excluded_units if excluded_units.any?
84
+ r.any? && r != all_units ? "_#{r.join('-')}" : ''
85
+ end
86
+
87
+ # @return [Array<Symbol>]
88
+ def included_units
89
+ includes.map(&:to_sym).sort
90
+ end
91
+
92
+ # @return [self]
93
+ def internal_perform
94
+ on_temp_data_file do
95
+ build_temp_data_file
96
+ rotate
97
+ move_data_to_target_path
98
+ end
99
+ end
100
+
101
+ def move_data_to_target_path
102
+ ::FileUtils.mv(temp_data_path, target_path.assert_parent)
103
+ end
104
+
105
+ def on_temp_data_file
106
+ ::EacRubyUtils::Fs::Temp.on_file do |file|
107
+ @temp_data_path = file.to_pathname
108
+ yield
109
+ end
110
+ end
111
+
112
+ # @return [String, nil]
113
+ def rotate
114
+ return unless target_path.exist?
115
+ return unless existing == EXISTING_ROTATE
116
+
117
+ infom "Rotating \"#{target_path}\"..."
118
+ ::Avm::Data::Rotate.new(target_path).run
119
+ end
120
+
121
+ # @return [Pathname]
122
+ def target_path_get_filter(value)
123
+ (value || default_dump_path).to_pathname
124
+ end
125
+ end
126
+ end
127
+ end
@@ -1,109 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/data/package/base_performer'
3
4
  require 'avm/data/package/build_directory'
4
- require 'avm/data/rotate'
5
5
  require 'eac_ruby_utils/core_ext'
6
6
  require 'minitar'
7
7
 
8
8
  module Avm
9
9
  module Data
10
10
  class Package
11
- class Dump
12
- enable_speaker
13
- enable_listable
11
+ class Dump < ::Avm::Data::Package::BasePerformer
12
+ enable_method_class
14
13
  include ::Avm::Data::Package::BuildDirectory
15
14
 
16
- DEFAULT_EXPIRE_TIME = 1.day
15
+ attr_reader :target_path
17
16
 
18
- attr_reader :package, :data_file_path, :existing
19
-
20
- lists.add_string :existing, :denied, :overwrite, :rotate, :rotate_expired
21
-
22
- def initialize(package, data_file_path, options = {})
23
- @package = package
24
- @data_file_path = data_file_path
25
- options = options.to_options_consumer
26
- @existing, @expire_time = options.consume(:existing, :expire_time)
27
- options.validate
28
- self.class.lists.existing.value_validate!(@existing)
29
- end
30
-
31
- def runnable?
32
- cannot_run_reason.blank?
33
- end
34
-
35
- def cannot_run_reason
36
- return nil if !data_file_exist? ||
37
- [EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)
38
-
39
- if existing == EXISTING_DENIED
40
- 'Data exist and overwriting is denied'
41
- elsif existing == EXISTING_ROTATE_EXPIRED && !data_file_expired?
42
- 'Data exist and yet is not expired'
43
- end
17
+ def initialize(package, target_path, options = {})
18
+ super(package, options)
19
+ @target_path = target_path.to_pathname
44
20
  end
45
21
 
46
- def run
47
- raise "Cannot run: #{cannot_run_reason}" unless runnable?
48
-
49
- package_file = on_build_directory do
22
+ # @return [void]
23
+ def result
24
+ on_build_directory do
50
25
  dump_units_to_build_directory
51
26
  create_package_file
52
27
  end
53
- rotate
54
- move_download_to_final_dest(package_file)
55
- end
56
-
57
- def data_file_exist?
58
- ::File.exist?(data_file_path)
59
- end
60
-
61
- def data_file_time
62
- data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil
63
- end
64
-
65
- def data_file_expired?
66
- data_file_time.if_present(false) { |v| v >= expire_time }
67
- end
68
-
69
- def expire_time
70
- @expire_time || DEFAULT_EXPIRE_TIME
71
- end
72
-
73
- private
74
-
75
- def move_download_to_final_dest(download_path)
76
- ::FileUtils.mkdir_p(::File.dirname(data_file_path))
77
- ::FileUtils.mv(download_path, data_file_path)
78
- end
79
-
80
- def rotate
81
- return unless data_file_exist?
82
- return unless existing == EXISTING_ROTATE
83
-
84
- infom "Rotating \"#{data_file_path}\"..."
85
- ::Avm::Data::Rotate.new(data_file_path).run
86
28
  end
87
29
 
88
- def new_build_path
89
- f = ::Tempfile.new(self.class.name.parameterize + '-download')
90
- path = f.path
91
- f.close
92
- f.unlink
93
- path
94
- end
30
+ protected
95
31
 
96
32
  def dump_units_to_build_directory
97
- package.dump_units_to_directory(build_directory)
33
+ package.dump_units_to_directory(build_directory, selected_units)
98
34
  end
99
35
 
100
36
  def create_package_file
101
- package_path = new_build_path
102
- infom "Creating package \"#{package_path}\" from \"#{build_directory}\"..."
37
+ infom "Creating package \"#{target_path}\" from \"#{build_directory}\"..."
103
38
  ::Dir.chdir(build_directory.to_path) do
104
- ::Minitar.pack('.', File.open(::File.expand_path(package_path), 'wb'))
39
+ ::Minitar.pack('.', ::File.open(target_path, 'wb'))
105
40
  end
106
- package_path
107
41
  end
108
42
  end
109
43
  end
@@ -32,17 +32,15 @@ module Avm
32
32
  DATA_FILE_EXTENSION
33
33
  end
34
34
 
35
- def dump(data_path, options = {})
36
- ::Avm::Data::Package::Dump.new(self, data_path, options)
37
- end
38
-
39
35
  def load(data_path)
40
36
  ::Avm::Data::Package::Load.new(self, data_path)
41
37
  end
42
38
 
43
- def dump_units_to_directory(directory)
39
+ def dump_units_to_directory(directory, selected_units = nil)
44
40
  run_callbacks :dump do
45
- units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
41
+ (selected_units || units).each do |identifier, unit|
42
+ unit.dump_to_directory(directory, identifier)
43
+ end
46
44
  end
47
45
  end
48
46
 
@@ -12,6 +12,11 @@ module Avm
12
12
  @instance = instance
13
13
  super options
14
14
  end
15
+
16
+ # @return [Pathname]
17
+ def data_default_dump_path
18
+ instance.data_default_dump_path.to_pathname
19
+ end
15
20
  end
16
21
  end
17
22
  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.73.1'
4
+ VERSION = '0.74.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.73.1
4
+ version: 0.74.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
@@ -233,6 +233,7 @@ files:
233
233
  - lib/avm/applications/base/stereotype.rb
234
234
  - lib/avm/data/callbacks.rb
235
235
  - lib/avm/data/clearer.rb
236
+ - lib/avm/data/dumper.rb
236
237
  - lib/avm/data/package.rb
237
238
  - lib/avm/data/package/base_performer.rb
238
239
  - lib/avm/data/package/build_directory.rb