Sha256: 32770e02c10f04c1338bd4f44320ae5f032444abbbd7cc8a1eb83533c515bf17

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

module Riserva::Commands
  class Backup < ApplicationCommand
    attr_reader :uploaders

    def initialize
      super
      @uploaders = {}
    end

    def call
      create_archives
      push_to_cloud

      success? ? broadcast(:ok) : broadcast(:failed)
    end

    private

    def success?
      @uploaders.values.map { |uploader| uploader.files == archivator.files }.all?
    end

    def create_archives
      Riserva::Config.folders { |folder| archivator.call(folder) }
    end

    def archivator
      @archivator ||= Riserva::Commands::CreateArchive.new
    end

    def push_to_cloud
      Riserva::Config.storages do |storage|
        archivator.files.each { |file| upload_file(storage, file) }
      end
    end

    def upload_file(storage, file)
      uploader(storage).call(file)
    end

    def uploader(storage)
      @uploaders[storage.title] ||= Riserva::Commands::UploadFile.new(storage)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
riserva-0.1.1 lib/riserva/commands/backup.rb
riserva-0.1.0 lib/riserva/commands/backup.rb