Class: Trackler::FileBundle
- Inherits:
-
Object
- Object
- Trackler::FileBundle
- Defined in:
- lib/trackler/file_bundle.rb
Overview
FileBundle is a zippech archive of a directory.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#ignore_patterns ⇒ Object
readonly
Returns the value of attribute ignore_patterns.
Instance Method Summary collapse
-
#initialize(dir, ignore_patterns = []) ⇒ FileBundle
constructor
A new instance of FileBundle.
- #paths ⇒ Object
- #zip ⇒ Object
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
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/trackler/file_bundle.rb', line 6 def dir @dir end |
#ignore_patterns ⇒ Object (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
#paths ⇒ Object
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 |
#zip ⇒ Object
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 |