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

Returns a new instance of Upstream.



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

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

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

Instance Method Details

#auth?Boolean

Returns:

  • (Boolean)


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

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

#host_idObject

Utilized as the parent directory for cached gems



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

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

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



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

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