[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to search Ruby files in Windows

Chris Gehlker

8/22/2006 5:03:00 PM

Sometimes you want to find some particular code snippet and all you
know is that it is in some file in a given directory. For example, if
you are reading the Pickaxe book and you want to actually run some
example code, all you know a priori is that it is somewhere in
ex0001.rb through ex1608.rb. I use a Mac and the wonderful Spotlight
Ruby Importer available at:
<http://www.arcadianvision...
makes it trivial to find a file containing any given code snippet. I
have a friend who uses Windows and she doesn't know how to achieve
the same functionality. I've tried running RDoc on the directory
containing the Pickaxe code but it quits because it only works on
file that actually compile.

So all this is simply to ask: What is the Windows equivalent to the
Spotlight Ruby Importer.

--
A young idea is a beautiful and a fragile thing. Attack people, not
ideas.


6 Answers

Chris Gehlker

8/22/2006 6:35:00 PM

0


On Aug 22, 2006, at 10:30 AM, Phrogz wrote:

> The Windows Way might be to use the Find command (Windows-F) and enter
> content type in "A word or phrase in the file". Bleah.
>
> What I do is use my little "findfile" ruby script (code below) from
> the
> command line. It's sort of like a grep utility that allows you to use
> regexps as a filter for file names, and as a content searcher. For
> example
>
> C:\Documents and Settings\gavin.kistner\Desktop>findfile rbw?$ "def
> \S+awl"
> ./ReArchive/Archive/dircrawl.rb
> def self.crawl ( path, level=0 )
>
> Found 1 file (out of 7510) in 2.765 seconds
>

Thanks Phrogz, I'll pass it on right now.
--
Conscience is thoroughly well-bred and soon leaves off talking to
those who do not wish to hear it.
-Samuel Butler, writer (1835-1902)




Jim Weirich

8/22/2006 7:03:00 PM

0

Phrogz wrote:
> What I do is use my little "findfile" ruby script (code below) from the
> command line. It's sort of like a grep utility that allows you to use
> regexps as a filter for file names, and as a content searcher. For

I have a little script called "fic" ... "Find In Code". Here it is:

#!/usr/bin/env ruby
require 'rake'
FileList["**/*.rb"].egrep(Regexp.new(ARGV.first))

-- Jim Weirich

--
Posted via http://www.ruby-....

Reid Thompson

8/22/2006 11:00:00 PM

0

Chris Gehlker wrote:
> Sometimes you want to find some particular code snippet and all you
> know is that it is in some file in a given directory. For example, if
> you are reading the Pickaxe book and you want to actually run some
> example code, all you know a priori is that it is somewhere in
> ex0001.rb through ex1608.rb. I use a Mac and the wonderful Spotlight
> Ruby Importer available at:
> <http://www.arcadianvision...
> makes it trivial to find a file containing any given code snippet. I
> have a friend who uses Windows and she doesn't know how to achieve the
> same functionality. I've tried running RDoc on the directory
> containing the Pickaxe code but it quits because it only works on file
> that actually compile.
>
> So all this is simply to ask: What is the Windows equivalent to the
> Spotlight Ruby Importer.
>
> --
> A young idea is a beautiful and a fragile thing. Attack people, not
> ideas.
>
>
I use cygwin (www.cygwin.com) and something like:
( mod to your liking, or make different versions for different needs)

cyberhome: /home/rthompso/bin>
$ cat greprb
if [ $# = 1 ]
then
dir=.
echo "dir is $dir"
else if [ $# = 2 ]
then
dir=$2
echo "dir is $dir"
else
echo "Usage: 'basename $0' pattern [path]"
echo "don't forget to quote patterns with spaces"
echo "\n"
exit 1
fi
fi

find $dir -type f -name \*.rb -exec grep -l "$1" {} \; -exec grep -n
"$1" {} \; -exec echo " " \;
==============================================================================
Example output ( filepath and line of occurance ):

$ greprb require .
dir is .
/.vim/plugin/snippetMagic/convert.rb
3:require 'rexml/document'
4:require 'rexml/streamlistener'
5:require 'yaml'
7:require 'snippet_set'

/.vim/plugin/snippetMagic/snippets/php.rb
11: - require_once(..) (req1)
12: - "require_once( '${1:file}' );$0"
69: - require(..) (req)
70: - "require( '${1:file}' );$0"

/.vim/plugin/snippetMagic/snippets/propel.rb
16: - "<column name=\"${1:name}\" type=\"${2:type}\"${3:
required=\"${4:true}\"}${5:
20: - "<column name=\"${1:id}\" type=\"${2:integer}\" required=\"true\"

/.vim/plugin/snippetMagic/snippet_set.rb
1:require 'yaml'
39: # make sense to require installation of the gem for a vim plugin.

/client.rb
2:require "socket"

/date.rb
1:require 'date'

/dbtest.rb
1:require 'dbi'

/eXPlainPMT-20060408.0/app/controllers/application.rb
38: before_filter :require_team_membership
70: # This method can be used as a before_filter for actions which
should require
75: def require_admin_privileges
87: def require_team_membership
123: def require_current_project
132: flash[:error] = "You attempted to access a view that requires
a " +

/eXPlainPMT-20060408.0/app/controllers/iterations_controller.rb
22: before_filter :require_current_project

/eXPlainPMT-20060408.0/app/controllers/milestones_controller.rb
22: before_filter :require_current_project, :except =>
[:milestones_calendar]



Chris Gehlker

8/22/2006 11:32:00 PM

0


On Aug 22, 2006, at 12:03 PM, Jim Weirich wrote:

> I have a little script called "fic" ... "Find In Code". Here it is:
>
> #!/usr/bin/env ruby
> require 'rake'
> FileList["**/*.rb"].egrep(Regexp.new(ARGV.first))

That's pretty cool too.
--
No matter how far you have gone on the wrong road, turn back.
-Turkish proverb


David Vallner

8/24/2006 9:04:00 PM

0

Phrogz wrote:
> The Windows Way might be to use the Find command (Windows-F) and enter
> content type in "A word or phrase in the file". Bleah.

Actually, I think Windowsen have a document indexing service hidden
somewhere. Hard to believe it wouldn't do as much as fulltext document
indexing. And it's also probably extensible if you know the proper hand
motions and undocumented API calls. Maybe.

Buggered if I know how to get it to work, and the last time I let the
system index hard drive contents, it hogged the drives to no end. But it
is a hint to Windows hackers that would find this an interesting problem
to solve.

David Vallner

Austin Ziegler

8/25/2006 3:40:00 AM

0

On 8/24/06, David Vallner <david@vallner.net> wrote:
> Actually, I think Windowsen have a document indexing service hidden
> somewhere. Hard to believe it wouldn't do as much as fulltext document
> indexing. And it's also probably extensible if you know the proper hand
> motions and undocumented API calls. Maybe.

Not a good one. Use Google Desktop, or Yahoo Desktop, or MSN Desktop.

I use the former, when I'm on Windows.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca