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.
- #password ⇒ Object
- #url(path = nil, params = nil) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(upstream, user_agent: nil) ⇒ Upstream
Returns a new instance of Upstream.
16 17 18 19 20 21 22 |
# File 'lib/gemstash/upstream.rb', line 16 def initialize(upstream, user_agent: nil) url = CGI.unescape(upstream.to_s) url = "https://#{url}" unless %r{^https?://}.match?(url) @uri = URI(url) @user_agent = user_agent raise "URL '#{@uri}' is not valid!" unless @uri.to_s&.match?(URI::DEFAULT_PARSER.make_regexp) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/gemstash/upstream.rb', line 12 def uri @uri end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
12 13 14 |
# File 'lib/gemstash/upstream.rb', line 12 def user_agent @user_agent end |
Instance Method Details
#auth? ⇒ Boolean
36 37 38 |
# File 'lib/gemstash/upstream.rb', line 36 def auth? !user.to_s.empty? || !password.to_s.empty? end |
#host_id ⇒ Object
Utilized as the parent directory for cached gems
41 42 43 |
# File 'lib/gemstash/upstream.rb', line 41 def host_id @host_id ||= "#{host}_#{hash}" end |
#password ⇒ Object
49 50 51 |
# File 'lib/gemstash/upstream.rb', line 49 def password env_auth_pass || @uri.password end |
#url(path = nil, params = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gemstash/upstream.rb', line 24 def url(path = nil, params = nil) base = to_s unless path.to_s.empty? base = "#{base}/" unless base.end_with?("/") path = path[1..] if path.to_s.start_with?("/") end params = "?#{params}" if !params.nil? && !params.empty? "#{base}#{path}#{params}" end |
#user ⇒ Object
45 46 47 |
# File 'lib/gemstash/upstream.rb', line 45 def user env_auth_user || @uri.user end |