Class: Gemstash::Upstream
- Inherits:
-
Object
- Object
- Gemstash::Upstream
- Extended by:
- Forwardable
- Defined in:
- lib/gemstash/upstream.rb
Overview
:nodoc:
Defined Under Namespace
Classes: GemName
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #auth? ⇒ Boolean
-
#host_id ⇒ Object
Utilized as the parent directory for cached gems.
-
#initialize(upstream, user_agent: nil) ⇒ Upstream
constructor
A new instance of Upstream.
- #url(path = nil, params = nil) ⇒ Object
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(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
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/gemstash/upstream.rb', line 9 def uri @uri end |
#user_agent ⇒ Object (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
31 32 33 |
# File 'lib/gemstash/upstream.rb', line 31 def auth? !user.to_s.empty? && !password.to_s.empty? end |
#host_id ⇒ Object
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 |