uri-ssh_git 0.0.1.beta2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7fa74c73b9f837e7aaa86a6af6c593dae1b1f22
4
- data.tar.gz: 0b7412691d2758a22fe673d593341cf1d94247c7
3
+ metadata.gz: bf15234171b7d56ec1ad9aa16c3f84b8105f3835
4
+ data.tar.gz: 4136f25e2bbdb61a3425c8a02683985e3ab97df1
5
5
  SHA512:
6
- metadata.gz: 48d0c1136c1a59a42315613b852a91b2157f51167b32f78ed73a7915ccf3dd806e7e34db34cc3bb3150bb277ca4150c020c9a595b75fb13212e18baf12f17277
7
- data.tar.gz: 4f6af63e71bc027b4d12a27b4612cdd1e6bf9c61d1e156da625a67c7402285b89500438073800e33eaa6e154f94df58ceccc3f0afc1a4a40f2c8b6e1686816d2
6
+ metadata.gz: b01aa99f01f4ab2fec262e28f4cf5aba37134e698a7b59d8fb09fbe77ab9acf763c26fcfc364e5a3994f05911b93b20e4d7511b64ca3e9764ad436d842bef4db
7
+ data.tar.gz: 12d17d7a7c69c4664a66f0e8c73e265cf0eac6955c1466764363aed88370ce3314ece084d2b040d281562eaca2841d6bfb428b6abb594029052b5938c3472016
data/README.md CHANGED
@@ -3,9 +3,50 @@
3
3
  [![Gem Version](http://img.shields.io/gem/v/uri-ssh_git.svg?style=flat)](http://badge.fury.io/rb/uri-ssh_git)
4
4
  [![Build Status](http://img.shields.io/travis/packsaddle/ruby-uri-ssh_git/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-uri-ssh_git)
5
5
 
6
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/uri/ssh_git`. To experiment with that code, run `bin/console` for an interactive prompt.
7
-
8
- TODO: Delete this and the text above, and describe your gem
6
+ ```ruby
7
+ url = URI::SshGit.parse('git@github.com:packsaddle/ruby-uri-ssh_git.git')
8
+ # => #<URI::SshGit::Generic git@github.com:packsaddle/ruby-uri-ssh_git.git>
9
+
10
+ # http://docs.ruby-lang.org/ja/2.2.0/class/URI=3a=3aGeneric.html
11
+ # :scheme ,:userinfo, :host, :port, :registry, :path, :opaque, :query, :fragment
12
+ url.scheme #=> nil
13
+ url.userinfo #=> 'git'
14
+ url.user #=> 'git'
15
+ url.password #=> nil
16
+ url.host #=> 'github.com'
17
+ url.port #=> nil
18
+ url.registry #=> nil
19
+ url.path #=> '/packsaddle/ruby-uri-ssh_git.git'
20
+ url.opaque #=> nil
21
+ url.query #=> nil
22
+ url.fragment #=> nil
23
+
24
+ URI::SshGit.build(
25
+ userinfo: 'git',
26
+ host: 'github.com',
27
+ path: '/packsaddle/ruby-uri-ssh_git.git'
28
+ ).to_s
29
+ #=> 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
30
+
31
+ # Utility method
32
+ ssh_protocol = 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
33
+ git_protocol = 'git://github.com/packsaddle/ruby-uri-ssh_git.git'
34
+
35
+ ::URI::SshGit.ssh_protocol?(ssh_protocol) #=> true
36
+ ::URI::SshGit.git_protocol?(ssh_protocol) #=> false
37
+ ::URI::SshGit.ssh_protocol?(git_protocol) #=> false
38
+ ::URI::SshGit.git_protocol?(git_protocol) #=> true
39
+
40
+ # Usage
41
+ git_clone_url = '...'
42
+ if ::URI::SshGit.ssh_protocol?(git_clone_url)
43
+ parsed = URI::SshGit.parse(git_clone_url)
44
+ else
45
+ parsed = URI.passe(git_clone_url)
46
+ end
47
+ parsed.host
48
+ parsed.path
49
+ ```
9
50
 
10
51
  ## Installation
11
52
 
@@ -23,10 +64,6 @@ Or install it yourself as:
23
64
 
24
65
  $ gem install uri-ssh_git
25
66
 
26
- ## Usage
27
-
28
- TODO: Write usage instructions here
29
-
30
67
  ## Development
31
68
 
32
69
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
data/example/simple.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  require '../lib/uri/ssh_git'
2
2
 
3
3
  url = URI::SshGit.parse('git@github.com:packsaddle/ruby-uri-ssh_git.git')
4
+ # => #<URI::SshGit::Generic git@github.com:packsaddle/ruby-uri-ssh_git.git>
4
5
 
5
6
  # http://docs.ruby-lang.org/ja/2.2.0/class/URI=3a=3aGeneric.html
6
7
  # :scheme ,:userinfo, :host, :port, :registry, :path, :opaque, :query, :fragment
7
8
  url.scheme #=> nil
8
9
  url.userinfo #=> 'git'
10
+ url.user #=> 'git'
11
+ url.password #=> nil
9
12
  url.host #=> 'github.com'
10
13
  url.port #=> nil
11
14
  url.registry #=> nil
@@ -14,5 +17,28 @@ url.opaque #=> nil
14
17
  url.query #=> nil
15
18
  url.fragment #=> nil
16
19
 
17
- URI::SshGit.build(userinfo: 'git', host: 'github.com', path: '/packsaddle/ruby-uri-ssh_git.git')
20
+ URI::SshGit.build(
21
+ userinfo: 'git',
22
+ host: 'github.com',
23
+ path: '/packsaddle/ruby-uri-ssh_git.git'
24
+ ).to_s
18
25
  #=> 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
26
+
27
+ # Utility method
28
+ ssh_protocol = 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
29
+ git_protocol = 'git://github.com/packsaddle/ruby-uri-ssh_git.git'
30
+
31
+ ::URI::SshGit.ssh_protocol?(ssh_protocol) #=> true
32
+ ::URI::SshGit.git_protocol?(ssh_protocol) #=> false
33
+ ::URI::SshGit.ssh_protocol?(git_protocol) #=> false
34
+ ::URI::SshGit.git_protocol?(git_protocol) #=> true
35
+
36
+ # Usage
37
+ git_clone_url = '...'
38
+ if ::URI::SshGit.ssh_protocol?(git_clone_url)
39
+ parsed = URI::SshGit.parse(git_clone_url)
40
+ else
41
+ parsed = URI.passe(git_clone_url)
42
+ end
43
+ parsed.host
44
+ parsed.path
data/lib/uri/ssh_git.rb CHANGED
@@ -1,7 +1,23 @@
1
+ require 'uri'
2
+
3
+ require 'uri/ssh_git/generic'
1
4
  require 'uri/ssh_git/version'
2
5
 
3
6
  module URI
4
7
  module SshGit
5
- # Your code goes here...
8
+ def self.parse(uri_string)
9
+ host_part, path_part = uri_string.split(':', 2)
10
+ userinfo, host = host_part.split('@', 2)
11
+ path_part = '/' + path_part unless path_part.start_with?('/')
12
+ Generic.build(userinfo: userinfo, host: host, path: path_part)
13
+ end
14
+
15
+ def self.ssh_protocol?(url_string)
16
+ url_string.include?('@')
17
+ end
18
+
19
+ def self.git_protocol?(url_string)
20
+ !ssh_protocol?(url_string)
21
+ end
6
22
  end
7
23
  end
@@ -0,0 +1,10 @@
1
+ module URI
2
+ module SshGit
3
+ class Generic < ::URI::Generic
4
+ def to_s
5
+ show_path = path.slice(1..-1) if path.start_with?('/')
6
+ "#{user}@#{host}:#{show_path}"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module URI
2
2
  module SshGit
3
- VERSION = '0.0.1.beta2'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-ssh_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
@@ -70,6 +70,7 @@ files:
70
70
  - bin/setup
71
71
  - example/simple.rb
72
72
  - lib/uri/ssh_git.rb
73
+ - lib/uri/ssh_git/generic.rb
73
74
  - lib/uri/ssh_git/version.rb
74
75
  - uri-ssh_git.gemspec
75
76
  homepage: https://github.com/packsaddle/ruby-uri-ssh_git
@@ -87,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
88
  version: '0'
88
89
  required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  requirements:
90
- - - ">"
91
+ - - ">="
91
92
  - !ruby/object:Gem::Version
92
- version: 1.3.1
93
+ version: '0'
93
94
  requirements: []
94
95
  rubyforge_project:
95
96
  rubygems_version: 2.4.5