Tuesday, January 29, 2008

Ruby + CRT - a couple of quick examples

I've been tinkering with this here and there over the last couple of days for something at work. CRT (and SecureCRT) are able to hosting ActiveX script engines which make them great for automating a lot of tasks. Their documentation states that you can use VBScript and JScript (and teases with some PerlScript on their website), but I wanted to use Ruby simply because the project this is for is otherwise totally in Ruby. I didn't want to have to switch gears from Ruby to VBScript unless I just really had to.

For now, here are a couple of quick examples.

login.rb - this is simply a rewrite of a PerlScript example they have on their website. Except in Ruby.

bcbstn_download.rb- a script that connects to an insurance payer BBS (in this case BCBS of Tennessee) and downloads all available files. There is more work that I have to do here, but this shows usage of ActiveRecord to lookup various values from a database. I call this from the command line in a form like:
crt /script bcbstn_download.rb /arg 1

The arg is the ID of a record in the database... I won't go into that, but just know that ActiveRecord works from within these scripts. However, there are a couple of things.
  1. I have to use set_table_name within the ActiveRecord class definition even when the underlying table follows the normal ActiveRecord naming convention. It refused to work without it.
  2. Associations (has_and_belongs_to_many, etc...) do not seem to be working. I haven't had a chance to investigate this yet. And yes I know that the example script doesn't contain any of these associations. I took them out for now.

I'll be posting some more information as I get a chance to work on this more.]

0 comments:

Post a Comment