Sha256: 92286fecf55f6578ccff387b712c25f7de72e04572ddf52398b041574d9106b0

Contents?: true

Size: 1.56 KB

Versions: 13

Compression:

Stored size: 1.56 KB

Contents

module Backup
  module Syncer
    class Base
      include Utilities::Helpers
      include Config::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

      attr_reader :excludes

      def initialize(syncer_id = nil)
        @syncer_id = syncer_id

        load_defaults!

        @mirror ||= false
        @directories ||= []
        @excludes ||= []
      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

      # For Cloud Syncers, +pattern+ can be a string (with shell-style
      # wildcards) or a regex.
      # For RSync, each +pattern+ will be passed to rsync's --exclude option.
      def exclude(pattern)
        excludes << pattern
      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

13 entries across 13 versions & 4 rubygems

Version Path
backup-5.0.0.beta.3 lib/backup/syncer/base.rb
backedup-5.0.0.beta.5 lib/backup/syncer/base.rb
backedup-5.0.0.beta.4 lib/backup/syncer/base.rb
backedup-5.0.0.beta.3 lib/backup/syncer/base.rb
ext_backup-5.0.0.beta.2.1 lib/backup/syncer/base.rb
ext_backup-5.0.0.beta.2.ext.0.1.2 lib/backup/syncer/base.rb
ext_backup-5.0.0.beta.2.ext.0.1.1 lib/backup/syncer/base.rb
ext_backup-5.0.0.beta.2.ext.0.1.0 lib/backup/syncer/base.rb
backup-5.0.0.beta.2 lib/backup/syncer/base.rb
backup-5.0.0.beta.1 lib/backup/syncer/base.rb
backup-bouchard-4.4.4 lib/backup/syncer/base.rb
backup-bouchard-4.4.2 lib/backup/syncer/base.rb
backup-bouchard-4.4.1 lib/backup/syncer/base.rb