Class: Miteru::Downloader
- Includes:
- MemoWise
- Defined in:
- lib/miteru/downloader.rb
Instance Attribute Summary collapse
- #base_dir ⇒ String readonly
- #kit ⇒ Miteru::Kit readonly
Instance Method Summary collapse
- #call ⇒ String
-
#initialize(kit, base_dir: Miteru.config.download_to) ⇒ Downloader
constructor
<Description>.
Methods inherited from Service
Constructor Details
#initialize(kit, base_dir: Miteru.config.download_to) ⇒ Downloader
<Description>
24 25 26 27 28 |
# File 'lib/miteru/downloader.rb', line 24 def initialize(kit, base_dir: Miteru.config.download_to) super() @kit = kit @base_dir = base_dir end |
Instance Attribute Details
#base_dir ⇒ String (readonly)
13 14 15 |
# File 'lib/miteru/downloader.rb', line 13 def base_dir @base_dir end |
Instance Method Details
#call ⇒ String
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/miteru/downloader.rb', line 33 def call destination = kit.filepath_to_download # downloader.download(kit.url, destination:, max_size:) downloader.download(kit.url, destination:, max_size:) unless Record.unique_sha256?(sha256(destination)) FileUtils.rm destination raise UniquenessError, "Kit:#{sha256(destination)} is registered already." end # Record a kit in DB Record.create_by_kit_and_hash(kit, sha256: sha256(destination)) logger.info "Download #{kit.url} as #{destination}" destination end |