Class: Jaxx::Upload
- Inherits:
-
Object
- Object
- Jaxx::Upload
- Defined in:
- lib/jaxx/upload.rb
Constant Summary collapse
- DEFAULT_RETRIES =
3
Instance Attribute Summary collapse
-
#process ⇒ Object
readonly
Returns the value of attribute process.
-
#retries ⇒ Object
readonly
Returns the value of attribute retries.
Instance Method Summary collapse
- #execute ⇒ Object
- #filename ⇒ Object
- #files ⇒ Object
-
#initialize(args = {}) ⇒ Upload
constructor
A new instance of Upload.
Constructor Details
#initialize(args = {}) ⇒ Upload
Returns a new instance of Upload.
11 12 13 14 15 |
# File 'lib/jaxx/upload.rb', line 11 def initialize args = {} @process = Process.new(args.merge('validations' => [:privacy, :file_exists, :file_presence])) @filename = args['filename'] @retries = args['retries'] || DEFAULT_RETRIES end |
Instance Attribute Details
#process ⇒ Object (readonly)
Returns the value of attribute process.
9 10 11 |
# File 'lib/jaxx/upload.rb', line 9 def process @process end |
#retries ⇒ Object (readonly)
Returns the value of attribute retries.
9 10 11 |
# File 'lib/jaxx/upload.rb', line 9 def retries @retries end |
Instance Method Details
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jaxx/upload.rb', line 29 def execute process.start do |storage| dir, attempts = remote_directory(storage), 0 files.each do |file, name| stat, exc = false, nil attempts += 1 begin stat = create_file dir, file, name rescue => ex exc = ex end if !stat and attempts >= self.retries raise("File process failed: #{file}:#{name} : #{exc. rescue nil}") elsif !stat redo end attempts = 0 end end end |
#filename ⇒ Object
17 18 19 |
# File 'lib/jaxx/upload.rb', line 17 def filename @filename || File.basename(process.file) end |
#files ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/jaxx/upload.rb', line 21 def files if File.directory?(process.file) Dir[File.join(process.file, "**", "*")].reject{|fp| File.directory?(fp) }.inject({}) {|hsh, fp| hsh[fp] = fp.gsub(process.file, ''); hsh } else { process.file => filename } end end |