Class: Avm::Data::Package::Dump
- Inherits:
-
Object
- Object
- Avm::Data::Package::Dump
- Includes:
- BuildDirectory
- Defined in:
- lib/avm/data/package/dump.rb
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.
23 24 25 26 27 28 29 30 |
# File 'lib/avm/data/package/dump.rb', line 23 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.
19 20 21 |
# File 'lib/avm/data/package/dump.rb', line 19 def data_file_path @data_file_path end |
#existing ⇒ Object (readonly)
Returns the value of attribute existing.
19 20 21 |
# File 'lib/avm/data/package/dump.rb', line 19 def existing @existing end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
19 20 21 |
# File 'lib/avm/data/package/dump.rb', line 19 def package @package end |
Instance Method Details
#cannot_run_reason ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/avm/data/package/dump.rb', line 36 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
58 59 60 |
# File 'lib/avm/data/package/dump.rb', line 58 def data_file_exist? ::File.exist?(data_file_path) end |
#data_file_expired? ⇒ Boolean
66 67 68 |
# File 'lib/avm/data/package/dump.rb', line 66 def data_file_expired? data_file_time.if_present(false) { |v| v >= expire_time } end |
#data_file_time ⇒ Object
62 63 64 |
# File 'lib/avm/data/package/dump.rb', line 62 def data_file_time data_file_exist? ? ::Time.now - ::File.mtime(data_file_path) : nil end |
#expire_time ⇒ Object
70 71 72 |
# File 'lib/avm/data/package/dump.rb', line 70 def expire_time @expire_time || DEFAULT_EXPIRE_TIME end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/avm/data/package/dump.rb', line 47 def run raise "Cannot run: #{cannot_run_reason}" unless runnable? package_file = on_build_directory do dump_units_to_build_directory create_package_file end rotate move_download_to_final_dest(package_file) end |
#runnable? ⇒ Boolean
32 33 34 |
# File 'lib/avm/data/package/dump.rb', line 32 def runnable? cannot_run_reason.blank? end |