Class: Martilla::Storage
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.create(config = {}) ⇒ Object
When a new Storage is supported it needs to go here.
Instance Method Summary collapse
- #append_datetime_suffix(filename) ⇒ Object
- #config_error(config_name) ⇒ Object
- #enforce_retention! ⇒ Object
-
#initialize(config) ⇒ Storage
constructor
A new instance of Storage.
- #invalid_options_msg ⇒ Object
- #options_filename ⇒ Object
- #output_filename(gzip) ⇒ Object
- #persist(temp_file:, gzip:) ⇒ Object
- #retention_limit ⇒ Object
- #suffix? ⇒ Boolean
- #timestamp_regex ⇒ Object
Methods inherited from Component
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/martilla/storage.rb', line 5 def @options end |
Class Method Details
.create(config = {}) ⇒ Object
When a new Storage is supported it needs to go here
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/martilla/storage.rb', line 66 def self.create(config = {}) case config['type'].downcase when 'local' Local.new(config['options']) when 's3' S3.new(config['options']) when 'scp' Scp.new(config['options']) else raise Error.new("Invalid Storage type: #{config['type']}") end end |
Instance Method Details
#append_datetime_suffix(filename) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/martilla/storage.rb', line 40 def append_datetime_suffix(filename) dirname = File.dirname(filename) basename = File.basename(filename, '.*') # 'dir_with_name' is the original filename WITHOUT the extension dir_with_name = "#{dirname}/#{basename}" dir_with_name = basename if dirname == '.' extension = filename.gsub(dir_with_name, '') = Time.now.strftime("%Y-%m-%dT%H%M%S") "#{dirname}/#{basename}_#{}#{extension}" end |
#config_error(config_name) ⇒ Object
61 62 63 |
# File 'lib/martilla/storage.rb', line 61 def config_error(config_name) Error.new("Storage adapter configuration requires #{config_name}. Details here: https://github.com/fdoxyz/martilla") end |
#enforce_retention! ⇒ Object
16 17 18 |
# File 'lib/martilla/storage.rb', line 16 def enforce_retention! raise NotImplementedError, 'You must implement the enforce_retention! method' end |
#invalid_options_msg ⇒ Object
20 21 22 |
# File 'lib/martilla/storage.rb', line 20 def 'Storage configuration is invalid. Details here: https://github.com/fdoxyz/martilla' end |
#options_filename ⇒ Object
29 30 31 |
# File 'lib/martilla/storage.rb', line 29 def @options['filename'] || 'backup.sql' end |
#output_filename(gzip) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/martilla/storage.rb', line 33 def output_filename(gzip) filename = filename = append_datetime_suffix(filename) if suffix? filename = "#{filename}.gz" if gzip filename end |
#persist(temp_file:, gzip:) ⇒ Object
12 13 14 |
# File 'lib/martilla/storage.rb', line 12 def persist(temp_file:, gzip:) raise NotImplementedError, 'You must implement the persist method' end |
#retention_limit ⇒ Object
53 54 55 |
# File 'lib/martilla/storage.rb', line 53 def retention_limit @options['retention'].to_i end |
#suffix? ⇒ Boolean
24 25 26 27 |
# File 'lib/martilla/storage.rb', line 24 def suffix? return true if @options['suffix'].nil? @options['suffix'] end |
#timestamp_regex ⇒ Object
57 58 59 |
# File 'lib/martilla/storage.rb', line 57 def /\d{4}-\d{2}-\d{2}T\d{6}/ end |