gem_grep 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +19 -0
- data/CHANGELOG.rdoc +9 -0
- data/LICENSE.txt +1 -1
- data/README.rdoc +3 -7
- data/Rakefile +23 -39
- data/deps.rip +1 -0
- data/lib/gem_grep.rb +71 -0
- data/lib/gem_grep/version.rb +3 -0
- data/lib/rubygems/commands/grep_command.rb +8 -21
- data/lib/rubygems/super_search.rb +3 -2
- metadata +42 -20
- data/VERSION.yml +0 -4
data/.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems' unless Object.const_defined?(:Gem)
|
3
|
+
require File.dirname(__FILE__) + "/lib/gem_grep/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "gem_grep"
|
7
|
+
s.version = GemGrep::VERSION
|
8
|
+
s.authors = ["Gabriel Horner"]
|
9
|
+
s.email = "gabriel.horner@gmail.com"
|
10
|
+
s.homepage = "http://github.com/cldwalker/gem_grep"
|
11
|
+
s.summary = "A gem command plugin which enhances the search command by providing extra search options and displaying results as a table."
|
12
|
+
s.description = 'Enhances search command by displaying results in an ascii table and providing options to search (--fields) and display (--columns) gemspec attributes. These options take any gemspec attribute and more than one when comma delimited. Gemspec attributes can be aliased by specifying the first unique string that it starts with i.e. "su" for "summary".'
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
14
|
+
s.rubyforge_project = 'tagaholic'
|
15
|
+
s.add_dependency 'hirb'
|
16
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
|
17
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
18
|
+
s.license = 'MIT'
|
19
|
+
end
|
data/CHANGELOG.rdoc
ADDED
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ Enhances search command by displaying results in an ascii table and providing op
|
|
6
6
|
|
7
7
|
Install the gem with:
|
8
8
|
|
9
|
-
|
9
|
+
sudo gem install gem_grep
|
10
10
|
|
11
11
|
== Examples
|
12
12
|
|
@@ -135,14 +135,10 @@ gem grep can also search inside gemspec attributes that are arrays i.e. @depende
|
|
135
135
|
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
|
136
136
|
10 rows in set
|
137
137
|
|
138
|
-
== Bugs/
|
138
|
+
== Bugs/Issues
|
139
139
|
|
140
140
|
Please submit tickets through {github's issue tracker}[http://github.com/cldwalker/gem_grep/issues].
|
141
141
|
|
142
|
-
==
|
142
|
+
== Todo
|
143
143
|
|
144
144
|
* Tests!
|
145
|
-
|
146
|
-
== LICENSE
|
147
|
-
|
148
|
-
See LICENSE.txt
|
data/Rakefile
CHANGED
@@ -1,51 +1,35 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
begin
|
5
|
-
require 'rcov/rcovtask'
|
2
|
+
require 'fileutils'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
t.test_files = FileList['test/**/*_test.rb']
|
10
|
-
t.rcov_opts = ["-T -x '/Library/Ruby/*'"]
|
11
|
-
t.verbose = true
|
12
|
-
end
|
13
|
-
rescue LoadError
|
14
|
-
puts "Rcov not available. Install it for rcov-related tasks with: sudo gem install rcov"
|
4
|
+
def gemspec
|
5
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
15
6
|
end
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
|
29
|
-
s.add_dependency 'cldwalker-hirb'
|
30
|
-
s.rubyforge_project = 'tagaholic'
|
31
|
-
end
|
8
|
+
desc "Build the gem"
|
9
|
+
task :gem=>:gemspec do
|
10
|
+
sh "gem build .gemspec"
|
11
|
+
FileUtils.mkdir_p 'pkg'
|
12
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Install the gem locally"
|
16
|
+
task :install => :gem do
|
17
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
|
18
|
+
end
|
32
19
|
|
33
|
-
|
34
|
-
|
20
|
+
desc "Generate the gemspec"
|
21
|
+
task :generate do
|
22
|
+
puts gemspec.to_ruby
|
35
23
|
end
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
t.verbose = false
|
25
|
+
desc "Validate the gemspec"
|
26
|
+
task :gemspec do
|
27
|
+
gemspec.validate
|
41
28
|
end
|
42
29
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
desc 'Run tests'
|
31
|
+
task :test do |t|
|
32
|
+
sh 'bacon -q -Ilib -I. test/*_test.rb'
|
49
33
|
end
|
50
34
|
|
51
35
|
task :default => :test
|
data/deps.rip
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hirb >=0
|
data/lib/gem_grep.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/super_search'
|
3
|
+
require 'zlib'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'gem_grep/version'
|
6
|
+
|
7
|
+
module GemGrep
|
8
|
+
extend self
|
9
|
+
attr_accessor :grep_fields, :display_fields
|
10
|
+
def grep_fields
|
11
|
+
@grep_fields ||= ['name', 'description', 'summary']
|
12
|
+
end
|
13
|
+
|
14
|
+
def display_fields
|
15
|
+
@display_fields ||= [:name,:summary,:authors]
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_gemspec_columns
|
19
|
+
@valid_gemspec_columns ||= Gem::Specification.attribute_names.map {|e| e.to_s}.sort
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_input(input)
|
23
|
+
input.split(/\s*,\s*/).map {|e|
|
24
|
+
valid_gemspec_columns.detect {|c| c =~ /^#{e}/ }
|
25
|
+
}.compact
|
26
|
+
end
|
27
|
+
|
28
|
+
class Index
|
29
|
+
attr_accessor :server
|
30
|
+
def initialize(server)
|
31
|
+
@server = server
|
32
|
+
setup_marshal_index unless File.exists?(marshal_file)
|
33
|
+
end
|
34
|
+
|
35
|
+
def gem_server
|
36
|
+
{:rubygems=>"http://rubygems.org", :github=>"http://gems.github.com"}
|
37
|
+
end
|
38
|
+
|
39
|
+
def gem_index
|
40
|
+
@gem_index ||= begin
|
41
|
+
puts "Loading large gem index. Patience is a bitch ..."
|
42
|
+
spec_hash = Hash[*Marshal.load(File.read(marshal_file)).flatten]
|
43
|
+
Gem::SourceIndex.new(spec_hash).extend(Gem::SuperSearch)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_marshal_index(name=nil)
|
48
|
+
server = name if name
|
49
|
+
download_marshal_index unless File.exists?(marshal_compressed_file)
|
50
|
+
File.open(marshal_file, 'w') {|f| f.write Zlib::Inflate.inflate(File.read(marshal_compressed_file)) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def download_marshal_index
|
54
|
+
puts "Downloading compressed Marshal gemspec index to ~/.gem_grep. Patience is a bitch..."
|
55
|
+
FileUtils.mkdir_p("~/.gem_grep")
|
56
|
+
system("curl #{marshal_url} > #{marshal_compressed_file}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def marshal_file
|
60
|
+
File.expand_path "~/.gem_grep/marshal_#{server}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def marshal_compressed_file
|
64
|
+
File.expand_path "~/.gem_grep/marshal_#{server}.Z"
|
65
|
+
end
|
66
|
+
|
67
|
+
def marshal_url
|
68
|
+
gem_server[server] + "/Marshal.#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}.Z"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,28 +1,20 @@
|
|
1
1
|
require 'rubygems/commands/query_command'
|
2
2
|
require 'rubygems/super_search'
|
3
3
|
require 'hirb'
|
4
|
+
require 'gem_grep'
|
4
5
|
|
5
6
|
class Gem::Commands::GrepCommand < Gem::Commands::QueryCommand
|
6
|
-
|
7
|
-
def valid_gemspec_columns
|
8
|
-
@valid_gemspec_columns ||= Gem::Specification.attribute_names.map {|e| e.to_s}.sort
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
7
|
+
attr_accessor :results, :results_only
|
12
8
|
def initialize
|
13
9
|
super 'grep', "Enhances search command by providing extra search options and displaying results as a table"
|
14
10
|
defaults.merge!(:columns=>[:name,:summary,:authors])
|
15
11
|
|
16
12
|
add_option('-c', '--columns STRING', 'Gemspec columns/attributes to display per gem') do |value, options|
|
17
|
-
options[:columns] =
|
18
|
-
self.class.valid_gemspec_columns.detect {|c| c =~ /^#{e}/ }
|
19
|
-
}.compact.map {|e| e.to_sym}
|
13
|
+
options[:columns] = GemGrep.parse_input(value).map {|e| e.to_sym}
|
20
14
|
end
|
21
15
|
|
22
16
|
add_option('-f', '--fields STRING', 'Gemspec fields/attributes to search (only for local gems)') do |value, options|
|
23
|
-
options[:fields] =
|
24
|
-
self.class.valid_gemspec_columns.detect {|c| c =~ /^#{e}/ }
|
25
|
-
}.compact
|
17
|
+
GemGrep.grep_fields = options[:fields] = GemGrep.parse_input(value)
|
26
18
|
end
|
27
19
|
remove_option '--name-matches'
|
28
20
|
remove_option '-d'
|
@@ -45,7 +37,7 @@ class Gem::Commands::GrepCommand < Gem::Commands::QueryCommand
|
|
45
37
|
'Enhances search command by providing options to search (--fields) and display (--columns) ' +
|
46
38
|
'gemspec attributes. Results are displayed in an ascii table. Gemspec attributes can be specified '+
|
47
39
|
'by the first unique string that it starts with i.e. "su" for "summary". To specify multiple gemspec attributes, delimit ' +
|
48
|
-
"them with commas. Gemspec attributes available to options are: #{
|
40
|
+
"them with commas. Gemspec attributes available to options are: #{GemGrep.valid_gemspec_columns.join(', ')}."
|
49
41
|
end
|
50
42
|
|
51
43
|
def execute
|
@@ -56,14 +48,9 @@ class Gem::Commands::GrepCommand < Gem::Commands::QueryCommand
|
|
56
48
|
end
|
57
49
|
|
58
50
|
def output_query_results(tuples)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
val = e[0][-1].send(c)
|
63
|
-
h[c] = val.is_a?(Array) ? val.join(',') : val; h
|
64
|
-
}
|
65
|
-
}
|
66
|
-
say Hirb::Helpers::Table.render(records, :fields=>options[:columns])
|
51
|
+
@results = cleanup_tuples(tuples).map {|e| e[0][-1]}
|
52
|
+
@results_only ? @results :
|
53
|
+
say(Hirb::Helpers::Table.render(@results, :fields=>options[:columns]))
|
67
54
|
end
|
68
55
|
|
69
56
|
# borrowed from query command
|
@@ -33,8 +33,9 @@ module Gem::SuperSearch
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# only changes from original method
|
36
|
-
search_fields = Gem::CommandManager.instance['grep'].options[:fields] || ['name']
|
37
|
-
|
36
|
+
# search_fields = Gem::CommandManager.instance['grep'].options[:fields] || ['name']
|
37
|
+
search_fields = GemGrep.grep_fields
|
38
|
+
specs = all_gems.values.select do |spec|
|
38
39
|
search_fields.map {|e| spec.send(e).to_s}.any? {|e| e =~ gem_pattern} and
|
39
40
|
version_requirement.satisfied_by? spec.version
|
40
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_grep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Gabriel Horner
|
@@ -9,19 +15,23 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-09-11 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
name: hirb
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
25
35
|
description: Enhances search command by displaying results in an ascii table and providing options to search (--fields) and display (--columns) gemspec attributes. These options take any gemspec attribute and more than one when comma delimited. Gemspec attributes can be aliased by specifying the first unique string that it starts with i.e. "su" for "summary".
|
26
36
|
email: gabriel.horner@gmail.com
|
27
37
|
executables: []
|
@@ -29,41 +39,53 @@ executables: []
|
|
29
39
|
extensions: []
|
30
40
|
|
31
41
|
extra_rdoc_files:
|
32
|
-
- LICENSE.txt
|
33
42
|
- README.rdoc
|
34
|
-
files:
|
35
43
|
- LICENSE.txt
|
36
|
-
|
37
|
-
-
|
38
|
-
-
|
44
|
+
files:
|
45
|
+
- lib/gem_grep/version.rb
|
46
|
+
- lib/gem_grep.rb
|
39
47
|
- lib/rubygems/commands/grep_command.rb
|
40
48
|
- lib/rubygems/super_search.rb
|
41
49
|
- lib/rubygems_plugin.rb
|
50
|
+
- LICENSE.txt
|
51
|
+
- CHANGELOG.rdoc
|
52
|
+
- README.rdoc
|
53
|
+
- deps.rip
|
54
|
+
- Rakefile
|
55
|
+
- .gemspec
|
42
56
|
has_rdoc: true
|
43
57
|
homepage: http://github.com/cldwalker/gem_grep
|
44
|
-
licenses:
|
45
|
-
|
58
|
+
licenses:
|
59
|
+
- MIT
|
46
60
|
post_install_message:
|
47
|
-
rdoc_options:
|
48
|
-
|
61
|
+
rdoc_options: []
|
62
|
+
|
49
63
|
require_paths:
|
50
64
|
- lib
|
51
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
52
67
|
requirements:
|
53
68
|
- - ">="
|
54
69
|
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
55
73
|
version: "0"
|
56
|
-
version:
|
57
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
58
76
|
requirements:
|
59
77
|
- - ">="
|
60
78
|
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
79
|
+
hash: 23
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 3
|
83
|
+
- 6
|
84
|
+
version: 1.3.6
|
63
85
|
requirements: []
|
64
86
|
|
65
87
|
rubyforge_project: tagaholic
|
66
|
-
rubygems_version: 1.3.
|
88
|
+
rubygems_version: 1.3.7
|
67
89
|
signing_key:
|
68
90
|
specification_version: 3
|
69
91
|
summary: A gem command plugin which enhances the search command by providing extra search options and displaying results as a table.
|
data/VERSION.yml
DELETED