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.



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

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.



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

def file_name
  @file_name
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#readObject



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

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