GT.M binding to Ruby

 

GT.M binding to Ruby

 

logo

M is both a language and a database. Just like with most other popular NoSQL databases it is useful to be able to access M from many different languages, even though using it from the M language might be the preferred approach. Bindings to other languages make the M database available to a larger number of applications and facilitates the growth of a larger community.

 

A Ruby module has now been created to make possible to use GT.M from Ruby scripts.

This Ruby module builds upon the gtm_cip C-API of GT.M.

It wraps the C API into a C++ class, that in turn is wrapped with SWIG for Ruby.

 

Details of this Ruby binding for GT.M are available in this article in the OSEHRA Technical Journal.

 

http://code.osehra.org/journal/browse/publication/28

 

Note that this provides only the GT.M bindings for Ruby.
It is expected that GT.M will already be installed in the target system.

 

After installing the gtm Ruby module, you still have to proceed with the two following post-installation steps

 

A) Set the GTMCI environment variable to the full path of the gtm_access.ci file.

B) Copy the _gtmaccess.m file in to one of the directories where you have M routines. These directories are the ones that you already include in the gtmroutines environment variable.

C) Add to your LD_LIBRARY_PATH environment variable the directory where you installed GT.M.

More precisely, the directory where the GT.M library

                           libgtmshr.so

is currently located. This will make possible for the Ruby binding to find the GT.M shared library when you run Ruby scripts. This directory is what you would typically have in the "gtm_dist" environment variable.

 

 

Once you have completed the post-installation, you can try some of the tests available at

 

https://github.com/OSEHRA-Sandbox/gtm-bindings/tree/master/Testing

 

For example, start Ruby code such as:

 

require "./gtm"

db = Gtm::GTM.new()

print db.version()

print db.about()

 

Then follow with more interesting code, such as:

 

require "./gtm"

db = Gtm::GTM.new()

globalName = '^Capital("US")'

setValue = 'Washington'

db.set( globalName, setValue )

globalName = '^Capital("UK")'

setValue = 'London'

db.set( globalName, setValue )

getValue = db.order( globalName )

puts "Order of ", globalName, " = ", getValue

getValue = db.query( globalName )

puts "Query of ", globalName, " = ", getValue

db.execute( 'write $ZVERSION,!')

db.kill('^Capital')

 

 

Enjoy GT.M from Ruby !

 

Groups:

Comments

luisibanez

This has now been packaged as

This has now been packaged as a Ruby Gem.

You can find it at:

                 https://rubygems.org/gems/gtm

The Github repository has been updated accordingly:

https://github.com/OSEHRA-Sandbox/gtm-bindings/commit/f913b7e157f20338ef1d50849f931ca30c7a13a4
https://github.com/OSEHRA-Sandbox/gtm-bindings/tree/master/Wrapping/RubyGemPackage

You should now be able to install it by simply typing:

                    gem   install   gtm

Note that this command will only install the bindings for gtm.

You must still install GT.M the usual way.

Please let us know if you find any issues with this Gem package.

 

Thanks to Tyler Kiley for his help and guidance on how to create a Gem package.