Sign in to edit and +1 items.
Login required
Download

Ruby

(0)
Author(s) Bobby Warner
Current Release 1.0.M3   (6 months ago)
Grails Version 1.2 > *
Tags
Dependency
compile ":ruby:1.0.M3"
Plugin for using Ruby code in Grails via JRuby.
Last updated by admin 8 months ago
grails install-plugin ruby
Last updated by bobbywarner 6 months ago

Ruby Plugin

The Ruby plugin provides easy access to execute Ruby code from any Grails artifact (controllers, taglibs, services etc...)

Installation

To install the Ruby plug-in just run the following command from within an existing Grails project:

grails install-plugin ruby

Usage

The plugin expects to find Ruby source files under the src/ruby/ directory. The directory is created for you when the plugin is installed. Ruby source files in a Grails project should have the .rb extension.

For example, src/ruby/hello_world.rb might look like this:

class RubyHelloWorld
    def create_greeting(name, greeting)
        time = Time.new
        day = time.strftime("%A")
        "#{greeting} #{name}! Today is #{day}."
    end
end

def greet(name, greeting) hello_world = RubyHelloWorld.new hello_world.create_greeting(name, greeting) end

With that code in place, the greet function may be executed by using the dynamic property named ruby from any Grails artifact. See below:

class HomeController {
    def hi() {
        ruby.put('name', 'Bobby')
        ruby.put('greeting', 'Hi')
        render ruby.eval('greet($name, $greeting)')
    }

def bye() { ruby.put('name', 'Bobby') ruby.put('greeting', 'Bye') render ruby.eval('greet($name, $greeting)') } }

The Dynamic Property

The dynamic property will be named ruby by default. In a future version of the plugin, this property name will be configurable.

Source

Ruby Plugin on GitHub

Feedback

Your feedback is welcome via GitHub. Please share what you would like to see provided by the plugin or fork it and send a pull request!

References

Release Notes

Version 1.0.M3

  • JRuby upgraded to 1.6.5
  • Grails upgraded to 2.0.0.RC1

Version 1.0.M2

  • Plugin was cleaned up from initial release

Version 1.0.M1

  • JRuby 1.6.4
  • Require Grails 1.2 or later (tested on 1.2.5, 1.3.7 and 2.0.0.M2)
Last updated by admin 8 months ago
Last updated by admin 8 months ago