gem-path 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 342baf0a44960b0378d32eb170cc87d007a2b81a
4
+ data.tar.gz: 3a2a037056b005cba6a7553daa0782bd7c70dea4
5
+ SHA512:
6
+ metadata.gz: dfd604224e2bd9567fdd24155716dac2689a01adb7d883b2c6fc46628dd054a127b78df5b0f67e1f24e9dff192d4e873c81f4835e7abc2828c7a3c2bc5ce1d38
7
+ data.tar.gz: 308897da1285e9fae093dc8de22a31c10ef6cba0e2bd6eb8c1bb4c846b80d2e7e9d3919c67595dbb1a08255007f45396f8f5d66216062b18cf5cf2e7874408f1
@@ -0,0 +1 @@
1
+ /pkg/
@@ -0,0 +1,3 @@
1
+ [submodule "task"]
2
+ path = task
3
+ url = git://github.com/godfat/gemgem.git
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,81 @@
1
+ # gem-path [![Build Status](https://secure.travis-ci.org/godfat/gem-path.png?branch=master)](http://travis-ci.org/godfat/gem-path)
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/gem-path)
8
+ * [rubygems](https://rubygems.org/gems/gem-path)
9
+
10
+ ## DESCRIPTION:
11
+
12
+ Find the path for a given gem or require path for editing or greping.
13
+
14
+ For examples, under [fish](http://fishshell.com/):
15
+
16
+ cd (gem path gem-path)
17
+ vim (gem path gem-path)
18
+ grep require -R (gem path gem-path)
19
+
20
+ Or checkout [gem-cd][], [gem-eit][], [gem-grep][] for shorthands.
21
+
22
+ [gem-cd]: https://github.com/godfat/gem-cd
23
+ [gem-eit]: https://github.com/godfat/gem-eit
24
+ [gem-grep]: https://github.com/godfat/gem-grep
25
+
26
+ ## REQUIREMENTS:
27
+
28
+ * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
29
+
30
+ ## INSTALLATION:
31
+
32
+ gem install gem-path
33
+
34
+ ## SYNOPSIS:
35
+
36
+ ### Gem path
37
+
38
+ gem path gem-path # ~/.gem/ruby/2.0.0/gems/gem-path-1.0.0
39
+
40
+ ### Gem path with specific gem version
41
+
42
+ gem path gem-path '<1' # ~/.gem/ruby/2.0.0/gems/gem-path-0.9.9
43
+ gem path gem-path '~>0.8.2' # ~/.gem/ruby/2.0.0/gems/gem-path-0.8.9
44
+ gem path gem-path 0.1.0 # ~/.gem/ruby/2.0.0/gems/gem-path-0.1.0
45
+
46
+ ### Find gem path from a require path
47
+
48
+ # ~/.gem/ruby/2.0.0/gems/gem-path-1.0.0
49
+ gem path rubygems/commands/path_command
50
+
51
+ ### Find file path from a require path
52
+
53
+ gem path timeout # /usr/lib/ruby/2.0.0/timeout.rb
54
+
55
+ ## CONTRIBUTORS:
56
+
57
+ * Lin Jen-Shin (@godfat)
58
+
59
+ ## SIDE NOTES:
60
+
61
+ This was extracted from [eit-gem][].
62
+
63
+ [eit-gem]: https://github.com/godfat/dev-tool/blob/eaafad940ee3c274cccddf831e04216969223146/bin/eit-gem
64
+
65
+ ## LICENSE:
66
+
67
+ Apache License 2.0
68
+
69
+ Copyright (c) 2013, Lin Jen-Shin (godfat)
70
+
71
+ Licensed under the Apache License, Version 2.0 (the "License");
72
+ you may not use this file except in compliance with the License.
73
+ You may obtain a copy of the License at
74
+
75
+ <http://www.apache.org/licenses/LICENSE-2.0>
76
+
77
+ Unless required by applicable law or agreed to in writing, software
78
+ distributed under the License is distributed on an "AS IS" BASIS,
79
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80
+ See the License for the specific language governing permissions and
81
+ limitations under the License.
@@ -0,0 +1,12 @@
1
+
2
+ begin
3
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
4
+ rescue LoadError
5
+ sh 'git submodule update --init'
6
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
+ end
8
+
9
+ Gemgem.init(dir) do |s|
10
+ s.name = 'gem-path'
11
+ s.version = '0.5.0'
12
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: gem-path 0.5.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "gem-path"
6
+ s.version = "0.5.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.authors = ["Lin Jen-Shin (godfat)"]
10
+ s.date = "2013-11-22"
11
+ s.description = "Find the path for a given gem or require path for editing or greping.\n\nFor examples, under [fish](http://fishshell.com/):\n\n cd (gem path gem-path)\n vim (gem path gem-path)\n grep require -R (gem path gem-path)\n\nOr checkout [gem-cd][], [gem-eit][], [gem-grep][] for shorthands.\n\n[gem-cd]: https://github.com/godfat/gem-cd\n[gem-eit]: https://github.com/godfat/gem-eit\n[gem-grep]: https://github.com/godfat/gem-grep"
12
+ s.email = ["godfat (XD) godfat.org"]
13
+ s.files = [
14
+ ".gitignore",
15
+ ".gitmodules",
16
+ "LICENSE",
17
+ "README.md",
18
+ "Rakefile",
19
+ "gem-path.gemspec",
20
+ "lib/rubygems/commands/path_command.rb",
21
+ "lib/rubygems_plugin.rb",
22
+ "task/README.md",
23
+ "task/gemgem.rb"]
24
+ s.homepage = "https://github.com/godfat/gem-path"
25
+ s.licenses = ["Apache License 2.0"]
26
+ s.require_paths = ["lib"]
27
+ s.rubygems_version = "2.1.11"
28
+ s.summary = "Find the path for a given gem or require path for editing or greping."
29
+ end
@@ -0,0 +1,53 @@
1
+
2
+ class Gem::Commands::PathCommand < Gem::Command
3
+ def description
4
+ 'Find the path for a given gem or require path'
5
+ end
6
+
7
+ def initialize
8
+ super('path', description)
9
+ end
10
+
11
+ def execute
12
+ name, version = extract!(options[:args])
13
+
14
+ # find the exact gem
15
+ if path_gem = find_path_gem(name)
16
+ say(path_gem)
17
+
18
+ # find the require file
19
+ elsif path = Gem.find_files("#{name}.rb").first
20
+ # favor gem first (e.g. rake gem)
21
+ if path_gem = Gem.path.find{ |p|
22
+ break $1 if path =~ %r{(#{p}(/[^/]+){2})}
23
+ }
24
+ say(path_gem)
25
+ else
26
+ say(path)
27
+ end
28
+ else
29
+ alert_error("#{name} not found")
30
+ terminate_interaction(1)
31
+ end
32
+ end
33
+
34
+ private
35
+ def extract! args
36
+ gem(*args) if args.size > 1 # only gem has versions
37
+ args
38
+ rescue LoadError => e
39
+ alert_error(e.message)
40
+ terminate_interaction(1)
41
+ end
42
+
43
+ def find_path_gem name
44
+ path_gem = Gem.path.find do |base|
45
+ path_gem = $LOAD_PATH.find do |path|
46
+ path_gem = path[%r{#{base}/gems/#{name}\-[^/-]+/}]
47
+ break path_gem if path_gem
48
+ end
49
+ break path_gem if path_gem
50
+ end
51
+ path_gem[0...-1] if path_gem
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require 'rubygems/command_manager'
3
+ Gem::CommandManager.instance.register_command(:path)
@@ -0,0 +1,54 @@
1
+ # Gemgem
2
+
3
+ ## DESCRIPTION:
4
+
5
+ Provided tasks:
6
+
7
+ rake clean # Remove ignored files
8
+ rake gem:build # Build gem
9
+ rake gem:install # Install gem
10
+ rake gem:release # Release gem
11
+ rake gem:spec # Generate gemspec
12
+ rake test # Run tests in memory
13
+
14
+ ## REQUIREMENTS:
15
+
16
+ * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
17
+
18
+ ## INSTALLATION:
19
+
20
+ git submodule add git://github.com/godfat/gemgem.git task
21
+
22
+ And in Rakefile:
23
+
24
+ ``` ruby
25
+ begin
26
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
27
+ rescue LoadError
28
+ sh 'git submodule update --init'
29
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
+ end
31
+
32
+ Gemgem.init(dir) do |s|
33
+ s.name = 'your-gem'
34
+ s.version = '0.1.0'
35
+ end
36
+ ```
37
+
38
+ ## LICENSE:
39
+
40
+ Apache License 2.0
41
+
42
+ Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
43
+
44
+ Licensed under the Apache License, Version 2.0 (the "License");
45
+ you may not use this file except in compliance with the License.
46
+ You may obtain a copy of the License at
47
+
48
+ <http://www.apache.org/licenses/LICENSE-2.0>
49
+
50
+ Unless required by applicable law or agreed to in writing, software
51
+ distributed under the License is distributed on an "AS IS" BASIS,
52
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53
+ See the License for the specific language governing permissions and
54
+ limitations under the License.
@@ -0,0 +1,268 @@
1
+
2
+ module Gemgem
3
+ class << self
4
+ attr_accessor :dir, :spec, :spec_create
5
+ end
6
+
7
+ module_function
8
+ def gem_tag ; "#{spec.name}-#{spec.version}" ; end
9
+ def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
10
+ def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
11
+ def pkg_dir ; "#{dir}/pkg" ; end
12
+ def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
+
14
+ def init dir, &block
15
+ self.dir = dir
16
+ $LOAD_PATH.unshift("#{dir}/lib")
17
+ ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
+ ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
19
+ self.spec_create = block
20
+ end
21
+
22
+ def create
23
+ spec = Gem::Specification.new do |s|
24
+ s.authors = ['Lin Jen-Shin (godfat)']
25
+ s.email = ['godfat (XD) godfat.org']
26
+
27
+ s.description = description.join
28
+ s.summary = description.first
29
+ s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
30
+
31
+ s.date = Time.now.strftime('%Y-%m-%d')
32
+ s.files = gem_files
33
+ s.test_files = test_files
34
+ s.executables = bin_files
35
+ end
36
+ spec_create.call(spec)
37
+ spec.homepage = "https://github.com/godfat/#{spec.name}"
38
+ self.spec = spec
39
+ end
40
+
41
+ def write
42
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
43
+ end
44
+
45
+ def split_lines ruby
46
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
47
+ if $2.index(',')
48
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
49
+ else
50
+ s
51
+ end
52
+ }
53
+ end
54
+
55
+ def strip_path path
56
+ strip_home_path(strip_cwd_path(path))
57
+ end
58
+
59
+ def strip_home_path path
60
+ path.sub(ENV['HOME'], '~')
61
+ end
62
+
63
+ def strip_cwd_path path
64
+ path.sub(Dir.pwd, '.')
65
+ end
66
+
67
+ def git *args
68
+ `git --git-dir=#{dir}/.git #{args.join(' ')}`
69
+ end
70
+
71
+ def sh_git *args
72
+ Rake.sh('git', "--git-dir=#{dir}/.git", *args)
73
+ end
74
+
75
+ def sh_gem *args
76
+ Rake.sh(Gem.ruby, '-S', 'gem', *args)
77
+ end
78
+
79
+ def glob path=dir
80
+ Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
81
+ end
82
+
83
+ def readme
84
+ @readme ||=
85
+ if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
86
+ ps = "##{File.read(path)}".
87
+ scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
88
+ ps.inject('HEADER' => ps.first){ |r, s, i|
89
+ r[s[/\w+/]] = s
90
+ r
91
+ }
92
+ else
93
+ {}
94
+ end
95
+ end
96
+
97
+ def description
98
+ # JRuby String#lines is returning an enumerator
99
+ @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
100
+ end
101
+
102
+ def all_files
103
+ @all_files ||= fold_files(glob).sort
104
+ end
105
+
106
+ def fold_files files
107
+ files.inject([]){ |r, path|
108
+ if File.file?(path) && path !~ %r{/\.git(/|$)} &&
109
+ (rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
110
+ r << rpath
111
+ elsif File.symlink?(path) # walk into symlinks...
112
+ r.concat(fold_files(glob(File.expand_path(path,
113
+ File.readlink(path)))))
114
+ else
115
+ r
116
+ end
117
+ }
118
+ end
119
+
120
+ def gem_files
121
+ @gem_files ||= all_files.reject{ |f|
122
+ f =~ ignored_pattern && !git_files.include?(f)
123
+ }
124
+ end
125
+
126
+ def test_files
127
+ @test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
128
+ end
129
+
130
+ def bin_files
131
+ @bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
132
+ end
133
+
134
+ def git_files
135
+ @git_files ||= if File.exist?("#{dir}/.git")
136
+ git('ls-files').split("\n")
137
+ else
138
+ []
139
+ end
140
+ end
141
+
142
+ def ignored_files
143
+ @ignored_files ||= all_files.grep(ignored_pattern)
144
+ end
145
+
146
+ def ignored_pattern
147
+ @ignored_pattern ||= if gitignore.empty?
148
+ /^$/
149
+ else
150
+ Regexp.new(expand_patterns(gitignore).join('|'))
151
+ end
152
+ end
153
+
154
+ def expand_patterns pathes
155
+ # http://git-scm.com/docs/gitignore
156
+ pathes.flat_map{ |path|
157
+ case path
158
+ when %r{\*}
159
+ Regexp.escape(path).gsub(/\\\*/, '[^/]*')
160
+ when %r{^/}
161
+ "^#{Regexp.escape(path[1..-1])}"
162
+ else # we didn't implement negative pattern for now
163
+ Regexp.escape(path)
164
+ end
165
+ }
166
+ end
167
+
168
+ def gitignore
169
+ @gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
170
+ File.read(path).lines.
171
+ reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
172
+ else
173
+ []
174
+ end
175
+ end
176
+ end
177
+
178
+ namespace :gem do
179
+
180
+ desc 'Install gem'
181
+ task :install => [:build] do
182
+ Gemgem.sh_gem('install', Gemgem.gem_path)
183
+ end
184
+
185
+ desc 'Build gem'
186
+ task :build => [:spec] do
187
+ require 'fileutils'
188
+ require 'rubygems/package'
189
+ gem = nil
190
+ Dir.chdir(Gemgem.dir) do
191
+ gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
192
+ FileUtils.mkdir_p(Gemgem.pkg_dir)
193
+ FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
194
+ end
195
+ puts "\e[35mGem built: \e[33m" \
196
+ "#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
197
+ end
198
+
199
+ desc 'Generate gemspec'
200
+ task :spec do
201
+ Gemgem.create
202
+ Gemgem.write
203
+ end
204
+
205
+ desc 'Release gem'
206
+ task :release => [:spec, :check, :build] do
207
+ Gemgem.module_eval do
208
+ sh_git('tag', Gemgem.gem_tag)
209
+ sh_git('push')
210
+ sh_git('push', '--tags')
211
+ sh_gem('push', Gemgem.gem_path)
212
+ end
213
+ end
214
+
215
+ task :check do
216
+ ver = Gemgem.spec.version.to_s
217
+
218
+ if ENV['VERSION'].nil?
219
+ puts("\e[35mExpected " \
220
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
221
+ exit(1)
222
+
223
+ elsif ENV['VERSION'] != ver
224
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
225
+ "\e[35mbut got\n " \
226
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
227
+ exit(2)
228
+ end
229
+ end
230
+
231
+ end # of gem namespace
232
+
233
+ desc 'Run tests'
234
+ task :test do
235
+ next if Gemgem.test_files.empty?
236
+
237
+ require 'bacon'
238
+ Bacon.extend(Bacon::TestUnitOutput)
239
+ Bacon.summary_on_exit
240
+ Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
241
+ end
242
+
243
+ desc 'Trash ignored files'
244
+ task :clean => ['gem:spec'] do
245
+ next if Gemgem.ignored_files.empty?
246
+
247
+ require 'fileutils'
248
+ trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
249
+ puts "Move the following files into:" \
250
+ " \e[35m#{Gemgem.strip_path(trash)}\e[33m"
251
+
252
+ Gemgem.ignored_files.each do |file|
253
+ from = "#{Gemgem.dir}/#{file}"
254
+ to = "#{trash}/#{File.dirname(file)}"
255
+ puts Gemgem.strip_path(from)
256
+
257
+ FileUtils.mkdir_p(to)
258
+ FileUtils.mv(from, to)
259
+ end
260
+
261
+ print "\e[0m"
262
+ end
263
+
264
+ task :default do
265
+ # Is there a reliable way to do this in the current process?
266
+ # It failed miserably before between Rake versions...
267
+ exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
268
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-path
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Lin Jen-Shin (godfat)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Find the path for a given gem or require path for editing or greping.
15
+
16
+ For examples, under [fish](http://fishshell.com/):
17
+
18
+ cd (gem path gem-path)
19
+ vim (gem path gem-path)
20
+ grep require -R (gem path gem-path)
21
+
22
+ Or checkout [gem-cd][], [gem-eit][], [gem-grep][] for shorthands.
23
+
24
+ [gem-cd]: https://github.com/godfat/gem-cd
25
+ [gem-eit]: https://github.com/godfat/gem-eit
26
+ [gem-grep]: https://github.com/godfat/gem-grep
27
+ email:
28
+ - godfat (XD) godfat.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - .gitmodules
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - gem-path.gemspec
39
+ - lib/rubygems/commands/path_command.rb
40
+ - lib/rubygems_plugin.rb
41
+ - task/README.md
42
+ - task/gemgem.rb
43
+ homepage: https://github.com/godfat/gem-path
44
+ licenses:
45
+ - Apache License 2.0
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.1.11
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Find the path for a given gem or require path for editing or greping.
67
+ test_files: []