# Saikuro v0.2 Released

**URL:** <https://www.ruby-forum.com/t/saikuro-v0-2-released/79231>\
**Category:** Ruby\
**Created:** [December 13, 2006, 2:10pm UTC](https://www.ruby-forum.com/t/saikuro-v0-2-released/79231 "2006-12-13T14:10:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zev\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb8c5e/32.png) [@Zev\_B](https://www.ruby-forum.com/u/Zev_B)\
**Post date:** [December 13, 2006, 2:10pm UTC](https://www.ruby-forum.com/t/saikuro-v0-2-released/79231/1 "2006-12-13T14:10:18Z")

</div>

Saikuro is a Ruby cyclomatic complexity analyzer.

[http://saikuro.rubyforge.org](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](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

---

<div class="post-metadata">

**Author:** ![Zev\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb8c5e/32.png) [@Zev\_B](https://www.ruby-forum.com/u/Zev_B)\
**Post date:** [December 14, 2006, 12:06am UTC](https://www.ruby-forum.com/t/saikuro-v0-2-released/79231/2 "2006-12-14T00:06:12Z")

</div>

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

> Saikuro is a Ruby cyclomatic complexity analyzer.
> 
> [http://saikuro.rubyforge.org](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. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)

I LIT YOUR GEM ON FIRE!

---

<div class="post-metadata">

**Author:** ![Zev\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb8c5e/32.png) [@Zev\_B](https://www.ruby-forum.com/u/Zev_B)\
**Post date:** [December 14, 2006, 4:14am UTC](https://www.ruby-forum.com/t/saikuro-v0-2-released/79231/3 "2006-12-14T04:14:38Z")

</div>

On Thu, 14 Dec 2006 08:05:37 +0900, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![Zev\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb8c5e/32.png) [@Zev\_B](https://www.ruby-forum.com/u/Zev_B)\
**Post date:** [December 14, 2006, 9:41am UTC](https://www.ruby-forum.com/t/saikuro-v0-2-released/79231/4 "2006-12-14T09:41:12Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Zev\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb8c5e/32.png) [@Zev\_B](https://www.ruby-forum.com/u/Zev_B)\
**Post date:** [December 15, 2006, 3:33am UTC](https://www.ruby-forum.com/t/saikuro-v0-2-released/79231/5 "2006-12-15T03:33:52Z")

</div>

On Thu, 14 Dec 2006 17:40:06 +0900, Alex F.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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:

1. 

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:

1. 

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/](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
