class Batali::Origin::RemoteSite
Fetch unit information from remote site
Constants
- API_SUFFIX
Site suffix for API endpoint
Public Class Methods
new(*_)
click to toggle source
Calls superclass method
Batali::Origin::new
# File lib/batali/origin/remote_site.rb, line 23 def initialize(*_) super # NOTE: We currently don't require API_SUFFIX information # self.endpoint = URI.join(endpoint, API_SUFFIX).to_s self.identifier = Digest::SHA256.hexdigest(endpoint) unless name? self.name = identifier end end
Public Instance Methods
cache_directory()
click to toggle source
@return [String] cache directory path
# File lib/batali/origin/remote_site.rb, line 34 def cache_directory memoize(:cache_directory) do c_path = Utility.join_path(cache_path, "remote_site", identifier) FileUtils.mkdir_p(c_path) c_path end end
units()
click to toggle source
@return [Array<Unit>] all units
# File lib/batali/origin/remote_site.rb, line 43 def units memoize(:units) do items.map do |u_name, versions| versions.map do |version, info| Unit.new( :name => u_name, :version => version, :dependencies => info[:dependencies].to_a, :source => Smash.new( :type => :site, :url => info[:download_url], :version => version, :dependencies => info[:dependencies], :cache_path => cache_path, ), ) end end.flatten end end
Protected Instance Methods
fetch()
click to toggle source
Fetch the universe
@return [String] path to universe file
# File lib/batali/origin/remote_site.rb, line 76 def fetch do_fetch = true cache_directory # init directory creation if File.exist?(universe_path) age = Time.now - File.mtime(universe_path) if age < update_interval do_fetch = false end end if do_fetch t_uni = "#{universe_path}.#{SecureRandom.urlsafe_base64}" result = HTTP.get(URI.join(endpoint, "universe")) File.open(t_uni, "w") do |file| while content = result.body.readpartial(2048) file.write content end end FileUtils.mv(t_uni, universe_path) end universe_path end
items()
click to toggle source
@return [Smash] all info
# File lib/batali/origin/remote_site.rb, line 67 def items memoize(:items) do MultiJson.load(File.read(fetch)).to_smash end end
universe_path()
click to toggle source
@return [String] path to universe file
# File lib/batali/origin/remote_site.rb, line 99 def universe_path Utility.join_path(cache_directory, "universe.json") end