Sha256: b60a094d15b031de9b5d8a7d01430caca0798d94aa15f2facc47ea0dffa73c67

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require_relative 'performers/base_git'
require_relative 'backup_github'
require_relative 'backup_bitbucket'
require_relative 'backup_gitlab_endpoint'
require_relative 'backup_gitlab'

module BackupRepos
  class Backup
    attr_reader :errors

    def initialize
      @errors = []

      validate!
    end

    def process
      process_github
      process_bitbucket
      process_gitlab
    end

    def process_github
      return unless valid?
      BackupGithub.new.process
    end

    def process_bitbucket
      return unless valid?
      BackupBitbucket.new.process
    end

    def process_gitlab
      return unless valid?
      BackupGitlab.new.process
    end

    def valid?
      errors.blank?
    end

    private

    def validate!
      validate_backup_dir!
      inform_about_error! unless valid?
    end

    def validate_backup_dir!
      backup_root = BackupRepos.config.backup_root

      if backup_root.blank?
        errors.push('Backup directory is not specified.') && return
      end

      return if File.exist?(backup_root)
      errors << 'Backup directory does not exists.'
    end

    def inform_about_error!
      puts errors.first.red
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
backup_repos-0.3.0 lib/backup_repos/backup.rb
backup_repos-0.2.1 lib/backup_repos/backup.rb
backup_repos-0.2.0 lib/backup_repos/backup.rb