Sha256: 9e70c11e72d2642e91bf710fbb7803d0f361462088c3816c5c4d04d51496d11c

Contents?: true

Size: 626 Bytes

Versions: 10

Compression:

Stored size: 626 Bytes

Contents

module Astrails
  module Safe
    class Sink < Stream

      def run
        if active?
          save
          cleanup
        else
          @parent.run
        end
      end

      protected

      # prefix is defined in subclass
      def path
        @path ||= File.join(prefix, filename)
      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

10 entries across 10 versions & 4 rubygems

Version Path
astrails-safe-0.1.1 lib/astrails/safe/sink.rb
astrails-safe-0.1.2 lib/astrails/safe/sink.rb
astrails-safe-0.1.3 lib/astrails/safe/sink.rb
astrails-safe-0.1.4 lib/astrails/safe/sink.rb
astrails-safe-0.1.6 lib/astrails/safe/sink.rb
colin-safe-0.1.6 lib/astrails/safe/sink.rb
colin-safe-0.1.7 lib/astrails/safe/sink.rb
colin-safe-0.1.8 lib/astrails/safe/sink.rb
markmansour-safe-0.1.7 lib/astrails/safe/sink.rb
ralph-safe-0.1.7 lib/astrails/safe/sink.rb