Sha256: b039bd2b7b3cd08ed03e03626add7ab33ac8676f2a5dff309590a2beb9e2a080

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8

module Backup
  module Syncer
    class Base
      include Backup::Utilities::Helpers
      include Backup::Configuration::Helpers

      ##
      # Path to store the synced files/directories to
      attr_accessor :path

      ##
      # Flag for mirroring the files/directories
      attr_accessor :mirror

      ##
      # Optional user-defined identifier to differentiate multiple syncers
      # defined within a single backup model. Currently this is only used
      # in the log messages.
      attr_reader :syncer_id

      def initialize(syncer_id = nil)
        @syncer_id = syncer_id

        load_defaults!

        @path   ||= '~/backups'
        @mirror ||= false
        @directories = Array.new
      end

      ##
      # Syntactical suger for the DSL for adding directories
      def directories(&block)
        return @directories unless block_given?
        instance_eval(&block)
      end

      def add(path)
        directories << path
      end

      private

      def syncer_name
        @syncer_name ||= self.class.to_s.sub('Backup::', '') +
            (syncer_id ? " (#{ syncer_id })" : '')
      end

      def log!(action)
        msg = case action
              when :started then 'Started...'
              when :finished then 'Finished!'
              end
        Logger.info "#{ syncer_name } #{ msg }"
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
backup-3.6.0 lib/backup/syncer/base.rb
backup-3.5.1 lib/backup/syncer/base.rb
backup-3.5.0 lib/backup/syncer/base.rb
backup-3.4.0 lib/backup/syncer/base.rb
backup-3.3.2 lib/backup/syncer/base.rb
backup-3.3.1 lib/backup/syncer/base.rb
backup-3.3.0 lib/backup/syncer/base.rb
backup-3.2.0 lib/backup/syncer/base.rb