P4Ruby: Ruby interface to the Perforce API |
So, what's it all about? Well in a nutshell P4Ruby allows you to write beautiful Ruby code that interacts with a Perforce server. The main features are:
Writing Ruby code is a joy for all programmers, and P4Ruby makes that experience available to Perforce users. Enjoy it!
This extension is distributed under the terms of this license, which is a BSD-like license. You use it at your own risk.
FreeBSD users can just use pkg_add to install ruby as there's a FreeBSD port for it.
Windows users can download a Windows installer for Ruby from http://rubyinstaller.rubyforge.org/wiki/wiki.pl They can also grab a P4Ruby installer from the links below - useful if you don't have Visual Studio installed. If you do this, then obviously you don't need to do any of the other build steps.
Otherwise you can download the source for Ruby from http://www.ruby-lang.org which is the main Ruby home page.
If you chose to use the Windows installer then the process ends here. You're ready to start using P4Ruby. What follows is only applicable to those building P4Ruby from source.
See the Porting section below to help you find the right Perforce API build for your platform.
Then go to the Perforce download site and grab the p4api.tar file for your platform. Try to get the latest available release, but certainly no older than 2001.1.
Extract the files in the p4api.tar tarfile (WinZip can handle it for Windows users) into a new empty directory and remember its location.
Follow the build instructions in P4Ruby's README file.
Release Type | Source Code | API Version | Installer (Ruby 1.6.x) | Installer (Ruby 1.8.x) |
---|---|---|---|---|
Current | P4Ruby.tar.gz | Latest | p4ruby-main-1.6.8-setup.exe | p4ruby-main-1.8.2-setup.exe |
Latest Stable | P4Ruby-1.5953.tar.gz | 2007.2 | p4ruby-1.5953-1.6.8-setup.exe | p4ruby-1.5953-1.8.2-setup.exe |
Source Code | Installer (Ruby 1.6.x) | Installer (Ruby 1.8.x) |
---|---|---|
P4Ruby-1.5768.tar.gz | p4ruby-1.5768-1.6.8-setup.exe | p4ruby-1.5768-1.8.2-setup.exe |
P4Ruby-1.4841.tar.gz | p4ruby-1.4841-1.6.8-setup.exe | p4ruby-1.4841-1.8.0-setup.exe |
P4Ruby-1.4809.tar.gz | p4ruby-1.4809-1.6.8-setup.exe | p4ruby-1.4809-1.8.0-setup.exe |
P4Ruby-1.4251.tar.gz | p4ruby-1.4251-1.6.8-setup.exe | p4ruby-1.4251-1.8.0-setup.exe |
P4Ruby-1.3578.tar.gz | p4ruby-1.3578-1.6.8-setup.exe | p4ruby-1.3578-1.8.0-setup.exe | P4Ruby-1.1750.tar.gz (first stable release) | (None) | (None) |
To find out what's changed, read the change log.
require "P4" template = "my-client-template" client_root = "c:\\p4-work" p4 = P4.new p4.parse_forms p4.connect begin # Run a "p4 client -t template -o" and convert it into a Ruby hash spec = p4.fetch_client( "-t", template ) # Now edit the fields in the form spec[ "Root" ] = client_root spec[ "Options" ] = spec[ "Options" ].sub( "normdir", "rmdir" ) # Now save the udpated spec p4.save_client( spec ) # And sync it. p4.run_sync rescue P4Exception # If any errors occur, we'll jump in here. Just log them # and raise the exception up to the higher level p4.errors.each { |e| $stderr.puts( e ) } raise end
P4Ruby has been built on at least the following platforms:
Note that P4Ruby is compatible with older versions of Ruby and the Perforce API, so on older platforms you should still be able to get a working build.
If you get "unresolved symbol" errors when building or running P4Ruby, you probably used the wrong compiler or the wrong Perforce API build.
Thanks to Dave Thomas and Andy Hunt at The Pragmatic Programmers for their superb book and kindly giving me permission to use the funky Ruby image at the top of this page.
And of course, thanks to Matz for Ruby.