anything-gorepo 0.0.2 → 0.0.5

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: c5df0f856789b5baf54437999320d50e11189b0d
4
- data.tar.gz: 8a74772ded9508652f31dec4cc0d0cf8282e2f0a
3
+ metadata.gz: 0f785be26310765c4a249533ef3a0a66ea4159aa
4
+ data.tar.gz: 833b568c4c221ea7ab23abd0f1863b1e3b70c68a
5
5
  SHA512:
6
- metadata.gz: 63be75a1f6e4ecb2c5d4e7b74761f598e7ed37152c15f0a09e613606ab693ba80a5eef0cd1d62db0b363e8403c4e9596d0b1d12d5478c36d3969de042292e3b9
7
- data.tar.gz: dbcc1cf1a93e3ad3b9365c7b8135373fa6755e0bae5ee9e2eff078ec2c7abb94c928512c7c3cf66600d3342a0a2f6373036d2659756e5caf8c3aa3ae9b865cb5
6
+ metadata.gz: c33da7e0f27cb852158380037079881c09b1660e30db5be5d5604ac4f6ab189e1c1decbaa4aa81f1f64cee9ef7b71d03724e72d9d870cda4a570b31f99fd7f46
7
+ data.tar.gz: 9fe227a9667f259ed57ac4f7f49bc40a01b266d72002570368bb9a0fcab5a923a52ee69cae3a8a7297086432e7e583ecc24e0c1c42cd2fab234289a98ed15461
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
- spec.add_dependency "ruby-anything", ">= 0.0.4"
24
+ spec.add_dependency "ruby-anything", ">= 0.0.5"
25
25
  end
data/bin/anything-gorepo CHANGED
@@ -13,11 +13,16 @@ end
13
13
 
14
14
  require 'ruby-anything'
15
15
 
16
- gopath = ENV['GOPATH'].dup
17
-
18
- unless gopath
19
- STDERR.puts e.message
20
- exit 1
16
+ unless ENV['PATH'].split(':').any? { |path| File.exists?(File.join(path, 'go')) }
17
+ STDERR.puts 'go should be in $PATH'
21
18
  end
22
19
 
23
- STDOUT.puts AnythingGorepo.find(File.join(gopath, 'src'))
20
+ goenv = `go env`.split("\n")
21
+ rgoroot = goenv.grep(/^GOROOT/).first
22
+ rgopath = goenv.grep(/^GOPATH/).first
23
+
24
+ find_paths = []
25
+ find_paths << File.join(rgoroot.gsub(/GOROOT="(.+)"/, '\1'), 'src', 'pkg') if rgoroot
26
+ find_paths << File.join(rgopath.gsub(/GOPATH="(.+)"/, '\1'), 'src') if rgopath
27
+
28
+ STDOUT.puts AnythingGorepo.find(find_paths)
@@ -1,3 +1,3 @@
1
1
  module AnythingGorepo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,8 +1,41 @@
1
1
  require "anything-gorepo/version"
2
- require "anything-gorepo/finder"
3
2
 
4
3
  module AnythingGorepo
5
- def self.find src
6
- File.join(src, Finder.new(src).find)
4
+ def self.find paths
5
+ # key: package name
6
+ # value: package full path
7
+ pkgs = {}
8
+
9
+ paths.each do |path|
10
+ packages(path).map do |pkg|
11
+ pkgs[pkg.gsub(path + '/', '')] = pkg
12
+ end
13
+ end
14
+
15
+ pkgs[_anything_(pkgs.keys)]
16
+ end
17
+
18
+ def self.packages(src, stack = [])
19
+ directories(src).reduce([]) do |pkgs, p|
20
+ pkgs << File.join(src, p)
21
+
22
+ if directories(File.join(src, p)).empty?
23
+ pkgs
24
+ else
25
+ pkgs + packages(File.join(src, p))
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def self.directories path
33
+ return [] if Dir.glob(File.join(path, "**/*.go")).empty?
34
+
35
+ Dir.entries(path).select do |filename|
36
+ File.directory?(File.join(path, filename))
37
+ end.select do |filename|
38
+ !filename.start_with?('.')
39
+ end
7
40
  end
8
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anything-gorepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takatoshi Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2014-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.4
47
+ version: 0.0.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.4
54
+ version: 0.0.5
55
55
  description: Find local go repositories in $GOPATH by anything interface.
56
56
  email:
57
57
  - toqoz403@gmail.com
@@ -68,7 +68,6 @@ files:
68
68
  - anything-gorepo.gemspec
69
69
  - bin/anything-gorepo
70
70
  - lib/anything-gorepo.rb
71
- - lib/anything-gorepo/finder.rb
72
71
  - lib/anything-gorepo/version.rb
73
72
  homepage: http://github.com/ToQoz/anything-gorepo
74
73
  licenses:
@@ -1,28 +0,0 @@
1
- module AnythingGorepo
2
- class Finder
3
- def initialize src
4
- @repo_paths = []
5
- directories(src).each do |host|
6
- directories(File.join(src, host)).each do |user|
7
- directories(File.join(src, host, user)).each do |repo|
8
- @repo_paths << File.join(host, user, repo) # diplay without src
9
- end
10
- end
11
- end
12
- end
13
-
14
- def find
15
- _anything_(@repo_paths)
16
- end
17
-
18
- private
19
-
20
- def directories path
21
- Dir.entries(path).select do |filename|
22
- File.directory?(File.join(path, filename))
23
- end.select do |filename|
24
- filename != '.' && filename != '..'
25
- end
26
- end
27
- end
28
- end