Wolfmans Howlings

A programmers Blog about Ruby, Rails and a few other issues

Experiences with Komodo Pro and Ruby

Posted by Jim Morris Thu, 10 Aug 2006 05:39:00 GMT

I got a license for Komodo Pro, (Komodo-Professional-3.5.3-262321-linux-libcpp5-x86) and started trying to use it, I have the latest KUbuntu, with GTK installed so I had no problems installing Komodo as far as libraries and requirements were concerned, however running it had me stumped, I ran into immediate problems (some of my own making I'll admit).

First I saw a stream of errors on the screen, they didn't seem fatal but are annoying, for instance...

(Gecko:24458): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_width: assertion `pixbuf != NULL' failed
(Gecko:24458): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_height: assertion `pixbuf != NULL' failed
(Gecko:24458): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_rowstride: assertion `pixbuf != NULL' failed
(Gecko:24458): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
(Gecko:24458): Gdk-CRITICAL **: gdk_pixbuf_get_from_drawable: assertion `gdk_window_is_viewable (src)' failed

For a commercial product costing around $299 that seemed a little unnecessary.

The first problem was my making I launched Komodo from the command line in the installation directory, then deleted the installation directory, which caused it to have hysterics about chdir etc, although to be honest an xwindows IDE probably shouldn't care where it is launched from, as it would normally be launched from a button or desktop icon.

Tech support was very fast in responding to my email though, and they didn't even know I had a pro license. They asked a bunch of questions, which I answered, but seeing as the remaining problems were non-fatal I wasn't too concerned about the response, which I haven't got yet, but I would like to know if all those GTK errors are normal.

The more disturbing problem was when I tried to write a simple Ruby script, I expected completion as you would see with Java and Eclipse, but instead typing:

str= ""
str.

gave me an error:

 error determining members: don't know how to make a suitable dumb_get_members for Ruby

This error was what I got at first, after going back and typing str. again I got the expected list of possible completions, seems this happens the first time every time, either it is slow figuring out what to complete or it is very buggy. (Update see later, it is the former, it is slow figuring out what type something is).

Time.

Did give me a list of completions most times. When it does decide to offer a list of completions, it also shows the parameters for the calls, like Eclipse/Java does, that's nice, I hope it is reliable though.

OK got word back from tech support, apparently it can take "a couple of seconds" for Komodo to catch up with typing, so my example of...

str= ""
str.

Would probably not work unless I waited a few seconds between the two lines, I think this may be acceptable as it is unlikely to be an issue in normal use. In practice it seems to be more than a couple of seconds BTW.

The main reason for me trying Komodo was for the code completion, without intelligent code completions I really don't see the use for an IDE, I can use my trusty Epsilon editor from Lugaru, with the ruby syntax highlighting and formatting extensions and my own contribution to the Epsilon library snippets, much like the great Textmate snippets (although not nearly as complete), there are also various user contributed extensions for various source code code control systems etc here.

Yes Epsilon is quite expensive for an editor, but I have been using it for nearly 20 years, upgrading every few years or so, it is basically Emacs with a c-like extension language (instead of lisp), it is very solid, and runs on all the platforms I use (Mac OS/X, Windows and of course Linux). It does not have code completion of course (although I think I can write an extension ala Vim7 to do that, watch this space).

Maybe I should mention what I am looking for in an IDE for Ruby and Rails...

I want:

  • syntax highlighting
  • auto indentation
  • auto-correction (or at least error highlighting, or suggestions)
  • snippets (or templates)
  • code completion (showing the possible methods for a variable called intellisense or intelligent code completion by some)
  • word completion based on something in the source already, or from a tags list or from a known-word list
  • showing the parameters for a given method I am currently typing
  • full debugging (with breakpoints, watches, stepping and variable examination)
  • SCCM integration (subversion, CVS, perforce)

Basically everything I get when I use Eclipse and Java.

I get some of this with Epsilon, and Textmate but they are not IDEs so do not have debugging or code completion, or error detection.

Back to Komodo...

It has Perforce, CVS and Subversion bindings built-in, and does show the files status in the project view.

The auto-indent works nicely, unlike RadRails which I tried but just didn't get along with as I kind of expect it to be as good as Java and Eclipse, but my main complaint is it doesn't even auto-indent. (I think intentionally).

The syntax highlighting in Komodo is OK but not great, I think that can be tweaked, but I haven't looked that closely.

The debugging does seem to work well, you can set breakpoints, and step over, into and watch variables, everything you would expect. This may be worth the price of admission (YMMV).

It does show you highlighting when it detects errors as you type, within the limitation of Ruby syntax.

The Snippets implementation is pathetic compared to Textmate or Eclipse, you can't specify tab stops, you can't type the trigger word for a snippet and have it expanded on TAB, you have to either bind it to a key sequence, or double click the snippet name in the toolbox, that is simply clunky, and pretty much unusable. There are *NO* built-in snippets, you have to create them all yourself, so if you like typing "for" then tab and have a for loop created forget it, unless you create it yourself then you have to find the "for" snippet in the toolbox and double click it. I also couldn't find any on the web, I think for the price of this product they should supply most of the expected snippets. The other thing I don't like is the snippets will pop up a dialog box asking for input, instead of the usual way of just highlighting the text and typing over it to replace it.

My initial impressions is the editor part is clunky, given the excellent examples of Eclipse and Textmate, it simply doesn't compare as far as modern editing conveniences such as snippets are concerned.

The debugging seems capable, and probably the best I have seen for Ruby.

The code completion is slow and doesn't always work.

The source code control seems a little buggy in some places, although only from a UI standpoint. (Pops up strange dialog boxes on updates saying files need to be added, when they don't).

A serious bug is if the file changes on disk, (like if you do a revert), you get a dialog popping up saying the file has changed on disk, but you can't get it to go away, clicking OK just pops it up again, ad infinitum, you need to kill the program to move on.

All in all I think this would be a nice IDE if it were free, and the personal version may well be useful for some if you want decent debugging, but I simply can't see a justification for $299 for the pro-version. (At least not for this version). There is an alpha for the next version that claims to support Rails development, if they also fix the snippets and the code completion (which they have not in the current alpha), then we may be getting close to value for the money, but right now I think they have a long long way to go before this product justifies the price tag, and comes close to competing with the few other editors out there let alone IDEs.

Update

Tech support have been very responsive, and they came up with a macro that inserts snippets almost the way I expect,

komodo.view.setFocus();
try {
    komodo.editor.vCHomeExtend();
    var snippet = komodo.interpolate('%s');
    var tmpl = komodo.findPart("snippet", snippet, "container");
    if(tmpl) {
        Snippet_insert(tmpl);
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}

Add this as a macro, bind it to a key (say ALT-=), and then add your snippets to the same folder as the macro is in, name them appropriately, and the type im the name hit ALT-= and the snippiet is found and inserted, pretty neat.

Disclaimer: These are my personal opinions, I am not affiliated with any editor or IDE manufacturers.

Posted in ,  | Tags , , , , ,  | 1 comment | no trackbacks

metaWeblog api in typo fails on some posts

Posted by Jim Morris Sun, 04 Jun 2006 06:32:00 GMT

I was using a ruby script to post my blogs from the command line, and it used the xmlrpc/client which would occasionally fail with this error…

/usr/local/lib/ruby/1.8/xmlrpc/client.rb:546:in `do_rpc': HTTP-Error: 500 Internal Server Error  (RuntimeError)
    from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:420:in `call2'
    from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:410:in `call'
    from send2blog.rb:103

This was annoying, so I did some sleuthing and it turns out there were various apparently unrelated bugs posted about this in the typo trac, and in rails. I noticed it seemed to be fixed in Rails edge so I found the patch and applied it locally to my typo’s version of rails, and now I can post all my blogs from the command line again.

The problem was with posts containing && or << etc which seeing as I was posting a lot of ruby code most of my blogs had.

  • The relevant ticket is #538
  • The relevant rails ticket is #4955

The fix is a one line addition to vendor/rails/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb on line 48 the patch is…

Index: actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
===================================================================
--- actionpack/lib/action_controller/cgi_ext/cgi_methods.rb     (revision 4324)
+++ actionpack/lib/action_controller/cgi_ext/cgi_methods.rb     (working copy)
@@ -45,6 +45,7 @@
       parsed_params = {}

       for key, value in params
+        next if key.nil?
     value = [value] if key =~ /.*[]$/
     unless key.include?('[')
       # much faster to test for the most common case first (GET)

This seems to work for rails versions >= 1.0, although it is already patched in edge rails.

Posted in ,  | Tags ,  | 1 comment | no trackbacks

Capistrano deploy from local repository

Posted by Jim Morris Sat, 27 May 2006 00:08:00 GMT

UPDATE 2006-12-06 I have replaced this with a full blown SCM module that works much better, see this posting

It seems that many people are in the same position as I was, they want to deploy to a remote server farm that does not have access to the SCCM (subversion,CVS,perforce etc), which is usually behind a corporate firewall.

The following recipe overcomes this by checking out the source code from the local repository (using svn in this case) and goes into your deploy.rb.

What it does is checkout the latest copy of the application from your local subversion repository, tars it up, and copies the tar file to the remote server, then detars it and does the normal deploy tasks from then on.

desc <<DESC
Update all servers with the latest release of the source code.
This is a modified version that copies a local copy to the remote site
DESC

task :update_code, :roles => [:app, :db, :web] do
    on_rollback { delete release_path, :recursive => true }

    #puts "doing my update_code"
    temp_dest= "tmp_code"

    #puts "...get a local copy of the code into #{temp_dest} from local svn"
    # but this could also just be your local development folder
    system("svn export -q #{configuration.repository} #{temp_dest}")

    #puts "...tar the folder"
    # you could exclude files here that you don't want on your production server
    system("tar -C #{temp_dest} -c -z -f code_update.tar.gz .")

    #puts "...Sending tar file to remote server"
    put(File.read("code_update.tar.gz"), "code_update.tar.gz")

    #puts "...detar code on server"
    run <<-CMD
        mkdir -p #{release_path} &&
        tar -C #{release_path} -x -z -f code_update.tar.gz &&
        rm -rf code_update.tar.gz &&
        rm -rf #{release_path}/log #{release_path}/public/system &&
        ln -nfs #{shared_path}/log #{release_path}/log &&
        ln -nfs #{shared_path}/system #{release_path}/public/system
    CMD

    #puts "...cleanup"
    system("rm -rf #{temp_dest} code_update.tar.gz")
end

This recipe does what many people need todo which is replace the database.yml with the production version, and also repalces the .htaccess with the production version (YMMV)

desc "fix up database and .htaccess"
task :after_update_code do
  run "cp #{release_path}/config/database.yml.templ #{release_path}/config/database.yml"
  run "cp #{release_path}/public/dot.htaccess.deploy #{release_path}/public/.htaccess"
end

Posted in ,  | Tags , , ,  | no comments | no trackbacks

Create Rails ActiveRecord Models from DDL

Posted by Jim Morris Thu, 25 May 2006 06:20:00 GMT

I had a database with about 60 tables in it, most where simple lookup tables with simple has_many and belongs_to relationships, and I didn't want to manually create all the models, with the associations by hand. I googled around and came across Bill Katz's dbmodel, which takes the output of dbdesigner and creates the models with the relationships. However I already had the Databases and schema setup, and I didn't have (and couldn't find) a copy of dbdesigner to use. So I hacked Bills dbmodel to read a DDL file that was created from the command rake db:structure:dump, as I was using Postgresql this file had all the relevant relationship info in it plus a bit extra.

I added the ability to create the relationships that had non standard table names and foreign keys, and also added some validations to the created models.

By default all relationships are created as has_many (and belongs_to), and tables can have multiple belongs_to referencing the same table so long as the foreign keys are different. Also models are created for every table found in the DDL.

I also added an yaml file as an override so you can specify habtm and has_one relationships too.

There are two files to this modification, a hacked version of the original dbmodel.rb and a new file which encapsulates the parsing of the DDL file. The main changes to the original dbmodel.rb consists of removing the parsing of the original xml file and reading the changes from a modified hash of the tables and associations.

The new ddl.rb file handles the parsing of the DDL file, and building a hash of data for the tables, with their associations and validations. It also reads the YAML file that overides the association types.

You can get a zip of the two files from this link ddl2model.zip.

Both files need to be in the same directory and it is run from the command line, the yaml override being in the same directory as the dbmodel.rb script. The ddl file to be processed is given on the command line.

The YAML file assocs.yml is used to tell the ddl.rb script about relations that are anything other than has_many, so:

extable1:
   - {:assoc: has_one, :ref: extable2, :column: extable1_id}
   - {:assoc: has_one, :ref: extable3, :column: extable1_id}
   - {:assoc: habtm, :ref: extable1_extable2, :column: extable1_id}
extable2:
   - {:assoc: habtm, :ref: extable1_extable2, :column: extable2_id}

Tells the parser that the model for a table named extable1 should create a has_one relation for extable2 using the foreign key extable1_id. Ditto for extable3.

It also specifies that the model for extable2 has a habtm relationship using the join table extable1_extable2 using foreign key extable1_id. Note that the habtm override needs to be specified for both tables, in this case extable2 also has a habtm override.

You can also ignore a table with this:

table3: []

will ignore the table called table3.

Lastly the generator will add validate_presence_of based on any NOT NULL constraints found on the column DDL.

Update

A better solution to this problem has been provided here http://db-discovery.rubyforge.org/

Posted in ,  | Tags , ,  | 5 comments | no trackbacks

Older posts: 1 ... 8 9 10 11