Class: Shoes::Download
- Inherits:
-
Object
- Object
- Shoes::Download
- Defined in:
- shoes-core/lib/shoes/download.rb
Constant Summary collapse
- UPDATE_STEPS =
100
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#gui ⇒ Object
readonly
Returns the value of attribute gui.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#transferred ⇒ Object
readonly
Returns the value of attribute transferred.
Instance Method Summary collapse
- #abort ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(app, _parent, url, opts = {}, &blk) ⇒ Download
constructor
A new instance of Download.
- #initialize_blocks(app, blk) ⇒ Object
-
#join_thread ⇒ Object
needed for the specs (jay multi threading and specs).
-
#length ⇒ Object
shoes 3 compatibility.
- #percent ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
Constructor Details
#initialize(app, _parent, url, opts = {}, &blk) ⇒ Download
Returns a new instance of Download.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'shoes-core/lib/shoes/download.rb', line 19 def initialize(app, _parent, url, opts = {}, &blk) @app = app @url = url @opts = opts @body = opts[:body] @headers = opts[:headers] || {} @method = opts[:method] || "GET" initialize_blocks(app, blk) @gui = Shoes.backend_for(self) @response = HttpResponse.new @finished = false @transferred = 0 @content_length = 1 # non zero initialized to avoid Zero Div Errors end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
15 16 17 |
# File 'shoes-core/lib/shoes/download.rb', line 15 def app @app end |
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
15 16 17 |
# File 'shoes-core/lib/shoes/download.rb', line 15 def content_length @content_length end |
#gui ⇒ Object (readonly)
Returns the value of attribute gui.
15 16 17 |
# File 'shoes-core/lib/shoes/download.rb', line 15 def gui @gui end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
15 16 17 |
# File 'shoes-core/lib/shoes/download.rb', line 15 def progress @progress end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
15 16 17 |
# File 'shoes-core/lib/shoes/download.rb', line 15 def response @response end |
#transferred ⇒ Object (readonly)
Returns the value of attribute transferred.
15 16 17 |
# File 'shoes-core/lib/shoes/download.rb', line 15 def transferred @transferred end |
Instance Method Details
#abort ⇒ Object
68 69 70 |
# File 'shoes-core/lib/shoes/download.rb', line 68 def abort @thread&.exit end |
#finished? ⇒ Boolean
54 55 56 |
# File 'shoes-core/lib/shoes/download.rb', line 54 def finished? @finished end |
#initialize_blocks(app, blk) ⇒ Object
38 39 40 41 42 43 44 |
# File 'shoes-core/lib/shoes/download.rb', line 38 def initialize_blocks(app, blk) slot = app.current_slot @blk = slot.create_bound_block(blk) @progress_blk = slot.create_bound_block(@opts[:progress]) @finish_blk = slot.create_bound_block(@opts[:finish]) @error_blk = slot.create_bound_block(@opts[:error] || default_error_proc) end |
#join_thread ⇒ Object
needed for the specs (jay multi threading and specs)
59 60 61 |
# File 'shoes-core/lib/shoes/download.rb', line 59 def join_thread @thread&.join end |
#length ⇒ Object
shoes 3 compatibility
73 74 75 |
# File 'shoes-core/lib/shoes/download.rb', line 73 def length @content_length end |
#percent ⇒ Object
63 64 65 66 |
# File 'shoes-core/lib/shoes/download.rb', line 63 def percent return 0 if @transferred.nil? || @content_length.nil? @transferred * 100 / @content_length end |
#start ⇒ Object
46 47 48 |
# File 'shoes-core/lib/shoes/download.rb', line 46 def start start_download end |
#started? ⇒ Boolean
50 51 52 |
# File 'shoes-core/lib/shoes/download.rb', line 50 def started? @started end |