Class: Gemstash::Upstream

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gemstash/upstream.rb

Overview

:nodoc:

Defined Under Namespace

Classes: GemName

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upstream, user_agent: nil) ⇒ Upstream



12
13
14
15
16
# File 'lib/gemstash/upstream.rb', line 12

def initialize(upstream, user_agent: nil)
  @uri = URI(URI.decode(upstream.to_s))
  @user_agent = user_agent
  raise "URL '#{@uri}' is not valid!" unless @uri.to_s =~ URI.regexp
end

Instance Attribute Details

#user_agentObject (readonly)

Returns the value of attribute user_agent.



8
9
10
# File 'lib/gemstash/upstream.rb', line 8

def user_agent
  @user_agent
end

Instance Method Details

#auth?Boolean



30
31
32
# File 'lib/gemstash/upstream.rb', line 30

def auth?
  !user.to_s.empty? && !password.to_s.empty?
end

#host_idObject

Utilized as the parent directory for cached gems



35
36
37
# File 'lib/gemstash/upstream.rb', line 35

def host_id
  @host_id ||= "#{host}_#{hash}"
end

#url(path = nil, params = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gemstash/upstream.rb', line 18

def url(path = nil, params = nil)
  base = to_s

  unless path.to_s.empty?
    base = "#{base}/" unless base.end_with?("/")
    path = path[1..-1] if path.to_s.start_with?("/")
  end

  params = "?#{params}" if !params.nil? && !params.empty?
  "#{base}#{path}#{params}"
end