Class: Jaxx::Download
- Inherits:
-
Object
- Object
- Jaxx::Download
- Defined in:
- lib/jaxx/download.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Instance Method Summary collapse
- #execute ⇒ Object
- #files(directory) ⇒ Object
-
#initialize(args = {}) ⇒ Download
constructor
A new instance of Download.
Constructor Details
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/jaxx/download.rb', line 7 def filename @filename end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
7 8 9 |
# File 'lib/jaxx/download.rb', line 7 def process @process end |
Instance Method Details
#execute ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jaxx/download.rb', line 25 def execute process.start do |storage| directory = storage.directories.get(process.bucket) files(directory).each do |target, source| # Ensure directory exists dir = File.dirname(target) FileUtils.mkdir_p(dir) unless File.exist?(dir) # Create file File.open(target, 'wb') do |file| directory.files.get(source) {|chunk, byt_remain, byt_total| file.write(chunk) } end end end end |
#files(directory) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jaxx/download.rb', line 13 def files(directory) if process.file.match(%r{/$}) directory.files.inject({}) do |hsh, f| key = f.key.gsub(process.file, '') hsh[key] = f.key if !key.empty? and f.key.match(process.file) hsh end else { File.basename(process.file) => process.file } end end |