Class: PDK::Util::VendoredFile
- Inherits:
-
Object
- Object
- PDK::Util::VendoredFile
- Includes:
- Filesystem
- Defined in:
- lib/pdk/util/vendored_file.rb
Defined Under Namespace
Classes: DownloadError
Constant Summary collapse
- HTTP_ERRORS =
[ EOFError, Errno::ECONNRESET, Errno::EINVAL, Errno::ECONNREFUSED, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Timeout::Error, ].freeze
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
Methods included from Filesystem
directory?, exist?, expand_path, file?, fnmatch, glob, mkdir_p, read_file, readable?, write_file
Constructor Details
#initialize(file_name, url) ⇒ VendoredFile
Returns a new instance of VendoredFile.
28 29 30 31 |
# File 'lib/pdk/util/vendored_file.rb', line 28 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.
23 24 25 |
# File 'lib/pdk/util/vendored_file.rb', line 23 def file_name @file_name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
24 25 26 |
# File 'lib/pdk/util/vendored_file.rb', line 24 def url @url end |
Instance Method Details
#read ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pdk/util/vendored_file.rb', line 33 def read return File.read(package_vendored_path) if PDK::Util.package_install? return File.read(gem_vendored_path) if File.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 FileUtils.mkdir_p(File.dirname(gem_vendored_path)) write_file(gem_vendored_path, content) content end |