gem-src 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/gem-src.gemspec +1 -1
  2. data/lib/rubygems_plugin.rb +55 -17
  3. metadata +18 -38
data/gem-src.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "gem-src"
7
- gem.version = '0.3.3'
7
+ gem.version = '0.4.0'
8
8
  gem.authors = ["Akira Matsuda"]
9
9
  gem.email = ["ronnie@dio.jp"]
10
10
  gem.description = 'Gem.post_install { `git clone gem_source src` }'
@@ -1,19 +1,27 @@
1
1
  require 'rubygems'
2
2
 
3
- Gem.post_install do |installer|
4
- if (repo = installer.spec.homepage) && !repo.empty?
5
- clone_dir = if ENV['GEMSRC_CLONE_ROOT']
6
- File.expand_path installer.spec.name, ENV['GEMSRC_CLONE_ROOT']
7
- elsif Gem.configuration[:gemsrc_clone_root]
8
- File.expand_path installer.spec.name, Gem.configuration[:gemsrc_clone_root]
9
- else
10
- gem_dir = installer.respond_to?(:gem_dir) ? installer.gem_dir : File.expand_path(File.join(installer.gem_home, 'gems', installer.spec.full_name))
11
- File.join gem_dir, 'src'
12
- end
13
-
14
- unless File.exists?(clone_dir)
15
- if repo =~ /\Ahttps?:\/\/([^.]+)\.github.com\/(.+)/
16
- repo = if $1 == 'www'
3
+ module Gem
4
+ class Src
5
+ attr_reader :installer
6
+
7
+ def initialize(installer)
8
+ @installer = installer
9
+ end
10
+
11
+ def clone_dir
12
+ @clone_dir ||= if ENV['GEMSRC_CLONE_ROOT']
13
+ File.expand_path installer.spec.name, ENV['GEMSRC_CLONE_ROOT']
14
+ elsif Gem.configuration[:gemsrc_clone_root]
15
+ File.expand_path installer.spec.name, Gem.configuration[:gemsrc_clone_root]
16
+ else
17
+ gem_dir = installer.respond_to?(:gem_dir) ? installer.gem_dir : File.expand_path(File.join(installer.gem_home, 'gems', installer.spec.full_name))
18
+ File.join gem_dir, 'src'
19
+ end
20
+ end
21
+
22
+ def github_url(url)
23
+ if url =~ /\Ahttps?:\/\/([^.]+)\.github.com\/(.+)/
24
+ if $1 == 'www'
17
25
  "https://github.com/#{$2}"
18
26
  elsif $1 == 'wiki'
19
27
  # https://wiki.github.com/foo/bar => https://github.com/foo/bar
@@ -23,10 +31,40 @@ Gem.post_install do |installer|
23
31
  "https://github.com/#{$1}/#{$2}"
24
32
  end
25
33
  end
34
+ end
26
35
 
27
- if !`git ls-remote #{repo} 2> /dev/null`.empty?
28
- `git clone #{repo} #{clone_dir}`
29
- end
36
+ def git?(url)
37
+ !`git ls-remote #{url} 2> /dev/null`.empty?
38
+ end
39
+
40
+ def api
41
+ @api ||= Net::HTTP.get(URI.parse "http://rubygems.org/api/v1/gems/#{installer.spec.name}.yaml")
42
+ end
43
+
44
+ def source_code_uri
45
+ api[/^source_code_uri: (.*)$/, 1]
46
+ end
47
+
48
+ def homepage_uri
49
+ api[/^homepage_uri: (.*)$/, 1]
50
+ end
51
+
52
+ def git_clone(repository)
53
+ system 'git', 'clone', repository, clone_dir if repository && !repository.empty? && git?(repository)
54
+ end
55
+
56
+ def git_clone_homepage_or_source_code_uri_or_homepage_uri
57
+ return false if File.exists? clone_dir
58
+ git_clone(installer.spec.homepage) ||
59
+ git_clone(github_url(installer.spec.homepage)) ||
60
+ git_clone(source_code_uri) ||
61
+ git_clone(homepage_uri) ||
62
+ git_clone(github_url(homepage_uri))
30
63
  end
31
64
  end
32
65
  end
66
+
67
+
68
+ Gem.post_install do |installer|
69
+ Gem::Src.new(installer).git_clone_homepage_or_source_code_uri_or_homepage_uri
70
+ end
metadata CHANGED
@@ -1,33 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gem-src
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Akira Matsuda
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-16 00:00:00 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Gem.post_install { `git clone gem_source src` }
22
- email:
15
+ email:
23
16
  - ronnie@dio.jp
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - .gitignore
32
22
  - Gemfile
33
23
  - LICENSE.txt
@@ -37,36 +27,26 @@ files:
37
27
  - lib/rubygems_plugin.rb
38
28
  homepage: https://github.com/amatsuda/gem-src
39
29
  licenses: []
40
-
41
30
  post_install_message:
42
31
  rdoc_options: []
43
-
44
- require_paths:
32
+ require_paths:
45
33
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
34
+ required_ruby_version: !ruby/object:Gem::Requirement
47
35
  none: false
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- hash: 3
52
- segments:
53
- - 0
54
- version: "0"
55
- required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
41
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
64
46
  requirements: []
65
-
66
47
  rubyforge_project:
67
48
  rubygems_version: 1.8.24
68
49
  signing_key:
69
50
  specification_version: 3
70
51
  summary: Gem.post_install { `git clone gem_source src` }
71
52
  test_files: []
72
-