Title: [waffle-scm] [87] trunk/core/src/main/ruby: wired pico into Waffle::Controller module

Diff

Modified: trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java (86 => 87)

--- trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java	2007-05-26 16:56:45 UTC (rev 86)
+++ trunk/core/src/main/java/org/codehaus/waffle/bind/RubyDataBinder.java	2007-05-26 17:34:37 UTC (rev 87)
@@ -13,7 +13,6 @@
 
 public class RubyDataBinder extends OgnlDataBinder {
 
-    // needs to bind, request, session and parameter to instance variables
     public RubyDataBinder(TypeConverter typeConverter, BindErrorMessageResolver bindErrorMessageResolver) {
         super(typeConverter, bindErrorMessageResolver);
     }
@@ -28,6 +27,8 @@
             JavaEmbedUtils.invokeMethod(runtime, rubyObject, "response=", new HttpServletResponse[] {response}, Object.class);
             JavaEmbedUtils.invokeMethod(runtime, rubyObject, "session=", new HttpSession[] {request.getSession(false)}, Object.class);
 
+            // inspect rubyObject instance variables ... resolve values from (params, req, session, application) ... and set them onto the instance
+
         } else {
             // default to standard binding
             super.bind(request, response, errorsContext, controller);

Modified: trunk/core/src/main/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapter.java (86 => 87)

--- trunk/core/src/main/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapter.java	2007-05-26 16:56:45 UTC (rev 86)
+++ trunk/core/src/main/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapter.java	2007-05-26 17:34:37 UTC (rev 87)
@@ -1,6 +1,7 @@
 package org.codehaus.waffle.registrar.pico;
 
 import org.jruby.Ruby;
+import org.jruby.javasupport.JavaEmbedUtils;
 import org.jruby.runtime.builtin.IRubyObject;
 import org.picocontainer.ComponentAdapter;
 import org.picocontainer.PicoContainer;
@@ -32,7 +33,12 @@
         String script =
                 "controller = eval(\"#{String.camelize('" + componentKey + "')}.new\")\n" + // instantiate controller
                 "controller.extend(Waffle::Controller)"; // mixin Waffle module
-        return runtime.evalScript(script);
+        IRubyObject controller = runtime.evalScript(script);
+
+        // inject pico container
+        controller.callMethod(runtime.getCurrentContext(), "__pico_container=", JavaEmbedUtils.javaToRuby(runtime, picoContainer));
+        
+        return controller;
     }
 
     public void verify(PicoContainer picoContainer) throws PicoIntrospectionException {

Modified: trunk/core/src/main/ruby/waffle.rb (86 => 87)

--- trunk/core/src/main/ruby/waffle.rb	2007-05-26 16:56:45 UTC (rev 86)
+++ trunk/core/src/main/ruby/waffle.rb	2007-05-26 17:34:37 UTC (rev 87)
@@ -1,22 +1,21 @@
+# This is still a work in progress
+
 module Waffle
     module Controller
 
+        # the setters for these should be hidden (i.e. __request=, __response=, __session=)?
         attr_accessor :request, :response, :session
 
-        # Still a work in progress
         def __pico_container=(pico)
             @@__pico_container = pico
         end
 
         def method_missing(symbol, *args)
             if symbol.to_s =~ /^find_/
-                # Pico
-
-
+                key = symbol.to_s.gsub(/^find_/, '')
+                return @@__pico_container.getComponentInstance(key)
             end
         end
 
-        
-
     end
 end
\ No newline at end of file

Modified: trunk/core/src/test/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapterTest.java (86 => 87)

--- trunk/core/src/test/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapterTest.java	2007-05-26 16:56:45 UTC (rev 86)
+++ trunk/core/src/test/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapterTest.java	2007-05-26 17:34:37 UTC (rev 87)
@@ -23,6 +23,8 @@
         String script =
                 "module Waffle\n" +
                 "  module Controller\n" +
+                "   def __pico_container=(pico)\n" +
+                "   end\n" +
                 "  end\n" +
                 "end\n" +
                 "def String.camelize(param_1)\n" +
@@ -34,7 +36,7 @@
                 "  end\n" +
                 "end";
 
-        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("foobar", script);
+        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("foo_bar", script);
         MutablePicoContainer picoContainer = new DefaultPicoContainer();
         picoContainer.registerComponentInstance(Ruby.class, runtime);
 

Modified: trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java (86 => 87)

--- trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java	2007-05-26 16:56:45 UTC (rev 86)
+++ trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java	2007-05-26 17:34:37 UTC (rev 87)
@@ -18,15 +18,14 @@
 
     @Override
     public void application() {
-
+        registerInstance("chicago", "bears");
         String script =
                 "class FooBar\n" +
-                //"  attr_accessor :request\n" +
                 "  def index\n" +
-                "    \"HELLO WORLD from the index method #{request}\"\n" +
+                "    \"HELLO WORLD from the index method #{find_chicagouuu}\"\n" +
                 "  end\n" +
                 "  def bar\n" +
-                "    \"HELLO WORLD #{request.local_name} #{request.local_port}\"\n" +
+                "    \"HELLO WORLD #{request.local_name} #{request.local_port} \"\n" +
                 "  end\n" +
                 "end\n";
 


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to