Class: MasterDelivery::MasterDelivery
- Inherits:
-
Object
- Object
- MasterDelivery::MasterDelivery
- Defined in:
- lib/master_delivery.rb
Overview
File delivery class
-
Move the current active files to backup/
-
Place a symbolic link to the master (or copy of master) in the appropriate directory
Instance Attribute Summary collapse
-
#backup_root ⇒ Object
readonly
Returns the value of attribute backup_root.
Instance Method Summary collapse
- #confirm(basics, params) ⇒ Object
-
#deliver(basics, type: :symbolic_link, dryrun: false, verbose: false) ⇒ Object
note: Even if dryrun: true, @backup_dir is actually created! (for name-consistency).
-
#initialize(master_root, backup_root = '') ⇒ MasterDelivery
constructor
A new instance of MasterDelivery.
Constructor Details
#initialize(master_root, backup_root = '') ⇒ MasterDelivery
Returns a new instance of MasterDelivery.
30 31 32 33 34 35 36 37 |
# File 'lib/master_delivery.rb', line 30 def initialize(master_root, backup_root = '') @master_root = File.(master_root) @backup_root = if backup_root.nil? || backup_root.empty? File.(master_root + '/backup') else File.(backup_root) end end |
Instance Attribute Details
#backup_root ⇒ Object (readonly)
Returns the value of attribute backup_root.
27 28 29 |
# File 'lib/master_delivery.rb', line 27 def backup_root @backup_root end |
Instance Method Details
#confirm(basics, params) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/master_delivery.rb', line 76 def confirm(basics, params) unless params[:quiet] puts MSG_CONFIRMATION_INTRO unless params[:yes] print_params(basics, params.slice(:type, :dryrun)) print_sample(basics) end print MSG_CONFIRMATION.chomp unless params[:yes] # use print instead of puts for '\n' return true if params[:yes] || gets.chomp == 'y' puts 'aborted.' false end |
#deliver(basics, type: :symbolic_link, dryrun: false, verbose: false) ⇒ Object
note: Even if dryrun: true, @backup_dir is actually created! (for name-consistency)
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/master_delivery.rb', line 61 def deliver(basics, type: :symbolic_link, dryrun: false, verbose: false) FileUtils.mkdir_p(@backup_root) utils = dryrun ? FileUtils::DryRun : FileUtils backup_dir = Dir.mktmpdir("#{basics[:master_id]}-original-", @backup_root) puts "mkdir -p #{backup_dir}" if verbose mfiles = master_files(basics[:master_id]) mfiles.each do |master| tfile = move_to_backup(master, utils, basics, backup_dir, verbose) deliver_to_target(master, utils, tfile, type, verbose) end [mfiles, backup_dir] end |