gem_grep 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2009 Gabriel Horner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,148 @@
1
+ == Description
2
+
3
+ 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".
4
+
5
+ == Install
6
+
7
+ Install the gem with:
8
+
9
+ gem source -a http://gems.github.com && sudo gem install cldwalker-gem_grep
10
+
11
+ == Examples
12
+
13
+ If you want to choose what gemspec attributes (columns) you see in your results, no problem. Pass a
14
+ comma delimited list to --columns/-c in the order you want to see them. For any gemspec attribute, you can pass its alias which is the first unique string that it starts with.
15
+
16
+ # n,ho,da are shortcuts for name,homepage,date
17
+ bash> gem grep -c n,ho,da irb
18
+
19
+ *** LOCAL GEMS ***
20
+
21
+ +----------------+-------------------------------------------------+--------------------------------+
22
+ | name | homepage | date |
23
+ +----------------+-------------------------------------------------+--------------------------------+
24
+ | cldwalker-hirb | http://github.com/cldwalker/hirb | Thu Mar 12 00:00:00 -0400 2009 |
25
+ | irb_callbacks | http://rubysideshow.rubyforge.org/irb_callbacks | Tue May 13 00:00:00 -0400 2008 |
26
+ | irb_rocket | http://blog.s21g.com/genki | Sat Feb 07 00:00:00 -0500 2009 |
27
+ | sirb | http://github.com/davidrichards/sirb | Sun Mar 22 00:00:00 -0400 2009 |
28
+ | wirble | http://pablotron.org/software/wirble/ | Fri Sep 08 00:00:00 -0400 2006 |
29
+ +----------------+-------------------------------------------------+--------------------------------+
30
+ 5 rows in set
31
+
32
+ Choosing your columns works for remote gems as well.
33
+
34
+ bash> gem grep console -r -c n,ho,des
35
+
36
+ *** REMOTE GEMS ***
37
+
38
+ +---------------------------+---------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+
39
+ | name | homepage | description |
40
+ +---------------------------+---------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+
41
+ | CapConsole | http://handle.rubyforge.org | This adds a new capistrano task called console:shell which, when run, opens a script/console shell on your remote pro... |
42
+ | cldwalker-console_update | http://github.com/cldwalker/console_update | A rails plugin which allows you to edit your database records via the console and your favorite editor. |
43
+ | Console | http://www.nebulargauntlet.org | |
44
+ | jtrupiano-timecop-console | http://github.com/jtrupiano/timecop-console | |
45
+ | live_console | http://debu.gs/live-console | |
46
+ | mongrel_console | | Provides a combined Mongrel and Rails IRB console. |
47
+ | simpleconsole | http://simpleconsole.rubyforge.org | |
48
+ | takai-twitty-console | http://github.com/takai/twitty-console/ | TwittyConsole is a console based client for Twitter. |
49
+ | timecop-console | http://github.com/jtrupiano/timecop-console | |
50
+ | win32console | http://rubyforge.org/projects/winconsole | This gem packages Gonzalo Garramuno's Win32::Console project, and includes a compiled binary for speed. The Win32::Co... |
51
+ +---------------------------+---------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+
52
+ 10 rows in set
53
+
54
+ For <b>local gems only</b>, you get increased searching ability with --fields/-f. Pass it a comma delimited list of gemspec attributes you want to search on, aliased as shown above. Let's see my gems that were created/authored by jamis:
55
+
56
+ bash> gem grep jamis -f a
57
+
58
+ *** LOCAL GEMS ***
59
+
60
+ +-----------------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
61
+ | name | summary | authors |
62
+ +-----------------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
63
+ | capistrano | Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH. | Jamis Buck |
64
+ | needle | Needle is a Dependnjection/Inversion of Control container for Ruby. It supports (constructor) i... | Jamis Buck |
65
+ | net-scp | A pur | Net::SFTP is a pure-Ruby implementation of the SFTP c | Jamis Buck |
66
+ | net-ation of the SSH2 client protocol. Buck |
67
+ | net-ssh-gateway | A simple library to assist in esta | to allow Ruby scripts to interface with a SQLite3 database. | Jamis Buck |
68
+ | syntax | Syntax is Ruby library for performing simple syntax highlighting. | Jamis Buck |
69
+ +-----------------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
70
+ 8 rows in set
71
+
72
+ As already mentioned, you can search multiple attributes. Let's search for irb inside gemspec attributes name, description and summary:
73
+
74
+ bash> gem grep irb -f n,su,des
75
+
76
+ *** LOCAL GEMS ***
77
+
78
+ +-----------------------+----------------------------------------------------------------------------------------------------------+------------------------------+
79
+ | name | summary | authors |
80
+ +-----------------------+----------------------------------------------------------------------------------------------------------+------------------------------+
81
+ | cldwalker-hirb | A mini view framework for irb that's easy to use, even while under its influence. | Gabriel Horner |
82
+ | irb_callbacks | Adds three callbacks to the prompt, eval, and output phases of irb | Mike Judge |
83
+ | irb_rocket | irb plugin that makes irb #=> rocket | Genki Takiuchi |
84
+ | matthew-method_lister | Pretty method listers and finders, for use in IRB. | Matthew O'Connor |
85
+ | rtags | rtags is a Ruby replacement for ctags - allowing for name navigation in source code using vim, emacs ... | Pjotr Prins, Keiju Ishitsuka |
86
+ | sirb | Descriptive statistics + IRB + any other useful numerical library you may have around | David Richards |
87
+ | utility_belt | A grab-bag of IRB power user madness. | Giles Bowkett |
88
+ | wirble | Handful of common Irb features, made easy. | Paul Duncan |
89
+ +-----------------------+----------------------------------------------------------------------------------------------------------+------------------------------+
90
+
91
+ Like the default search and query commands, grep converts your search term to a regular expression. Let's use this to find out my gems that were created from 2000-2005. Hopefully not too many.
92
+
93
+ bash> gem grep 200[0-5] -f da -c n,da,su
94
+
95
+ *** LOCAL GEMS ***
96
+
97
+ +-------------+--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
98
+ | name | date | summary |
99
+ +-------------+--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
100
+ | dnssd | Thu Oct 07 00:00:00 -0400 2004 | DNS Service Discovery (aka Rendezvous) API for Ruby |
101
+ | extensions | Thu Dec 09 00:00:00 -0500 2004 | 'extensions' is a set of extensions to Ruby's built-in classes. It gathers common idioms, useful additions, and aliases, comp... |
102
+ | mysql | Sun Oct 09 00:00:00 -0400 2005 | MySQL/Ruby provides the same functions for Ruby programs that the MySQL C API provides for C programs. |
103
+ | needle | Fri Dec 23 00:00:00 -0500 2005 | Needle is a Dependency Injection/Inversion of Control container for Ruby. It supports both type-2 (setter) and type-3 (constru... |
104
+ | Platform | Thu Dec 01 00:00:00 -0500 2005 | Hopefully robust platform sensing |
105
+ | RedCloth | Thu Sep 15 00:00:00 -0400 2005 | RedCloth is a module for using Textile and Markdown in Ruby. Textile and Markdown are text formats. A very simple text format... |
106
+ | stemmer | Wed Apr 20 00:00:00 -0400 2005 | Word stemming algorithm(s) |
107
+ | syntax | Sat Jun 18 00:00:00 -0400 2005 | Syntax is Ruby library for performing simple syntax highlighting. |
108
+ | termios | Fri Sep 24 00:00:00 -0400 2004 | Termios module are simple wrapper for termios(3). It can be included into IO-family classes and can extend IO-family objects. ... |
109
+ | text-format | Fri Jun 24 00:00:00 -0400 2005 | Text::Format formats fixed-width text nicely. |
110
+ | text-hyphen | Mon Dec 20 00:00:00 -0500 2004 | Multilingual word hyphenation according to modified TeX hyphenation pattern files. |
111
+ | tree | Thu Dec 29 00:00:00 -0500 2005 | Ruby implementation of the Tree data structure. |
112
+ +-------------+--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
113
+ 12 rows in set
114
+
115
+
116
+ gem grep can also search inside gemspec attributes that are arrays i.e. @dependencies@. Let's see my gems that depend on rake:
117
+
118
+ bash> gem grep rake -f dep -c n,dep
119
+
120
+ *** LOCAL GEMS ***
121
+
122
+ +---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
123
+ | name | dependencies |
124
+ +---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
125
+ | bones | rake (>= 0.8.3, runtime) |
126
+ | echoe | rake (>= 0, runtime),rubyforge (>= 1.0.0, runtime),highline (>= 0, runtime) |
127
+ | ferret | rake (> 0.0.0, runtime) |
128
+ | hoe | rubyforge (>= 1.0.1, runtime),rake (>= 0.8.3, runtime) |
129
+ | launchy | rake (>= 0.8.1, runtime),configuration (>= 0.0.5, runtime) |
130
+ | mislav-hanna | rdoc (~> 2.2.0, runtime),haml (~> 2.0.4, runtime),rake (~> 0.8.2, runtime),echoe (>= 0, runtime) |
131
+ | mocha | rake (>= 0, runtime) |
132
+ | rails | rake (>= 0.7.2, runtime),activesupport (= 1.4.4, runtime),activerecord (= 1.15.6, runtime),actionpack (= 1.13.6, runtime),actionmailer (=... |
133
+ | red | ParseTree (~> 2.2.0, runtime),rake (~> 0.8.3, runtime),newgem (>= 1.0.6, development),hoe (>= 1.8.0, development) |
134
+ | www-delicious | rake (>= 0.8, development),echoe (>= 3.1, development),mocha (>= 0.9, development) |
135
+ +---------------+----------------------------------------------------------------------------------------------------------------------------------------------+
136
+ 10 rows in set
137
+
138
+ == Bugs/Tickets
139
+
140
+ Please submit tickets through {github's issue tracker}[http://github.com/cldwalker/gem_grep/issues].
141
+
142
+ == TODO
143
+
144
+ * Tests!
145
+
146
+ == LICENSE
147
+
148
+ See LICENSE.txt
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ begin
5
+ require 'rcov/rcovtask'
6
+
7
+ Rcov::RcovTask.new do |t|
8
+ t.libs << 'test'
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"
15
+ end
16
+
17
+ begin
18
+ require 'jeweler'
19
+ Jeweler::Tasks.new do |s|
20
+ s.name = "gem_grep"
21
+ 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".'
22
+ s.summary = "A gem command plugin which enhances the search command by providing extra search options and displaying results as a table."
23
+ s.email = "gabriel.horner@gmail.com"
24
+ s.homepage = "http://github.com/cldwalker/gem_grep"
25
+ s.authors = ["Gabriel Horner"]
26
+ s.has_rdoc = true
27
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
28
+ s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
29
+ s.add_dependency 'cldwalker-hirb'
30
+ s.rubyforge_project = 'tagaholic'
31
+ end
32
+
33
+ rescue LoadError
34
+ puts "Jeweler not available. Install it for jeweler-related tasks with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
35
+ end
36
+
37
+ Rake::TestTask.new do |t|
38
+ t.libs << 'lib'
39
+ t.pattern = 'test/**/*_test.rb'
40
+ t.verbose = false
41
+ end
42
+
43
+ Rake::RDocTask.new do |rdoc|
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = 'test'
46
+ rdoc.options << '--line-numbers' << '--inline-source'
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
50
+
51
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 1
4
+ :major: 0
@@ -0,0 +1,90 @@
1
+ require 'rubygems/commands/query_command'
2
+ require 'rubygems/super_search'
3
+ require 'hirb'
4
+
5
+ class Gem::Commands::GrepCommand < Gem::Commands::QueryCommand
6
+ class<<self
7
+ def valid_gemspec_columns
8
+ @valid_gemspec_columns ||= Gem::Specification.attribute_names.map {|e| e.to_s}.sort
9
+ end
10
+ end
11
+
12
+ def initialize
13
+ super 'grep', "Enhances search command by providing extra search options and displaying results as a table"
14
+ defaults.merge!(:columns=>[:name,:summary,:authors])
15
+
16
+ add_option('-c', '--columns STRING', 'Gemspec columns/attributes to display per gem') do |value, options|
17
+ options[:columns] = value.split(/\s*,\s*/).map {|e|
18
+ self.class.valid_gemspec_columns.detect {|c| c =~ /^#{e}/ }
19
+ }.compact.map {|e| e.to_sym}
20
+ end
21
+
22
+ add_option('-f', '--fields STRING', 'Gemspec fields/attributes to search (only for local gems)') do |value, options|
23
+ options[:fields] = value.split(/\s*,\s*/).map {|e|
24
+ self.class.valid_gemspec_columns.detect {|c| c =~ /^#{e}/ }
25
+ }.compact
26
+ end
27
+ remove_option '--name-matches'
28
+ remove_option '-d'
29
+ remove_option '--versions'
30
+ end
31
+
32
+ def arguments # :nodoc:
33
+ "REGEXP regular expression string to search specified gemspec attributes"
34
+ end
35
+
36
+ def usage # :nodoc:
37
+ "#{program_name} [REGEXP]"
38
+ end
39
+
40
+ def defaults_str # :nodoc:
41
+ "--local --columns name,summary,authors --fields name --no-installed"
42
+ end
43
+
44
+ def description # :nodoc:
45
+ 'Enhances search command by providing options to search (--fields) and display (--columns) ' +
46
+ 'gemspec attributes. Results are displayed in an ascii table. Gemspec attributes can be specified '+
47
+ '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: #{self.class.valid_gemspec_columns.join(', ')}."
49
+ end
50
+
51
+ def execute
52
+ string = get_one_optional_argument
53
+ options[:name] = /#{string}/i
54
+ Gem.source_index.extend Gem::SuperSearch
55
+ super
56
+ end
57
+
58
+ def output_query_results(tuples)
59
+ tuples = cleanup_tuples(tuples)
60
+ records = tuples.map {|e|
61
+ options[:columns].inject({:name=>e[0][0]}) {|h,c|
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])
67
+ end
68
+
69
+ # borrowed from query command
70
+ def cleanup_tuples(spec_tuples)
71
+ versions = Hash.new { |h,name| h[name] = [] }
72
+
73
+ spec_tuples.each do |spec_tuple, source_uri|
74
+ versions[spec_tuple.first] << [spec_tuple, source_uri]
75
+ end
76
+
77
+ versions = versions.sort_by do |(name,_),_|
78
+ name.downcase
79
+ end
80
+ tuples = options[:all] ? versions.inject([]) {|t,e| t += e[1]; t } : versions.map {|e| e[1].first }
81
+ tuples.each {|e|
82
+ if e.first.length != 4
83
+ uri = URI.parse e.last
84
+ spec = Gem::SpecFetcher.fetcher.fetch_spec e.first, uri
85
+ e.first.push(spec)
86
+ end
87
+ }
88
+ tuples
89
+ end
90
+ end
@@ -0,0 +1,50 @@
1
+ # Extends Gem::SourceIndex#search to allow searching of any gemspec attribute field.
2
+ # Differs from original method (from rubygems v1.3.2) by a couple of lines.
3
+ module Gem::SuperSearch
4
+ def search(gem_pattern, platform_only = false)
5
+ version_requirement = nil
6
+ only_platform = false
7
+
8
+ # TODO - Remove support and warning for legacy arguments after 2008/11
9
+ unless Gem::Dependency === gem_pattern
10
+ warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
11
+ end
12
+
13
+ case gem_pattern
14
+ when Regexp then
15
+ version_requirement = platform_only || Gem::Requirement.default
16
+ when Gem::Dependency then
17
+ only_platform = platform_only
18
+ version_requirement = gem_pattern.version_requirements
19
+ gem_pattern = if Regexp === gem_pattern.name then
20
+ gem_pattern.name
21
+ elsif gem_pattern.name.empty? then
22
+ //
23
+ else
24
+ /^#{Regexp.escape gem_pattern.name}$/
25
+ end
26
+ else
27
+ version_requirement = platform_only || Gem::Requirement.default
28
+ gem_pattern = /#{gem_pattern}/i
29
+ end
30
+
31
+ unless Gem::Requirement === version_requirement then
32
+ version_requirement = Gem::Requirement.create version_requirement
33
+ end
34
+
35
+ # only changes from original method
36
+ search_fields = Gem::CommandManager.instance['grep'].options[:fields] || ['name']
37
+ specs = @gems.values.select do |spec|
38
+ search_fields.map {|e| spec.send(e).to_s}.any? {|e| e =~ gem_pattern} and
39
+ version_requirement.satisfied_by? spec.version
40
+ end
41
+
42
+ if only_platform then
43
+ specs = specs.select do |spec|
44
+ Gem::Platform.match spec.platform
45
+ end
46
+ end
47
+
48
+ specs.sort_by { |s| s.sort_obj }
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :grep
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_grep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Horner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-25 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cldwalker-hirb
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ 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
+ email: gabriel.horner@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE.txt
33
+ - README.rdoc
34
+ files:
35
+ - LICENSE.txt
36
+ - README.rdoc
37
+ - Rakefile
38
+ - VERSION.yml
39
+ - lib/rubygems/commands/grep_command.rb
40
+ - lib/rubygems/super_search.rb
41
+ - lib/rubygems_plugin.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/cldwalker/gem_grep
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
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
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: tagaholic
66
+ rubygems_version: 1.3.2
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A gem command plugin which enhances the search command by providing extra search options and displaying results as a table.
70
+ test_files: []
71
+