Sha256: a80cb0f45105366df8c0d3f177c1669da071e693ae374565af2a6067b28c4404

Contents?: true

Size: 701 Bytes

Versions: 23

Compression:

Stored size: 701 Bytes

Contents

require 'zip'

module Trackler
  # FileBundle is a zippech archive of a directory.
  class FileBundle
    attr_reader :dir, :ignore_patterns
    def initialize(dir, ignore_patterns=[])
      @dir = dir
      @ignore_patterns = ignore_patterns
    end

    def zip
      Zip::OutputStream.write_buffer do |io|
        paths.each do |path|
          io.put_next_entry(path.relative_path_from(dir))
          io.print IO.read(path)
        end
        yield io if block_given?
      end
    end

    def paths
      Pathname.glob("#{dir}/**/*", File::FNM_DOTMATCH).reject {|file|
        file.directory? ||
          ignore_patterns.any? { |pattern| file.to_s =~ pattern }
      }.sort
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trackler-2.0.1.1 lib/trackler/file_bundle.rb
trackler-2.0.1.0 lib/trackler/file_bundle.rb
trackler-2.0.0.10 lib/trackler/file_bundle.rb
trackler-2.0.0.9 lib/trackler/file_bundle.rb
trackler-2.0.0.8 lib/trackler/file_bundle.rb
trackler-2.0.0.7 lib/trackler/file_bundle.rb
trackler-2.0.0.6 lib/trackler/file_bundle.rb
trackler-2.0.0.5 lib/trackler/file_bundle.rb
trackler-2.0.0.4 lib/trackler/file_bundle.rb
trackler-2.0.0.3 lib/trackler/file_bundle.rb
trackler-2.0.0.2 lib/trackler/file_bundle.rb
trackler-2.0.0.1 lib/trackler/file_bundle.rb
trackler-2.0.0.0 lib/trackler/file_bundle.rb
trackler-1.0.4.1 lib/trackler/file_bundle.rb
trackler-1.0.4.0 lib/trackler/file_bundle.rb
trackler-1.0.3.0 lib/trackler/file_bundle.rb
trackler-1.0.2.1 lib/trackler/file_bundle.rb
trackler-1.0.2.0 lib/trackler/file_bundle.rb
trackler-1.0.1.2 lib/trackler/file_bundle.rb
trackler-1.0.1.1 lib/trackler/file_bundle.rb