Sha256: 6321879794aa04c1d32e9db691bb3498beef06d31f72d359dded62189b41a2f0

Contents?: true

Size: 1.59 KB

Versions: 44

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8

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

44 entries across 44 versions & 6 rubygems

Version Path
backup-ssh-4.4.5 lib/backup/syncer/base.rb
backup-remote-0.0.19 lib/backup/syncer/base.rb
cm-backup-1.0.0 lib/backup/syncer/base.rb
backup-ssh-4.4.4 lib/backup/syncer/base.rb
backup-ssh-4.4.3 lib/backup/syncer/base.rb
backup-4.4.1 lib/backup/syncer/base.rb
backup-remote-0.0.18 lib/backup/syncer/base.rb
backup-remote-0.0.17 lib/backup/syncer/base.rb
backup-remote-0.0.16 lib/backup/syncer/base.rb
backup-remote-0.0.15 lib/backup/syncer/base.rb
backup-ssh-4.4.2 lib/backup/syncer/base.rb
backup-ssh-4.4.1 lib/backup/syncer/base.rb
backup-remote-0.0.14 lib/backup/syncer/base.rb
backup-remote-0.0.13 lib/backup/syncer/base.rb
backup-remote-0.0.12 lib/backup/syncer/base.rb
backup-remote-0.0.11 lib/backup/syncer/base.rb
backup-ssh-4.4.0 lib/backup/syncer/base.rb
backup-remote-0.0.10 lib/backup/syncer/base.rb
backup-remote-0.0.9 lib/backup/syncer/base.rb
backup-remote-0.0.8 lib/backup/syncer/base.rb