Ruby

Ruby is used for some utility functions and (soon) for SNUG modules.

For simplicity, the base installation of Ruby is covered in it’s own book

Installation

Getting Ruby

For SCO, we obtain the source and do a custom installation.

The source code is available from The Ruby Home

At the time of writing the current version of Ruby is 1.8.2 As a normal user, get and extract the Ruby source tarball.
bash-2.03$ wget ftp://ruby-lang.org/pub/ruby/ruby-1.8.2.tar.gz
bash-2.03$ tar xvzf ruby-1.8.2.tar.gz
bash-2.03$ cd ruby-1.8.2

Compile and Install

To avoid some warnings, missing.h can be edited as follows (i.e. make the extern definition of isinf unconditional), although not necessary. If you do not make this edit, you can ignore the warnings about isinf being redefined.

/*
#ifndef HAVE_ISINF
# if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
# define isinf(x) (!finite(x) && !isnan(x))
# else
*/
extern int isinf _((double));
/*
# endif
#endif
*/

It is also necessary to adjust ext/curses/Makefile by removing the -ltinfo flag from the linking option. Whilst this allows the compile to proceed, I do not know if it breaks anything which uses the curses extention. I guess we’ll cross that bridge if it happens.

Now we are ready to compile ruby.
bash-2.03$ ./configure --enable-install-doc --enable-shared \
LDSHARED="gcc -shared -W1,B=export" 
<<snip>>
creating config.h
configure: creating ./config.status
config.status: creating Makefile
bash-2.03$ make
bash-2.03$ make test
<<snip>>
test succeeded
bash-2.03$ sudo make install
bash-2.03$ ruby -v
ruby 1.8.2 (2004-12-25) [i686-sco3.2v5.0.7]

So, even though it took me over 30 billable (non-chargeable) hours to get this right, you have now successfully installed ruby 1.8.2 on SCO Openserver in just a few minutes!

Note that all of these steps are done as a normal user. sudo is required only for the actual installation step.

Now we need to add a few libraries which will make life easier and allow development of our local software.

Additional Libraries

The key library we will install is Rubygems. In fact this is more than just a library as it performs a similar function to CPAN for perl.

rubygems

Get a version of rubygems from RubyForge, extract it somehere and run sudo ruby setup.rb in its directory.

Rubygems assumes that /usr/bin/env is available to locate ruby in script files. On SCO Openserver, env is in /bin so a quick soft link will save problems later.

Then make sure that your gems are updated (internet access required).
bash-2.03$ sudo ln -s /bin/env /usr/bin/env
bash-2.03$ sudo gem update --system
Upgrading RubyGems...
<<snip>>
  Successfully built RubyGem
  Name: sources
  Version: 0.0.1
  File: sources-0.0.1.gem
RubyGems system software updated
bash-2.03$

SQLite

We make extensive use of SQLite for Nomad support functions so we will install the Ruby/SQLite bindings.
bash-2.03# gem install sqlite3
Attempting local installation of 'sqlite3'
Local gem file not found: sqlite3*.gem
Attempting remote installation of 'sqlite3'
Select which gem to install for your platform (i686-sco3.2v5.0.6)
 1. sqlite3-ruby 1.1.0 (ruby)
 2. sqlite3-ruby 1.1.0 (mswin32)
 3. sqlite3-ruby 1.0.1 (ruby)
 4. sqlite3-ruby 1.0.1 (mswin32)
 5. sqlite3-ruby 1.0.0 (mswin32)
 6. sqlite3-ruby 1.0.0 (ruby)
 7. sqlite3-ruby 0.9.0 (ruby)
 8. sqlite3-ruby 0.9.0 (mswin32)
 9. sqlite3-ruby 0.6.0 (ruby)
 10. sqlite3-ruby 0.5.0 (ruby)
 11. Cancel installation
> 1
Building native extensions.  This could take a while...
ruby extconf.rb install sqlite3
checking for sqlite3.h... yes
checking for sqlite3_open() in -lsqlite3... yes
creating Makefile

make

make install
Successfully installed sqlite3-ruby-1.1.0
Installing RDoc documentation for sqlite3-ruby-1.1.0...

lib/sqlite3/database.rb:637:65: Skipping require of \
  dynamic string: "sqlite3/driver/#{driver.to_s.downcase}/driver" 

lib/sqlite3/database.rb:642:59: Skipping require of 
  dynamic string: "sqlite3/driver/#{d.downcase}/driver" 
bash-2.03#

You must then run the following test program, which will fail and tell you to edit @/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/drive r/dl/api.rb@

require 'rubygems'
require 'sqlite3'
db = SQLite3::Database.new('/tmp/test.db')
rows = db.execute('select * from test')

Add the following lines to the file.

      when /sco3/
        "/usr/local/lib/libsqlite3.so" 

ActiveRecord

Binding Ruby Objects to SQLite3 tables is a breeze with ActiveRecord. Install using gem install activerecord

bash-2.03# gem install activerecord
Attempting local installation of 'activerecord'
Local gem file not found: activerecord*.gem
Attempting remote installation of 'activerecord'
Install required dependency activesupport? [Yn]  y
Successfully installed activerecord-1.10.1
Successfully installed activesupport-1.0.4
Installing RDoc documentation for activerecord-1.10.1...
Installing RDoc documentation for activesupport-1.0.4...
bash-2.03#

Documentation

RDoc

The alert reader would have noticed that whenever we install a Rubygem, we are told that …
Installing RDoc documentation for <name of gem here>

What does this mean, and how can you see the documentation?

The answer is simple really, just start the documentation server (if it isn’t already running) and point your browser at port 8808 on the machine where the server is running.
bash-2.03# gem_server
[2005-06-22 23:34:50] INFO  WEBrick 1.3.1
[2005-06-22 23:34:50] INFO  ruby 1.8.2 (2004-12-25) \
[i686-sco3.2v5.0.6]
[2005-06-22 23:34:50] INFO  WEBrick::HTTPServer#start: \
pid=17870 port=8808

Hey, ain’t Ruby cool? Comes with its own web server (webrick).

The index page of your Ruby gems documentation looks like this …

Rake

Background

Rake is the pure Ruby “make” tool which is used for compiling NPP and other functions. It is installed as a Rubygem as with gem install rake. The current version is 0.5.4.

In addition to traditional “make” type uses, rake can be used to automate all sorts of functions. It has the advantage that its Rakefile (Makefile in make terms) is pure Ruby code and has great flexibility. We use it for testing automation.

Full documentation is available locally provided the gem_server is running. Otherwise refer to the On-line version.

This chapter summarises some of the more common features that we use in real life!

SWF Development

Introduction

Ruby is being used in various different parts of the overall Nomad environment. This Chapter sets out how the SWF replacement module for SNUG is setup and tested.

Set Up

The source is held in its own CVS module. Get a working copy
[nigelb@nnlbak nigelb]$ cd src
[nigelb@nnlbak src]$ export \
 CVSROOT=":pserver:nigelb@enesbe.com.au:/wk/cvs" 
[nigelb@nnlbak src]$cvs checkout swf
cvs server: Updating swf            
U swf/.cvsignore                    
U swf/.project                      
U swf/snug.schema                   
U swf/swi-2990-16170                
U swf/swrf.rb                       
U swf/swrf.schema                   
U swf/tbl.txt                       
U swf/test.rb                       
U swf/test.txt                      
cvs server: Updating swf/lib        
U swf/lib/parser.rb                 
U swf/lib/snug.rb                   
[nigelb@nnlbak src]$         
For testing we require an “empty” snug database (i.e. one with just the configuration table loaded). This can be created by taking a copy of a live database and then run the snug utility reset.sh.