Make your ruby classes Comparable and Enumerable

Something very cool in ruby are mixins. As the word says mixin is a technique to mixed a module into a class using the statement “include”. While including a module is a very large topic I focused on the opportunity to include module defined in the Ruby standard library into your class to take advantages of the methods and abilities that these modules provide. The Comparable module in ruby define methods like  <   <=   ==   >   >=   between?  . What if I want to achieve is making my class instances comparable so that I can ask to ruby if class_a > class_b. Here an example: <div></div> The Person class include the module Comparable and implements one single method (<=>). This methods is used by the Comparable module to perform the logic of any of the operator that the module provide.In the example I say to the Person class to compare instances through the @name attribute. But we even gain more functionalities. Once that our classes are able to be compared they are also able to be sorted if placed inside an array. Amazing!!!

Ruby instance_eval

Working on one of my first ruby gem I have started to learn more about ruby meta programming and ruby core language. My gem needs a sort of singleton class that needs to be configured when the application starts. I have choosed to use a Module as singleton cause a ruby module cannot be initialized and so it just fits my needs. I will then include the configured module into the model that will need it. What I wanted to achieve was something like: <div></div> I created my module and added 2 class methods one called configure that is planned to take care of the block and a method called set that is going to apply the requested configurations. Something like this: <div></div> If you run this code you get an exception saying to you that: undefined method ‘set’ for main:Object This was a bit confusing at first. The error is thrown cause the block is created outside of the module scope and is executed in the scope where it was created. In this special case the scope is the general Object scope. What I need is that the block passed to the configure method is executed in the scope of My_module. This can be achieved using the instance_eval method. Passing the block as argument to instance_eval this is executed in the current self scope. Exactly what I need. <div></div> In conclusion instance_eval is one of the important topic in ruby meta programming allowing blocks to be sent around and executed in the calling instance scope.

Learning Ruby: gets and chomp

Playing with the ruby console I am wondering how I can read some input from the console. Ruby ships with the method gets that makes easy to read console input. Just try the following code:

Something about bundler and gems dependencies

Since some months I have started to programm in Ruby and especially using the Rails framework. I have to say I find Rails so great that I realized, that after some months, that I can be quite productive knowing very little about Ruby itself. This tells you how powerfull can be a dsl written in Ruby and talks about the nice job Rails developers did but is not going to make me shine as a Ruby developer. I have decided to step back and I am finally going to open a Programming Ruby book seriously. I will go throught my Ruby discovering writing here my tests and anything I will discover in my learning Ruby travel. This will help me to fix some concept in my mind and hopefully someone else will learn from my mistakes.

Railo cfmap addEvent() support

A couple of weeks ago I was reading a post from Raymond Camden that remembered me I completely forgot to add support to addevent() in Railo cfmap implementation. The blog post was quite interesting and showed a way to add streetview to a google map, generated by cfmap, using the Coldfusion.Map.addEvent function. Read the post here. Of course code was not running in Railo due to the lack of the method in the Railo js library.

MongoDb Cache Extension for Railo - New Update

A new update the the MongoDB Cache extension for Railo is on the extension provider.

Some bug was fixed and performance improved by a better tuning of the query that respects the cache expiration timeout. In my tests I could reach 400 interactions ( put and get of 400 items ) in in average time of 1200ms. Pretty awesome!!!!

Railo WebSockets Gateway Extension

I have just uploaded the Railo WebSockets Gateway Extension to the Railo preview extension provider.

This extension enables you to launch a server that is capable to manage messaging from HTML WebSockets.

The server runs on a dedicated port. Railo will receive notifications when a connection is opened, closed and any time a message is sent invoking a cfc listener class. The gateway can also being invoked via SendGatewayMessage so to allow your app to push message to all the connected clients.

While only few browsers natively support WebSockets up to now exists many libraries that mange the failover to flash sockets or other technologies like ajax long polling etc... WebSockets are a great way to implement messaging and data pushing using well known technologies like javascript. The gateway just makes it a breeze pushing data from your Railo application to any connected client.

You can find docs about the extension in the Railo wiki and some sample code cloning the following github repo https://github.com/andreacfm/websockets_example_apps.

Please post any feedback in the Railo Google Group and any bug in the Railo Jira bugtraker.

Railo MongoDB cache extension updated

I have uploaded yesterday a main update of the MongoDB Cache extension for Railo. See installation details here I have improved the management of timespan and timeidle expiring using some incredible feature that MongoDB offers.

Railo Membase Cache Extension available for beta testing.

NorthScale Membase Server is an elastic key-value database that stores web application data far more efficiently and cost effectively than it can be stored in a relational database. With NorthScale Membase Server, organizations can deploy a highly available, cloud-friendly data layer that expands dynamically as application needs change, delivering performance exceeding that of any other NoSQL solution. API compatible with memcached, the de facto standard web caching software, Membase is easy to use and supported by virtually every programming language and application framework.

Membase gives you an easy way to access and use memcached as a key-value database. Membase is a very powerfull solution if you need a reliable, fast and distribuited cache engine.

The Extension allows you to use Membase as a key/value cache for your Objects (components), Templates, Queries and Resources (such as files etc).

More info can be found in the Railo wiki : http://wiki.getrailo.org/wiki/extensions:membase

Railo MongoDB Cache Extension on Beta Test

In these days I am really interested in nosql tools and especially in the  MongoDB  document databse.

What amazes me about mongo is that is much more than a key value pair storage while it expose a quite complete query api, a full indexes support and an atomic Fast-In-Place data update.

Over this MongoDB supports asynchronous replication of data between servers for failover and redundancy. This makes really easy to share and replicate data between a cluster.

The result is that Mongodb is an incredibly fast and flexible document database.

Following what Mark Drew was  doing for CouchDb I thought was a good idea to implement a Railo Cache plugin that bring into Railo world the power of MongoDB used as cache engine.

The extension implements the Railo Cache interface at 100%. This means that you can switch from any other cache that Railo support to MongoDb cache with safety. The driver serialize  any object ( or queries or templates etc... ) you want to cache and will reinflate them up when you need to read them. An index is created over the key of your cache objects so that reading them will be a breeze. The plugin also support the mongodb replica Sets ( cluster )  and makes your application wait if a failover is in place.

Many thanks to Mark Drew that made the installation docs over the Railo wiki. You can find more info, installation step by step and details here: 

http://wiki.getrailo.com/wiki/extensions:mongodb