Ruby
Dependency:
compile "org.grails.plugins:ruby:1.0.M3"
Summary
Plugin for using Ruby code in Grails via JRuby.
Installation
grails install-plugin ruby
Description
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 thesrc/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 enddef greet(name, greeting) hello_world = RubyHelloWorld.new hello_world.create_greeting(name, greeting) end
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 namedruby
by default. In a future version of the plugin, this property name will be configurable.Source
Ruby Plugin on GitHubFeedback
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
- Jeff Brown's Clojure Plugin was used as a guide for creating this Ruby plugin.
- Blog Post About Plugin
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)