Class: Factorix::Progress::DownloadHandler
- Inherits:
-
Object
- Object
- Factorix::Progress::DownloadHandler
- Defined in:
- lib/factorix/progress/download_handler.rb
Overview
Download event handler for progress presenters
This class listens to download events and updates a progress presenter accordingly.
Instance Method Summary collapse
-
#initialize(presenter) ⇒ DownloadHandler
constructor
Create a new download handler.
-
#on_cache_hit(event) ⇒ void
Handle cache hit event.
-
#on_download_completed(_event) ⇒ void
Handle download completed event.
-
#on_download_progress(event) ⇒ void
Handle download progress event.
-
#on_download_started(event) ⇒ void
Handle download started event.
Constructor Details
#initialize(presenter) ⇒ DownloadHandler
Create a new download handler
12 |
# File 'lib/factorix/progress/download_handler.rb', line 12 def initialize(presenter) = @presenter = presenter |
Instance Method Details
#on_cache_hit(event) ⇒ void
This method returns an undefined value.
Handle cache hit event
36 37 38 39 40 41 42 43 |
# File 'lib/factorix/progress/download_handler.rb', line 36 def on_cache_hit(event) total_size = event.payload.fetch(:total_size, 1) # Start and complete immediately for cache hits @presenter.start(total: total_size) @presenter.update(total_size) @presenter.finish end |
#on_download_completed(_event) ⇒ void
This method returns an undefined value.
Handle download completed event
30 |
# File 'lib/factorix/progress/download_handler.rb', line 30 def on_download_completed(_event) = @presenter.finish |
#on_download_progress(event) ⇒ void
This method returns an undefined value.
Handle download progress event
24 |
# File 'lib/factorix/progress/download_handler.rb', line 24 def on_download_progress(event) = @presenter.update(event[:current_size]) |
#on_download_started(event) ⇒ void
This method returns an undefined value.
Handle download started event
18 |
# File 'lib/factorix/progress/download_handler.rb', line 18 def on_download_started(event) = @presenter.start(total: event[:total_size]) |