Class: Trackler::FileBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/trackler/file_bundle.rb

Overview

FileBundle is a zippech archive of a directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, ignore_patterns = []) ⇒ FileBundle

Returns a new instance of FileBundle.



7
8
9
10
# File 'lib/trackler/file_bundle.rb', line 7

def initialize(dir, ignore_patterns=[])
  @dir = dir
  @ignore_patterns = ignore_patterns
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/trackler/file_bundle.rb', line 6

def dir
  @dir
end

#ignore_patternsObject (readonly)

Returns the value of attribute ignore_patterns.



6
7
8
# File 'lib/trackler/file_bundle.rb', line 6

def ignore_patterns
  @ignore_patterns
end

Instance Method Details

#pathsObject



22
23
24
25
26
27
# File 'lib/trackler/file_bundle.rb', line 22

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

#zipObject



12
13
14
15
16
17
18
19
20
# File 'lib/trackler/file_bundle.rb', line 12

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