Class: PDK::Util::VendoredFile
- Inherits:
-
Object
- Object
- PDK::Util::VendoredFile
- Defined in:
- lib/pdk/util/vendored_file.rb
Defined Under Namespace
Classes: DownloadError
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(file_name, url) ⇒ VendoredFile
constructor
A new instance of VendoredFile.
- #read ⇒ Object
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_name ⇒ Object (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 |
#url ⇒ Object (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
#read ⇒ Object
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 |