class Riserva::Commands::CreateArchive
Public Instance Methods
call(path)
click to toggle source
Calls superclass method
Riserva::Commands::ApplicationCommand#call
# File lib/riserva/commands/create_archive.rb, line 3 def call(path) broadcast(:start, "folder: #{path}") return broadcast(:invalid, "`#{@path}` is not a directory") unless super file = archive_name create_archive(file) ? broadcast(:ok, file) : broadcast(:failed) end
Private Instance Methods
archive_location()
click to toggle source
# File lib/riserva/commands/create_archive.rb, line 28 def archive_location location = Pathname.new(Riserva::Config.read('storage_location')) location.mkpath unless location.exist? location end
archive_name()
click to toggle source
# File lib/riserva/commands/create_archive.rb, line 21 def archive_name time_prefix = Time.now.getlocal.strftime('%Y%m%d_%H%M') filename = @path.basename.to_s.downcase File.join(archive_location, "#{time_prefix}_#{filename}.tar.bz2") end
create_archive(file)
click to toggle source
# File lib/riserva/commands/create_archive.rb, line 17 def create_archive(file) system("tar cjf #{file} -C #{@path.parent} #{@path.basename}") end
valid?()
click to toggle source
# File lib/riserva/commands/create_archive.rb, line 13 def valid? @path.directory? end