Class: Avm::Data::Package::Dump
Constant Summary collapse
- DEFAULT_EXPIRE_TIME =
1.day
- DEFAULT_FILE_EXTENSION =
'.tar'
Instance Attribute Summary collapse
-
#data_file_path ⇒ Object
readonly
Returns the value of attribute data_file_path.
-
#existing ⇒ Object
readonly
Returns the value of attribute existing.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
Instance Method Summary collapse
- #cannot_run_reason ⇒ Object
- #data_file_exist? ⇒ Boolean
- #data_file_expired? ⇒ Boolean
- #data_file_time ⇒ Object
- #expire_time ⇒ Object
-
#initialize(package, data_file_path, options = {}) ⇒ Dump
constructor
A new instance of Dump.
- #run ⇒ Object
- #runnable? ⇒ Boolean
Constructor Details
#initialize(package, data_file_path, options = {}) ⇒ Dump
Returns a new instance of Dump.
21 22 23 24 25 26 27 28 |
# File 'lib/avm/data/package/dump.rb', line 21 def initialize(package, data_file_path, = {}) @package = package @data_file_path = data_file_path = . @existing, @expire_time = .consume(:existing, :expire_time) .validate self.class.lists.existing.value_validate!(@existing) end |
Instance Attribute Details
#data_file_path ⇒ Object (readonly)
Returns the value of attribute data_file_path.
17 18 19 |
# File 'lib/avm/data/package/dump.rb', line 17 def data_file_path @data_file_path end |
#existing ⇒ Object (readonly)
Returns the value of attribute existing.
17 18 19 |
# File 'lib/avm/data/package/dump.rb', line 17 def existing @existing end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
17 18 19 |
# File 'lib/avm/data/package/dump.rb', line 17 def package @package end |
Instance Method Details
#cannot_run_reason ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/avm/data/package/dump.rb', line 34 def cannot_run_reason return nil if !data_file_exist? || [EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing) if existing == EXISTING_DENIED 'Data exist and overwriting is denied' elsif existing == EXISTING_ROTATE_EXPIRED && !data_file_expired? 'Data exist and yet is not expired' end end |
#data_file_exist? ⇒ Boolean
54 55 56 |
# File 'lib/avm/data/package/dump.rb', line 54 def data_file_exist? ::File.exist?(data_file_path) end |
#data_file_expired? ⇒ Boolean
62 63 64 |
# File 'lib/avm/data/package/dump.rb', line 62 def data_file_expired? data_file_time.if_present(false) { |v| v >= expire_time } end |
#data_file_time ⇒ Object
58 59 60 |
# File 'lib/avm/data/package/dump.rb', line 58 def data_file_time data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil end |
#expire_time ⇒ Object
66 67 68 |
# File 'lib/avm/data/package/dump.rb', line 66 def expire_time @expire_time || DEFAULT_EXPIRE_TIME end |
#run ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/avm/data/package/dump.rb', line 45 def run raise "Cannot run: #{cannot_run_reason}" unless runnable? build_dir = dump_units_to_build_directory package_file = create_package_file(build_dir) rotate move_download_to_final_dest(package_file) end |
#runnable? ⇒ Boolean
30 31 32 |
# File 'lib/avm/data/package/dump.rb', line 30 def runnable? cannot_run_reason.blank? end |