Class: PDK::Util::VendoredFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pdk/util/vendored_file.rb

Defined Under Namespace

Classes: DownloadError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, url) ⇒ VendoredFile

Returns a new instance of VendoredFile.



9
10
11
12
# File 'lib/pdk/util/vendored_file.rb', line 9

def initialize(file_name, url)
  @file_name = file_name
  @url = url
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



6
7
8
# File 'lib/pdk/util/vendored_file.rb', line 6

def file_name
  @file_name
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/pdk/util/vendored_file.rb', line 7

def url
  @url
end

Instance Method Details

#readObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pdk/util/vendored_file.rb', line 14

def read
  require 'pdk/util'
  require 'pdk/util/filesystem'

  return PDK::Util::Filesystem.read_file(package_vendored_path) if PDK::Util.package_install?
  return PDK::Util::Filesystem.read_file(gem_vendored_path) if PDK::Util::Filesystem.file?(gem_vendored_path)

  content = download_file

  # TODO: should only write if it's valid JSON
  # TODO: need a way to invalidate if out of date
  PDK::Util::Filesystem.mkdir_p(File.dirname(gem_vendored_path))
  PDK::Util::Filesystem.write_file(gem_vendored_path, content)
  content
end