Class: Lifter::FileUpload
- Inherits:
-
Object
- Object
- Lifter::FileUpload
- Defined in:
- lib/lifter/file_upload.rb
Constant Summary collapse
- DEFAULT_PROLOGUE_SIZE =
10 * 1024
Instance Attribute Summary collapse
-
#original_name ⇒ Object
readonly
Returns the value of attribute original_name.
-
#original_request ⇒ Object
readonly
Returns the value of attribute original_request.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#prologue ⇒ Object
readonly
Returns the value of attribute prologue.
Instance Method Summary collapse
- #authorize ⇒ Object
- #authorized? ⇒ Boolean
- #close ⇒ Object
- #flush ⇒ Object
- #full_path ⇒ Object
- #hash ⇒ Object
-
#initialize(file, opts = {}) ⇒ FileUpload
constructor
A new instance of FileUpload.
- #mv(new_path) ⇒ Object
- #pending_authorization ⇒ Object
- #pending_authorization? ⇒ Boolean
- #rm ⇒ Object
- #write(data) ⇒ Object
Constructor Details
permalink #initialize(file, opts = {}) ⇒ FileUpload
Returns a new instance of FileUpload.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lifter/file_upload.rb', line 12 def initialize(file, opts = {}) @mutex = Mutex.new @file = file @path = file.path @authorized = false @pending_authorization = false @hash = setup_hash(opts[:hash_method]) @prologue_limit = opts[:prologue_size] || DEFAULT_PROLOGUE_SIZE @prologue = '' @original_request = opts[:original_request] @original_name = opts[:original_name] @param = opts[:param] end |
Instance Attribute Details
permalink #original_name ⇒ Object (readonly)
Returns the value of attribute original_name.
10 11 12 |
# File 'lib/lifter/file_upload.rb', line 10 def original_name @original_name end |
permalink #original_request ⇒ Object (readonly)
Returns the value of attribute original_request.
10 11 12 |
# File 'lib/lifter/file_upload.rb', line 10 def original_request @original_request end |
permalink #param ⇒ Object (readonly)
Returns the value of attribute param.
10 11 12 |
# File 'lib/lifter/file_upload.rb', line 10 def param @param end |
permalink #prologue ⇒ Object (readonly)
Returns the value of attribute prologue.
10 11 12 |
# File 'lib/lifter/file_upload.rb', line 10 def prologue @prologue end |
Instance Method Details
permalink #authorize ⇒ Object
[View source]
67 68 69 70 71 |
# File 'lib/lifter/file_upload.rb', line 67 def @mutex.synchronize do @authorized = true end end |
permalink #authorized? ⇒ Boolean
89 90 91 92 93 94 95 96 97 |
# File 'lib/lifter/file_upload.rb', line 89 def = false @mutex.synchronize do = @authorized == true end end |
permalink #close ⇒ Object
[View source]
45 46 47 |
# File 'lib/lifter/file_upload.rb', line 45 def close @file.close if !@file.closed? end |
permalink #flush ⇒ Object
[View source]
41 42 43 |
# File 'lib/lifter/file_upload.rb', line 41 def flush @file.flush end |
permalink #full_path ⇒ Object
[View source]
59 60 61 |
# File 'lib/lifter/file_upload.rb', line 59 def full_path File.(@path) end |
permalink #hash ⇒ Object
[View source]
63 64 65 |
# File 'lib/lifter/file_upload.rb', line 63 def hash @hash.hexdigest end |
permalink #mv(new_path) ⇒ Object
[View source]
54 55 56 57 |
# File 'lib/lifter/file_upload.rb', line 54 def mv(new_path) FileUtils.mv(full_path, new_path) @path = new_path end |
permalink #pending_authorization ⇒ Object
[View source]
73 74 75 76 77 |
# File 'lib/lifter/file_upload.rb', line 73 def @mutex.synchronize do @pending_authorization = true end end |
permalink #pending_authorization? ⇒ Boolean
79 80 81 82 83 84 85 86 87 |
# File 'lib/lifter/file_upload.rb', line 79 def pending = false @mutex.synchronize do pending = @pending_authorization == true end pending end |
permalink #rm ⇒ Object
[View source]
49 50 51 52 |
# File 'lib/lifter/file_upload.rb', line 49 def rm FileUtils.rm(full_path) @path = nil end |
permalink #write(data) ⇒ Object
[View source]
31 32 33 34 35 36 37 38 39 |
# File 'lib/lifter/file_upload.rb', line 31 def write(data) @file.write(data) @hash << data if @prologue.length < @prologue_limit @prologue << data[0, @prologue_limit - @prologue.length] end end |