Deployable project with C source code

R

Ruby Rubyruby

Hi. Ruby novice here. So far, I have had a great experience
programming Ruby where I have only been relying on the standard library.
Lately, I have been wanting to tie some of my tools into a nice GUI
using QT or Tk. I understand that running "ruby extconf.rb" will
dynamically generate a Makefile for me based on my OS, and that I run
that in order to compile and clean up my code. I also understand that
the source code that is provided would extend my Ruby API in order to
access lower level code that would enable me to access these C libraries
as objects in Ruby. What I fail to understand is how to make a project
that relies on such souce code easily deployable. For example, if I
were writing something that only relied on the Ruby standard library,
all I would do is tar up my project with a README saying "type: ruby
main.rb" and it would all work nicely. Now, I want to write something
that will compile code that extends the API if necessary, then clean
everything up and run my main.rb. How do I go about doing such a thing?

In Java, everything gets tied into a .jar file and when you compile it
goes from source->java bytecode. I see the transition from
Ruby->c->binary has a setback of having to do a little bit more work
than you would in Java. I could be wrong though. Any feedback would be
greatly appreciated. Thanks for your time.

-Mr. Rubyruby
 
A

Alex Fenton

Ruby said:
Hi. Ruby novice here. So far, I have had a great experience
programming Ruby where I have only been relying on the standard library.
Lately, I have been wanting to tie some of my tools into a nice GUI
using QT or Tk.
....

What I fail to understand is how to make a project
that relies on such souce code easily deployable.

If I understand you right, you want to create a package that runs your
project application fairly straightforwardly on other machines.

Probably the most popular solution to this is currently
rubyscript2exe[1], which examines your ruby script as it runs, then
creates an executable file (eg an .exe on Windows) which can be
distributed alone to other users to run as if it were a "normal"
compiled binary.

You should also look into tar2rubyscript[2] project, and exerb [3],
which do somewhat similar things, but not quite as simply.

As for packaging a GUI application, it depends on the GUI toolkit you're
using. AFAIK, Qt relies on fairly heavy libs which a user might have to
install separately. wxRuby and fxRuby are very simple to bundle using
rubyscript2exe or exerb. I don't know about TK, but I would imagine it's
fairly easy to include the appropriate dll.

a

[1] http://www.erikveen.dds.nl/rubyscript2exe/index.html
[2] http://www.erikveen.dds.nl/tar2rubyscript/index.html
[3] http://exerb.sourceforge.jp/index.en.html
 
A

Alex Gutteridge

Hi. Ruby novice here. So far, I have had a great experience
programming Ruby where I have only been relying on the standard
library.
Lately, I have been wanting to tie some of my tools into a nice GUI
using QT or Tk. I understand that running "ruby extconf.rb" will
dynamically generate a Makefile for me based on my OS, and that I run
that in order to compile and clean up my code. I also understand that
the source code that is provided would extend my Ruby API in order to
access lower level code that would enable me to access these C
libraries
as objects in Ruby. What I fail to understand is how to make a
project
that relies on such souce code easily deployable.

A correctly packaged gem would be able to do this (depending on
exactly what you want to do), read the Pickaxe book chapters on gems/
extensions for more details. On the other hand you could look at how
_why is packaging Shoes (http://code.whytheluckystiff.net/shoes/).

Alex Gutteridge

Bioinformatics Center
Kyoto University
 
D

David Mark Weiss

OK. I messed up not putting a subjects

Now I have two questions:

First as below:

Is there a way to connect Ruby to an existing database?

For my next project, i want to reproduce an app I did before in Ruby.
I really don't want to export and reimport records from the old db to
a db created by Ruby, as the tutorials always seem to ask you do do.

So, a db with 4 tables and thousands of records.

Second:

How do you format a column when displayed? In another life ...
format="datetime:%m/%d/%y"

Thanks for any suggestions.

Mark Weiss
http://trustthechildren.blogspot.com
 
M

Mark Gallop

Hi David,

What type of database is it eg mysql, sqlite, access? It shouldn't be
necessary to use a database which has been created with Ruby.

Depending on your database structure, ActiveRecord could be a very easy
way to get up and running with Ruby/db's.

There are many other database interfaces for Ruby. Try a search on
rubyforge.org.

Cheers,
Mark
 
D

David Mark Weiss

Your right, I just grabbed an email, responded to it, and changed the
subject and body.

I am happy to start a new thread next time, but may I ask where that
shows up?

Mark
 
D

David Mark Weiss

Mark,

I am running mySQL, innodb. 5.0.24a
I did the install found at http://hivelogic.com/narrative/articles/
ruby-rails-mongrel-mysql-osx
Did the install 2 days ago, so it is pretty current.

How do I use ActiveRecord to connect to an existing DB. ie how do I
configure Active Record to do that?
Or since I should do my part, where can I read about it, and perhaps
figure it out myself, like so many others on the list.

Thanks

Mark Weiss
 
M

Mark Gallop

Mark,

From your first post I got the impression you weren't using Rails. Are
you? If you want to use Rails you will get a ton of help from the Rails
mailing lists:

http://wiki.rubyonrails.org/rails/pages/MailingLists

If you go without Rails, you can easily use activerecord directly from
Ruby. For example....

Given a table called dmImage with fields:

ObjectID -> varchar
location -> varchar

The code would look like:

//---
require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:database => '<your_db_name>',
:host=>'<db_host_name>'
:username => '<db_username>',
:password => <db_password>
)

class Image < ActiveRecord::Base
set_primary_key 'ObjectID'
set_table_name 'dmImage'

end
//---

Now you can do:

"img = Image.find :all" to get a list of all images.

If you are using a database structure which doesn't follow the
activerecord's conventions then you will need to set "set_primary_key"
and "set_table_name" to the appropriate values (as above) for your DB.

Cheers,
Mark
 
R

Ryan Davis

Your right, I just grabbed an email, responded to it, and changed
the subject and body.

I am happy to start a new thread next time, but may I ask where
that shows up?

in threaded mail clients.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top