Saikuro v0.2 Released

Saikuro is a Ruby cyclomatic complexity analyzer.

http://saikuro.rubyforge.org

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:
=v0.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_options.rb.diff?r1=1.2.2.13;r2=1.2.2.14

Any feedback is appreciated.

Thanks,
Zev

On Dec 13, 2006, at 08:09, Zev B. wrote:

Saikuro is a Ruby cyclomatic complexity analyzer.

http://saikuro.rubyforge.org

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 H. - [email protected] - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!

On Thu, 14 Dec 2006 08:05:37 +0900, Eric H. [email protected]
wrote:

On Dec 13, 2006, at 08:09, Zev B. 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

Zev B. 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#executables

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

On Thu, 14 Dec 2006 17:40:06 +0900, Alex F.
[email protected] wrote:

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:

Saikuro uses the “if FILE == $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:

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 = Gem::Specification.new do |s|
s.name = “Saikuro”
s.version = “1.0.0”
s.author = “Zev B.”
s.homepage = “http://saikuro.rubyforge.org/
s.rubyforge_project = ‘saikuro’
s.platform = Gem::Platform::RUBY
candidates = Dir.glob(“{bin,tests}/**/*”)
s.files = candidates.delete_if do |item|
item.include?(“.svn”) || item.include?(“rdoc”)
end
s.executables = [‘saikuro’]
s.has_rdoc = true
s.extra_rdoc_files = [“README”]
end

if FILE == $0
Gem::manage_gems
Gem::Builder.new(spec).build
end

Thanks,
Zev