How would the RubyObjectWrapper work when specifying method argument,
e.g$jrubyObject.testMethod( "argument1", "argument2" ) ?
I already start down the road of using an Event handler for InvalidReference
to catch instances of RubyObject. It works for $jrubyObject.testMethod , but
I am having the same problem as above, how to handle method arguments? The
InvalidReferenceEventHandler#invalidMethod does not appear to contain the
argument information for a reference $jrubyObject.testMethod( "argument1",
"argument2" )
thanks,
Michael
On 2/20/07, Nathan Bubna <[EMAIL PROTECTED]> wrote:
I imagine you could get pretty far by wrapping the RubyObjects in a
more Velocity-friendly object that takes advantage how Velocity treats
get(String) methods before putting it into the context.
Perhaps something like:
public class RubyObjectWrapper {
private RubyObject foo;
public RubyObjectWrapper(RubyObject wrapMe) {
this.foo = wrapMe;
}
public Object get(String methodName) {
return new RubyObjectWrapper(this.foo.callMethod(
foo.getRuntime(), methodName));
}
}
If i understand the problem space here, this should allow you to
traverse the object graph for you RubyObjects as you ask:
$jrubyObject.testMethod
I'm really not at all familiar with Ruby, much less JRuby, but perhaps
this will help you get on the right track. I use tricks like this to
simplify the VTL syntax for various tools in VelocityTools all the
time.
The other thing which may help here is using Velocity's EventHandler
capabilities to recognize when a reference is a RubyObject and treat
it differently. Will is much more experienced and knowledgeable on
event handlers than i am, so he may be able to tell you better whether
or not that is a dead end for this sort of thing.
On 2/20/07, Michael <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have been using Velocity for years now and find it the best templating
> language around. This has lead me to try and spread the joy by
attempting to
> swap out RHTML for Velocity in JRuby on Rails.
>
> I have a few simple Ruby test scripts that parse a templates Velocity.
> Things get messy when Velocity needs to traverse an object graph. When
used
> in Rails, the VelocityContext can have a mix of Java objects and
RubyObject
> (these are the problematic ones). The RubyObject is a wrapper for a
Ruby
> object from the JRuby runtime. The RubyObjects do not have static typed
> methods, but everything must go through the method 'callMethod'.
>
> For example, to use velocity notation on the Java object 'sample' to get
the
> method 'test':
> $sample.test
>
> would be on a RubyObject 'sample' to get the method 'test':
> $sample.callMethod( $sample.getRuntime(), "test" )
>
> Things get sticker for passing arguments to a method in RubyObject, all
> arguments must implement IRubyObject. I will just skip over this for
now.
>
> Here is the crux of my question, is it possible to extend Velocity to
add
> support for handling RubyObjects? Ideally Velocity would be able to
> determine whether an object is an implementation of RubyObject, or not,
and
> handle appropriately, i.e $jrubyObject.testMethod could be call directly
> instead of the callMethod for a RubyObject.
>
>
> thanks,
> Michael
> [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]