Class: Gitw::Git::URL
- Inherits:
-
Object
- Object
- Gitw::Git::URL
- Defined in:
- lib/gitw/git/url.rb
Overview
git repository url
Constant Summary collapse
- SSH_RE =
%r{ ^ (?:(?<user>[^@/]+)@)? (?<host>[^:/]+) :(?!/) (?<path>.*?) $ }x.freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#raw_url ⇒ Object
readonly
Returns the value of attribute raw_url.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(raw_url) ⇒ URL
constructor
A new instance of URL.
-
#parse ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- #path_basename ⇒ Object
-
#path_dirname ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
- #to_s ⇒ Object
Constructor Details
#initialize(raw_url) ⇒ URL
Returns a new instance of URL.
20 21 22 23 24 25 26 27 28 |
# File 'lib/gitw/git/url.rb', line 20 def initialize(raw_url) @raw_url = raw_url @url = nil @user = nil @host = nil @path = nil parse end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
18 19 20 |
# File 'lib/gitw/git/url.rb', line 18 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/gitw/git/url.rb', line 18 def path @path end |
#raw_url ⇒ Object (readonly)
Returns the value of attribute raw_url.
18 19 20 |
# File 'lib/gitw/git/url.rb', line 18 def raw_url @raw_url end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
18 19 20 |
# File 'lib/gitw/git/url.rb', line 18 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
18 19 20 |
# File 'lib/gitw/git/url.rb', line 18 def user @user end |
Instance Method Details
#parse ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitw/git/url.rb', line 31 def parse if (match = SSH_RE.match(raw_url)) @user = match[:user] @host = match[:host] @path = match[:path] @url = raw_url.clone elsif (uri = URI.parse(raw_url)) @user = uri.user @host = uri.host @path = uri.path @url = uri.to_s end @path = @path.chomp('.git').sub(%r{^/+}, '').sub(%r{/+$}, '') end |
#path_basename ⇒ Object
51 52 53 |
# File 'lib/gitw/git/url.rb', line 51 def path_basename File.basename(path) end |
#path_dirname ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
47 48 49 |
# File 'lib/gitw/git/url.rb', line 47 def path_dirname File.dirname(path) end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/gitw/git/url.rb', line 55 def to_s url.to_s end |