Module: Factorix::CLI::Commands::BackupSupport

Defined in:
lib/factorix/cli/commands/backup_support.rb

Overview

Mixin for commands that backup files before writing

This module provides:

  • –backup-extension option to specify backup file extension

  • backup_if_exists method to backup a file before overwriting

Prepend this module to commands that modify mod-list.json or mod-settings.dat

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object

Hook called when this module is prepended to a class

Parameters:

  • base (Class)

    the class prepending this module



16
17
18
19
20
# File 'lib/factorix/cli/commands/backup_support.rb', line 16

def self.prepended(base)
  base.class_eval do
    option :backup_extension, default: ".bak", desc: "Backup file extension"
  end
end

Instance Method Details

#call(**options) ⇒ Object

Store the –backup-extension option for use in backup_if_exists

Parameters:

  • options (Hash)

    command options



28
29
30
31
# File 'lib/factorix/cli/commands/backup_support.rb', line 28

def call(**options)
  @backup_extension = options[:backup_extension] || DEFAULT_BACKUP_EXTENSION
  super
end