Class: GitInit::GitUrl
- Inherits:
-
Object
- Object
- GitInit::GitUrl
- Defined in:
- lib/git_init.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#path ⇒ Object
Returns the value of attribute path.
-
#proto ⇒ Object
Returns the value of attribute proto.
-
#type ⇒ Object
Returns the value of attribute type.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ GitUrl
constructor
A new instance of GitUrl.
- #url ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ GitUrl
Returns a new instance of GitUrl.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/git_init.rb', line 10 def initialize(opts={}) # convert url if needed if opts.is_a?(String) opts = GitUrl.parse_url(opts) end # set instance vars opts.each do |key, value| self.send("#{key}=".to_sym, value) end end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
8 9 10 |
# File 'lib/git_init.rb', line 8 def basename @basename end |
#domain ⇒ Object
Returns the value of attribute domain.
8 9 10 |
# File 'lib/git_init.rb', line 8 def domain @domain end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/git_init.rb', line 8 def path @path end |
#proto ⇒ Object
Returns the value of attribute proto.
8 9 10 |
# File 'lib/git_init.rb', line 8 def proto @proto end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/git_init.rb', line 8 def type @type end |
#user ⇒ Object
Returns the value of attribute user.
8 9 10 |
# File 'lib/git_init.rb', line 8 def user @user end |
Class Method Details
.detect_type(url) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/git_init.rb', line 71 def GitUrl.detect_type(url) # Simple git url return :git if (/^git:\/\//.match(url)) # http(s) return :http if (/^https?:\/\//.match(url)) # ssh return :ssh if (/:/.match(url)) raise "Unknown type of url #{url}" end |
.parse_url(url) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/git_init.rb', line 39 def GitUrl.parse_url(url) ret_val = {} # Detect type ret_val[:type] = detect_type(url) # Parse ssh url if ret_val[:type] == :ssh m = /^(([^@]+)@)?([^:]+):(.*\.git$)/.match(url) ret_val[:user] = m[2] ret_val[:domain] = m[3] ret_val[:path] = File.dirname(m[4]) ret_val[:basename] = File.basename(m[4]) elsif ret_val[:type] == :http m = /^(https?):\/\/([^\/]+)\/(.*\.git$)/.match(url) ret_val[:proto] = m[1] ret_val[:domain] = m[2] ret_val[:path] = File.dirname(m[3]) ret_val[:basename] = File.basename(m[3]) elsif ret_val[:type] == :git m = /^git:\/\/([^\/]+)\/(.*\.git$)/.match(url) ret_val[:domain] = m[1] ret_val[:path] = File.dirname(m[2]) ret_val[:basename] = File.basename(m[2]) end return ret_val end |
Instance Method Details
#url ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/git_init.rb', line 23 def url if type == :http "#{self.proto}://#{self.domain}/#{File.join(self.path,self.basename)}" elsif type == :ssh if self.user.nil? user = "" else user = "#{self.user}@" end "#{user}#{self.domain}:#{File.join(self.path,self.basename)}" elsif type == :git "git://#{self.domain}/#{File.join(self.path,self.basename)}" end end |