class Gemstash::GemSource::UpstreamSource
GemSource
for gems in an upstream server.
Public Class Methods
rack_env_rewriter()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 119 def self.rack_env_rewriter @rack_env_rewriter ||= Gemstash::RackEnvRewriter.new(%r{\A/upstream/(?<upstream_url>[^/]+)}) end
Public Instance Methods
serve_gem(id)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 127 def serve_gem(id) serve_cached(id, :gem) end
serve_latest_specs()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 131 def serve_latest_specs http_client = http_client_for(upstream) http_client.get("latest_specs.4.8.gz") end
serve_marshal(id)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 123 def serve_marshal(id) serve_cached(id, :spec) end
serve_prerelease_specs()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 136 def serve_prerelease_specs http_client = http_client_for(upstream) http_client.get("prerelease_specs.4.8.gz") end
serve_specs()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 141 def serve_specs http_client = http_client_for(upstream) http_client.get("specs.4.8.gz") end
Private Instance Methods
dependencies()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 165 def dependencies @dependencies ||= begin http_client = http_client_for(upstream) Gemstash::Dependencies.for_upstream(upstream, http_client) end end
fetch_gem(id, resource_type)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 181 def fetch_gem(id, resource_type) gem_name = Gemstash::Upstream::GemName.new(upstream, id) gem_resource = storage.resource(gem_name.name) if gem_resource.exist?(resource_type) fetch_local_gem(gem_name, gem_resource, resource_type) else fetch_remote_gem(gem_name, gem_resource, resource_type) end end
fetch_local_gem(gem_name, gem_resource, resource_type)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 191 def fetch_local_gem(gem_name, gem_resource, resource_type) log.info "Gem #{gem_name.name} exists, returning cached #{resource_type}" gem_resource end
fetch_remote_gem(gem_name, gem_resource, resource_type)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 196 def fetch_remote_gem(gem_name, gem_resource, resource_type) log.info "Gem #{gem_name.name} is not cached, fetching #{resource_type}" gem_fetcher.fetch(gem_name.id, resource_type) do |content, properties| resource_properties = { upstream: upstream.to_s, gem_name: gem_name.name, headers: { resource_type => properties } } gem = gem_resource.save({ resource_type => content }, resource_properties) Gemstash::DB::CachedRubygem.store(upstream, gem_name, resource_type) gem end end
gem_fetcher()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 177 def gem_fetcher @gem_fetcher ||= Gemstash::GemFetcher.new(http_client_for(upstream)) end
serve_cached(id, resource_type)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 148 def serve_cached(id, resource_type) gem = fetch_gem(id, resource_type) set_gem_headers(gem, resource_type) gem.content(resource_type) rescue Gemstash::WebError => e halt e.code end
set_gem_headers(gem, resource_type)
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 156 def set_gem_headers(gem, resource_type) return unless gem.property?(:headers, resource_type) gem_headers = gem.properties[:headers][resource_type] headers["Content-Type"] = gem_headers["content-type"] if gem_headers.include?("content-type") headers["Last-Modified"] = gem_headers["last-modified"] if gem_headers.include?("last-modified") headers["ETag"] = gem_headers["etag"] if gem_headers.include?("etag") end
storage()
click to toggle source
# File lib/gemstash/gem_source/upstream_source.rb, line 172 def storage @storage ||= Gemstash::Storage.for("gem_cache") @storage.for(upstream.host_id) end