class Batali::Source::Site
Site
based source
Attributes
cache[RW]
@return [String] local cache path
dependencies[R]
@return [Array<Hash>] dependency strings
version[R]
@return [String] version
Public Class Methods
new(args = {})
click to toggle source
Extract extra info before allowing super to load data
@param args [Hash] @return [self]
Calls superclass method
Batali::Source::new
# File lib/batali/source/site.rb, line 27 def initialize(args = {}) @deps = args.delete(:dependencies) || {} super end
Public Instance Methods
asset()
click to toggle source
@return [String] directory
# File lib/batali/source/site.rb, line 51 def asset path = Utility.join_path(cache_directory, Base64.urlsafe_encode64(url)) if File.directory?(path) discovered_path = Dir.glob(Utility.join_path(path, "*")).reject do |i| i.end_with?("#{File::SEPARATOR}asset") end.first FileUtils.rm_rf(path) end unless discovered_path retried = false begin FileUtils.mkdir_p(path) result = HTTP.get(url.end_with?("/") ? url : url + "/") while result.code == 302 result = HTTP.get(result.headers["Location"]) end File.open(a_path = Utility.join_path(path, "asset"), "wb") do |file| while content = result.body.readpartial(2048) file.write content end end ext = Gem::Package::TarReader.new( Zlib::GzipReader.open(a_path) ) ext.rewind ext.each do |entry| next unless entry.file? n_path = Utility.join_path(path, entry.full_name) FileUtils.mkdir_p(File.dirname(n_path)) File.open(n_path, "wb") do |file| while content = entry.read(2048) file.write(content) end end end begin FileUtils.rm(a_path) rescue Errno::EACCES # windows is dumb some times end rescue => e FileUtils.rm_rf(path) unless retried FileUtils.mkdir_p(path) retried = true retry end raise end discovered_path = Dir.glob(Utility.join_path(path, "*")).reject do |i| i.end_with?("#{File::SEPARATOR}asset") end.first end unless discovered_path raise Errno::ENOENT.new "Failed to locate asset within `#{path}`" end discovered_path end
cache_directory()
click to toggle source
@return [String] path to cache
# File lib/batali/source/site.rb, line 43 def cache_directory memoize(:cache_directory) do @cache ||= Utility.join_path(cache_path, "remote_site") cache end end
clean_asset(asset_path)
click to toggle source
@return [TrueClass, FalseClass]
Calls superclass method
Batali::Source#clean_asset
# File lib/batali/source/site.rb, line 111 def clean_asset(asset_path) if asset_path super File.dirname(asset_path) else false end end
unit_dependencies()
click to toggle source
@return [Array<Array<name, constraints>>]
# File lib/batali/source/site.rb, line 38 def unit_dependencies deps.to_a end
unit_version()
click to toggle source
@return [String]
# File lib/batali/source/site.rb, line 33 def unit_version version end