Class: AIPP::Downloader::File

Inherits:
Object
  • Object
show all
Defined in:
lib/aipp/downloader/file.rb

Overview

Local file

Direct Known Subclasses

GraphQL, HTTP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive: nil, file:, type: nil) ⇒ File

Returns a new instance of File.



8
9
10
11
# File 'lib/aipp/downloader/file.rb', line 8

def initialize(archive: nil, file:, type: nil)
  @archive = Pathname(archive) if archive
  @file, @type = Pathname(file), type&.to_s
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/aipp/downloader/file.rb', line 6

def file
  @file
end

Instance Method Details

#fetch_to(path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/aipp/downloader/file.rb', line 13

def fetch_to(path)
  path.join(fetched_file).tap do |target|
    if @archive
      fail NotFoundError unless @archive.exist?
      extract(file, from: @archive, as: target)
    else
      fail NotFoundError unless file.exist?
      FileUtils.cp(file, target)
    end
  end
  self
end

#fetched_fileObject



26
27
28
# File 'lib/aipp/downloader/file.rb', line 26

def fetched_file
  [name, type].join('.')
end