[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] Saikuro v0.2 Released

Zev Blut

12/13/2006 1:10:00 PM

Saikuro is a Ruby cyclomatic complexity analyzer.

http://saikuro.rub...

When given Ruby source code Saikuro will generate a report listing the
cyclomatic complexity of each method found. In addition, Saikuro
counts the number of lines per method and can generate a listing of
the number of tokens on each line of code.

Usage:
Saikuro is a command line program.
Running "saikuro -h" will output a usage statement describing all
the various arguments you can pass it.

"saikuro -c -p tests/samples.rb"

The above command is a simple example that generates a cyclomatic
complexity report on the samples.rb file, using the default filter,
warning and error settings. The report is saved in the current
directory.

Changes:
=3Dv0.2
* Adding setup.rb installer
* Fixing an infinite loop that the lexer goes into if a file is
missing a newline at the end.

Note:
Ruby 1.8.5 has a bug in ri_options that will prevent Saikuro from
running. If you are using 1.8.5 please apply this patch :
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/rdoc/ri/ri...
rb.diff?r1=3D1.2.2.13;r2=3D1.2.2.14

Any feedback is appreciated.

Thanks,
Zev

4 Answers

Eric Hodel

12/13/2006 11:06:00 PM

0

On Dec 13, 2006, at 08:09, Zev Blut wrote:

> Saikuro is a Ruby cyclomatic complexity analyzer.
>
> http://saikuro.rub...
>
> When given Ruby source code Saikuro will generate a report listing the
> cyclomatic complexity of each method found. In addition, Saikuro
> counts the number of lines per method and can generate a listing of
> the number of tokens on each line of code.

Where's the gem?

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Zev Blut

12/14/2006 3:14:00 AM

0

On Thu, 14 Dec 2006 08:05:37 +0900, Eric Hodel <drbrain@segment7.net>
wrote:

> On Dec 13, 2006, at 08:09, Zev Blut wrote:
>
>> Saikuro is a Ruby cyclomatic complexity analyzer.
>
> Where's the gem?


My attempts to make a gem have failed. I think because Saikuro wants
to be installed as an application in /bin. I can put my current
gemspec up on SVN if you want to show me what I am doing wrong.

Thanks,
Zev

Alex Fenton

12/14/2006 8:38:00 AM

0

Zev Blut wrote:

> My attempts to make a gem have failed. I think because Saikuro wants
> to be installed as an application in /bin.

Take a look at the 'executables' setting within the gemspec

http://rubygems.org/read/chapter/20#e...

This will install the listed executable files into the bin directory where the ruby executable is, which will commonly be in PATH (eg /usr/local/bin)

a

Zev Blut

12/15/2006 2:33:00 AM

0

On Thu, 14 Dec 2006 17:40:06 +0900, Alex Fenton =

<alex@deleteme.pressure.to> wrote:

> Zev Blut wrote:
>
>> My attempts to make a gem have failed. I think because Saikuro wants=

>> to be installed as an application in /bin.
>
> Take a look at the 'executables' setting within the gemspec
>
> http://rubygems.org/read/chapter/20#e...
>
> This will install the listed executable files into the bin directory =

> where the ruby executable is, which will commonly be in PATH (eg =

> /usr/local/bin)

Yes thank you I have already looked into this.

It appears I have made two mistakes when it comes to using RubyGems.

I did use the executables option, but I am not sure it was designed to
work the way I wrote Saikuro. Here are the two problems:

1)
Saikuro uses the "if __FILE__ =3D=3D $0" check before doing the
"application work". When RubyGems creates a new gemified saikuro
wrapper to call the real saikuro bin "$0" is the gemified saikuro and
not the real one. Thus, by default nothing happens.

For fun I cheated and commented out the "if __FILE__" check and
replaced it with "if true". I then ran "saikuro -?" to get a usage
message and found the next problem:

2)
I was reading through the Programming Ruby book and found a part that
showed how to use rdoc to create usage messages. I figured this might
be better than my normal technique so I used it in saikuro. This has
caused a number of problems actually.

* With the above cheat I get the gem message:
--
/usr/bin/saikuro: invalid option -- ?
This file was generated by RubyGems.

The application 'Saikuro' is installed as part of a gem, and this file
is here to facilitate running it.
--

Which is not the usage message I wanted.

* Part two is only somewhat related to gems but also a bug in Ruby
1.8.5 's rdoc API that makes this actually give an error due to it
not being able to require an options file. This is fixed in the
Ruby head, but not in the official release.

So I am wondering what is the best practice for this?

I could always separate saikuro into a lib and bin file. The bin file
will not do the if __FILE__ check. This should then work with
RubyGems, but of course I need to drop the rdoc usage technique.

My original goal was to keep saikuro simple so that as a single file
nothing complicated was needed. But now I suppose that should change.

Here is my basic gemspec file if someone wants to show me a better
technique.

----------------------------------------------------------------------
require 'rubygems'

spec =3D Gem::Specification.new do |s|
s.name =3D "Saikuro"
s.version =3D "1.0.0"
s.author =3D "Zev Blut"
s.homepage =3D "http://saikuro.rubyforge....
s.rubyforge_project =3D 'saikuro'
s.platform =3D Gem::Platform::RUBY
candidates =3D Dir.glob("{bin,tests}/**/*")
s.files =3D candidates.delete_if do |item|
item.include?(".svn") || item.include?("rdoc")
end
s.executables =3D ['saikuro']
s.has_rdoc =3D true
s.extra_rdoc_files =3D ["README"]
end

if __FILE__ =3D=3D $0
Gem::manage_gems
Gem::Builder.new(spec).build
end
----------------------------------------------------------------------


Thanks,
Zev
=