gem-bgrep 0.6.3 → 0.8.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: 02812e5a6c95d2aa420ae4655d4dd2b6ab802c2a
4
- data.tar.gz: ce86b6f65cc9badabee524f3c9f4a803b49d4499
3
+ metadata.gz: 3b776dfb01ec527083f64075ba632f817e312264
4
+ data.tar.gz: 874f74644b23d6dcd04cb5d20e9d36121224b0bc
5
5
  SHA512:
6
- metadata.gz: 9e9a42c6d176b0242c1cc80757f4eec4f3cd516c8b648d4559593bdd13f8ef66f6a39d17df6a6d7d7a22274e1e348894dd71fe644fe4e92a9611f854b40f6a6a
7
- data.tar.gz: 679c09a42bcb281577253e51af9aa4951cd31e931fbcbfaecb8e32f262c065974a87de3babcd0b6523fcc30c2e929c663239d679bf4124ee321edeb737e2170f
6
+ metadata.gz: bed38b24a628afd58d3b84e479b0b64401648ead1492e84fb867fbc1e710e8a1fe09dee6a2b720dbac247385f8a0f76b096402ed68584ff06c615c5c8c350331
7
+ data.tar.gz: ee00e4394663636e9b8903226681e6f85fdffb5d0db5429249652c7d331427f0a4dda46dfe028cd0a6174729e4417fea08e9d51772cec8b47ef6cbe5ea6cc3ba
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGES
2
2
 
3
+ ## gem-bgrep 0.8.0 -- 2017-09-11
4
+
5
+ * Use a single command to grep so that it's much more faster. Require
6
+ `gem-grep` 0.8.0.
7
+
3
8
  ## gem-bgrep 0.6.3 -- 2016-05-29
4
9
 
5
10
  * Show "No Gemfile detected." when we can't setup bundler.
data/Rakefile CHANGED
@@ -1,14 +1,14 @@
1
1
 
2
2
  begin
3
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
3
+ require "#{__dir__}/task/gemgem"
4
4
  rescue LoadError
5
- sh 'git submodule update --init'
5
+ sh 'git submodule update --init --recursive'
6
6
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
7
  end
8
8
 
9
- Gemgem.init(dir) do |s|
9
+ Gemgem.init(__dir__) do |s|
10
10
  s.name = 'gem-bgrep'
11
- s.version = '0.6.3'
12
- s.add_runtime_dependency('gem-grep', '>= 0.6.2')
11
+ s.version = '0.8.0'
12
+ s.add_runtime_dependency('gem-grep', '>= 0.8.0')
13
13
  s.add_runtime_dependency('bundler')
14
14
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: gem-bgrep 0.6.3 ruby lib
2
+ # stub: gem-bgrep 0.8.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "gem-bgrep".freeze
6
- s.version = "0.6.3"
6
+ s.version = "0.8.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
- s.date = "2016-05-29"
11
+ s.date = "2017-09-11"
12
12
  s.description = "Can't find some codes from your app? gem-bgrep let you grep from your Gemfile.\n\nAlso checkout [gem-grep][].\n\n[gem-grep]: https://github.com/godfat/gem-grep".freeze
13
13
  s.email = ["godfat (XD) godfat.org".freeze]
14
14
  s.files = [
@@ -26,21 +26,21 @@ Gem::Specification.new do |s|
26
26
  "task/gemgem.rb".freeze]
27
27
  s.homepage = "https://github.com/godfat/gem-bgrep".freeze
28
28
  s.licenses = ["Apache License 2.0".freeze]
29
- s.rubygems_version = "2.6.4".freeze
29
+ s.rubygems_version = "2.6.13".freeze
30
30
  s.summary = "Can't find some codes from your app? gem-bgrep let you grep from your Gemfile.".freeze
31
31
 
32
32
  if s.respond_to? :specification_version then
33
33
  s.specification_version = 4
34
34
 
35
35
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
36
- s.add_runtime_dependency(%q<gem-grep>.freeze, [">= 0.6.2"])
36
+ s.add_runtime_dependency(%q<gem-grep>.freeze, [">= 0.8.0"])
37
37
  s.add_runtime_dependency(%q<bundler>.freeze, [">= 0"])
38
38
  else
39
- s.add_dependency(%q<gem-grep>.freeze, [">= 0.6.2"])
39
+ s.add_dependency(%q<gem-grep>.freeze, [">= 0.8.0"])
40
40
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
41
41
  end
42
42
  else
43
- s.add_dependency(%q<gem-grep>.freeze, [">= 0.6.2"])
43
+ s.add_dependency(%q<gem-grep>.freeze, [">= 0.8.0"])
44
44
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
45
45
  end
46
46
  end
@@ -22,15 +22,11 @@ class Gem::Commands::BgrepCommand < Gem::Command
22
22
 
23
23
  def grep_gems
24
24
  cmd = Gem::Commands::GrepCommand.new
25
- Bundler.load.requested_specs.each do |spec|
26
- system(*cmd.grep_command([spec.name, spec.version],
27
- options[:args] + options[:build_args]))
25
+ gems = Bundler.load.requested_specs.map do |spec|
26
+ [spec.name, spec.version]
28
27
  end
29
- end
30
28
 
31
- private
32
- def system *args
33
- say(args.join(' '))
34
- super
29
+ cmd.__send__(
30
+ :exec, *cmd.grep_command(options[:args] + options[:build_args], *gems))
35
31
  end
36
32
  end
@@ -4,16 +4,16 @@
4
4
 
5
5
  Provided tasks:
6
6
 
7
- rake clean # Remove ignored files
7
+ rake clean # Trash ignored files
8
8
  rake gem:build # Build gem
9
9
  rake gem:install # Install gem
10
10
  rake gem:release # Release gem
11
11
  rake gem:spec # Generate gemspec
12
- rake test # Run tests in memory
12
+ rake test # Run tests
13
13
 
14
14
  ## REQUIREMENTS:
15
15
 
16
- * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
16
+ * Tested with MRI (official CRuby), Rubinius and JRuby.
17
17
 
18
18
  ## INSTALLATION:
19
19
 
@@ -23,13 +23,13 @@ And in Rakefile:
23
23
 
24
24
  ``` ruby
25
25
  begin
26
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
26
+ require "#{__dir__}/task/gemgem"
27
27
  rescue LoadError
28
- sh 'git submodule update --init'
28
+ sh 'git submodule update --init --recursive'
29
29
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
30
  end
31
31
 
32
- Gemgem.init(dir) do |s|
32
+ Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
33
33
  s.name = 'your-gem'
34
34
  s.version = '0.1.0'
35
35
  end
@@ -37,9 +37,9 @@ end
37
37
 
38
38
  ## LICENSE:
39
39
 
40
- Apache License 2.0
40
+ Apache License 2.0 (Apache-2.0)
41
41
 
42
- Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
42
+ Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
43
43
 
44
44
  Licensed under the Apache License, Version 2.0 (the "License");
45
45
  you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Gemgem
3
3
  class << self
4
- attr_accessor :dir, :spec, :spec_create
4
+ attr_accessor :dir, :spec, :submodules, :spec_create
5
5
  end
6
6
 
7
7
  module_function
@@ -11,12 +11,14 @@ module Gemgem
11
11
  def pkg_dir ; "#{dir}/pkg" ; end
12
12
  def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
13
 
14
- def init dir, &block
14
+ def init dir, options={}, &block
15
15
  self.dir = dir
16
- $LOAD_PATH.unshift("#{dir}/lib")
17
16
  ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
17
  ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
18
+ self.submodules = options[:submodules] || []
19
19
  self.spec_create = block
20
+
21
+ $LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
20
22
  end
21
23
 
22
24
  def create
@@ -26,7 +28,7 @@ module Gemgem
26
28
 
27
29
  s.description = description.join
28
30
  s.summary = description.first
29
- s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
31
+ s.license = license
30
32
 
31
33
  s.date = Time.now.strftime('%Y-%m-%d')
32
34
  s.files = gem_files
@@ -34,10 +36,113 @@ module Gemgem
34
36
  s.executables = bin_files
35
37
  end
36
38
  spec_create.call(spec)
37
- spec.homepage = "https://github.com/godfat/#{spec.name}"
39
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
38
40
  self.spec = spec
39
41
  end
40
42
 
43
+ def gem_install
44
+ require 'rubygems/commands/install_command'
45
+ # read ~/.gemrc
46
+ Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
47
+ Gem::Command.extra_args = Gem.configuration[:gem]
48
+
49
+ # setup install options
50
+ cmd = Gem::Commands::InstallCommand.new
51
+ cmd.handle_options([])
52
+
53
+ # install
54
+ install = Gem::Installer.new(gem_path, cmd.options)
55
+ install.install
56
+ puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
57
+ end
58
+
59
+ def gem_spec
60
+ create
61
+ write
62
+ end
63
+
64
+ def gem_build
65
+ require 'fileutils'
66
+ require 'rubygems/package'
67
+ gem = nil
68
+ Dir.chdir(dir) do
69
+ gem = Gem::Package.build(Gem::Specification.load(spec_path))
70
+ FileUtils.mkdir_p(pkg_dir)
71
+ FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
72
+ end
73
+ puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
74
+ end
75
+
76
+ def gem_release
77
+ sh_git('tag', gem_tag)
78
+ sh_git('push')
79
+ sh_git('push', '--tags')
80
+ sh_gem('push', gem_path)
81
+ end
82
+
83
+ def gem_check
84
+ unless git('status', '--porcelain').empty?
85
+ puts("\e[35mWorking copy is not clean.\e[0m")
86
+ exit(3)
87
+ end
88
+
89
+ ver = spec.version.to_s
90
+
91
+ if ENV['VERSION'].nil?
92
+ puts("\e[35mExpected " \
93
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
94
+ exit(1)
95
+
96
+ elsif ENV['VERSION'] != ver
97
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
98
+ "\e[35mbut got\n " \
99
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
100
+ exit(2)
101
+ end
102
+ end
103
+
104
+ def test
105
+ return if test_files.empty?
106
+
107
+ if ENV['COV'] || ENV['CI']
108
+ require 'simplecov'
109
+ if ENV['CI']
110
+ begin
111
+ require 'coveralls'
112
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
113
+ rescue LoadError => e
114
+ puts "Cannot load coveralls, skip: #{e}"
115
+ end
116
+ end
117
+ SimpleCov.start do
118
+ add_filter('test/')
119
+ add_filter('test.rb')
120
+ submodules_libs.each(&method(:add_filter))
121
+ end
122
+ end
123
+
124
+ test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
125
+ end
126
+
127
+ def clean
128
+ return if ignored_files.empty?
129
+
130
+ require 'fileutils'
131
+ trash = File.expand_path("~/.Trash/#{spec.name}")
132
+ puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
133
+
134
+ ignored_files.each do |file|
135
+ from = "#{dir}/#{file}"
136
+ to = "#{trash}/#{File.dirname(file)}"
137
+ puts strip_path(from)
138
+
139
+ FileUtils.mkdir_p(to)
140
+ FileUtils.mv(from, to)
141
+ end
142
+
143
+ print "\e[0m"
144
+ end
145
+
41
146
  def write
42
147
  File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
43
148
  end
@@ -57,11 +162,15 @@ module Gemgem
57
162
  end
58
163
 
59
164
  def strip_home_path path
60
- path.sub(ENV['HOME'], '~')
165
+ path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
61
166
  end
62
167
 
63
168
  def strip_cwd_path path
64
- path.sub(Dir.pwd, '.')
169
+ path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
170
+ end
171
+
172
+ def submodules_libs
173
+ submodules.map{ |path| "#{dir}/#{path}/lib" }
65
174
  end
66
175
 
67
176
  def git *args
@@ -99,6 +208,11 @@ module Gemgem
99
208
  @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
100
209
  end
101
210
 
211
+ def license
212
+ readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
213
+ split(/[()]/).map(&:strip).reject(&:empty?).last
214
+ end
215
+
102
216
  def all_files
103
217
  @all_files ||= fold_files(glob).sort
104
218
  end
@@ -119,7 +233,8 @@ module Gemgem
119
233
 
120
234
  def gem_files
121
235
  @gem_files ||= all_files.reject{ |f|
122
- f =~ ignored_pattern && !git_files.include?(f)
236
+ f =~ submodules_pattern ||
237
+ (f =~ ignored_pattern && !git_files.include?(f))
123
238
  }
124
239
  end
125
240
 
@@ -151,6 +266,15 @@ module Gemgem
151
266
  end
152
267
  end
153
268
 
269
+ def submodules_pattern
270
+ @submodules_pattern ||= if submodules.empty?
271
+ /^$/
272
+ else
273
+ Regexp.new(submodules.map{ |path|
274
+ "^#{Regexp.escape(path)}/" }.join('|'))
275
+ end
276
+ end
277
+
154
278
  def expand_patterns pathes
155
279
  # http://git-scm.com/docs/gitignore
156
280
  pathes.flat_map{ |path|
@@ -173,86 +297,38 @@ namespace :gem do
173
297
 
174
298
  desc 'Install gem'
175
299
  task :install => [:build] do
176
- Gemgem.sh_gem('install', Gemgem.gem_path)
300
+ Gemgem.gem_install
177
301
  end
178
302
 
179
303
  desc 'Build gem'
180
304
  task :build => [:spec] do
181
- require 'fileutils'
182
- require 'rubygems/package'
183
- gem = nil
184
- Dir.chdir(Gemgem.dir) do
185
- gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
186
- FileUtils.mkdir_p(Gemgem.pkg_dir)
187
- FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
188
- end
189
- puts "\e[35mGem built: \e[33m" \
190
- "#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
305
+ Gemgem.gem_build
191
306
  end
192
307
 
193
308
  desc 'Generate gemspec'
194
309
  task :spec do
195
- Gemgem.create
196
- Gemgem.write
310
+ Gemgem.gem_spec
197
311
  end
198
312
 
199
313
  desc 'Release gem'
200
314
  task :release => [:spec, :check, :build] do
201
- Gemgem.module_eval do
202
- sh_git('tag', Gemgem.gem_tag)
203
- sh_git('push')
204
- sh_git('push', '--tags')
205
- sh_gem('push', Gemgem.gem_path)
206
- end
315
+ Gemgem.gem_release
207
316
  end
208
317
 
209
318
  task :check do
210
- ver = Gemgem.spec.version.to_s
211
-
212
- if ENV['VERSION'].nil?
213
- puts("\e[35mExpected " \
214
- "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
215
- exit(1)
216
-
217
- elsif ENV['VERSION'] != ver
218
- puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
219
- "\e[35mbut got\n " \
220
- "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
221
- exit(2)
222
- end
319
+ Gemgem.gem_check
223
320
  end
224
321
 
225
322
  end # of gem namespace
226
323
 
227
324
  desc 'Run tests'
228
325
  task :test do
229
- next if Gemgem.test_files.empty?
230
-
231
- require 'bacon'
232
- Bacon.extend(Bacon::TestUnitOutput)
233
- Bacon.summary_on_exit
234
- Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
326
+ Gemgem.test
235
327
  end
236
328
 
237
329
  desc 'Trash ignored files'
238
330
  task :clean => ['gem:spec'] do
239
- next if Gemgem.ignored_files.empty?
240
-
241
- require 'fileutils'
242
- trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
243
- puts "Move the following files into:" \
244
- " \e[35m#{Gemgem.strip_path(trash)}\e[33m"
245
-
246
- Gemgem.ignored_files.each do |file|
247
- from = "#{Gemgem.dir}/#{file}"
248
- to = "#{trash}/#{File.dirname(file)}"
249
- puts Gemgem.strip_path(from)
250
-
251
- FileUtils.mkdir_p(to)
252
- FileUtils.mv(from, to)
253
- end
254
-
255
- print "\e[0m"
331
+ Gemgem.clean
256
332
  end
257
333
 
258
334
  task :default do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-bgrep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-29 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem-grep
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.2
19
+ version: 0.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.2
26
+ version: 0.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.6.4
85
+ rubygems_version: 2.6.13
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Can't find some codes from your app? gem-bgrep let you grep from your Gemfile.