Sha256: 4b2d2abd436fb233cad8d746d5dafb0682d58e8304fc58b643a8de23d5e01ec9

Contents?: true

Size: 911 Bytes

Versions: 6

Compression:

Stored size: 911 Bytes

Contents

module Astrails
  module Safe
    class Sink < Stream

      def process
        return unless active?

        save
        cleanup
      end

      protected

      # path is defined in subclass
      # base is used in 'cleanup' to find all files that begin with base. the '.'
      # at the end is essential to distinguish b/w foo.* and foobar.* archives for example
      def base
        @base ||= File.join(path, File.basename(@backup.filename).split(".").first + '.')
      end

      def full_path
        @full_path ||= File.join(path, @backup.filename) + @backup.extension
      end

      # call block on files to be removed (all except for the LAST 'limit' files
      def cleanup_with_limit(files, limit, &block)
        return unless files.size > limit

        to_remove = files[0..(files.size - limit - 1)]
        # TODO: validate here
        to_remove.each(&block)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
akupchanko-astrails-safe-0.3.1 lib/astrails/safe/sink.rb
astrails-safe-0.3.1 lib/astrails/safe/sink.rb
astrails-safe-0.3.0 lib/astrails/safe/sink.rb
netguru-safe-0.2.11 lib/astrails/safe/sink.rb
netguru-safe-0.2.10 lib/astrails/safe/sink.rb
netguru-safe-0.2.9 lib/astrails/safe/sink.rb