Title: [waffle-scm] [74] trunk/core: camelize the key the ruby controller is defined under within the Registrar (i.e.

Diff

Modified: trunk/core/core.iml (73 => 74)

--- trunk/core/core.iml	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/core/core.iml	2007-05-24 03:54:04 UTC (rev 74)
@@ -134,30 +134,12 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="" />
+          <root url="" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
       </library>
     </orderEntry>
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
-          <root url="" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
-          <root url="" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
     <orderEntryProperties />
   </component>
 </module>

Modified: trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactory.java (73 => 74)

--- trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactory.java	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/core/src/main/java/org/codehaus/waffle/context/pico/RubyAwarePicoContextContainerFactory.java	2007-05-24 03:54:04 UTC (rev 74)
@@ -14,9 +14,23 @@
     public ContextContainer buildApplicationContextContainer() {
         ContextContainer contextContainer = super.buildApplicationContextContainer();
 
+        Ruby runtime = Ruby.getDefaultInstance();
+
+        // TODO Ruby ... this needs to be moved to an actual Ruby file and loaded from clas loader
+        String script =
+            "def String.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)\n" +
+            "  if first_letter_in_uppercase\n" +
+            "    lower_case_and_underscored_word.to_s.gsub(/\\/(.?)/) { \"::\" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }\n" +
+            "  else\n" +
+            "    lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]\n" +
+            "  end\n" +
+            "end";
+
+        runtime.evalScript(script); // load waffle extensions to Ruby language
+
         // Register RubyRuntime at Application level
         MutablePicoContainer picoContainer = (MutablePicoContainer) contextContainer.getDelegate();
-        picoContainer.registerComponentInstance(Ruby.class, Ruby.getDefaultInstance());
+        picoContainer.registerComponentInstance(Ruby.class, runtime);
 
         return contextContainer;
     }

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

--- trunk/core/src/main/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapter.java	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/core/src/main/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapter.java	2007-05-24 03:54:04 UTC (rev 74)
@@ -31,7 +31,7 @@
 
         // TODO RUBY: mixin custom module!
 
-        return runtime.evalScript(componentKey + ".new"); // TODO RUBY: convert name to Camelize
+        return runtime.evalScript("eval(\"#{String.camelize('" + componentKey + "')}.new\")");
     }
 
     public void verify(PicoContainer picoContainer) throws PicoIntrospectionException {

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

--- trunk/core/src/test/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapterTest.java	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/core/src/test/java/org/codehaus/waffle/registrar/pico/RubyScriptComponentAdapterTest.java	2007-05-24 03:54:04 UTC (rev 74)
@@ -11,8 +11,8 @@
 public class RubyScriptComponentAdapterTest extends MockObjectTestCase {
 
     public void testComponentKeyAndImplementationMethods() {
-        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("Foobar", "'ruby script'");
-        assertEquals("Foobar", componentAdapter.getComponentKey());
+        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("foobar", "'ruby script'");
+        assertEquals("foobar", componentAdapter.getComponentKey());
         assertEquals(IRubyObject.class, componentAdapter.getComponentImplementation());
     }
 
@@ -21,13 +21,16 @@
         runtime.evalScript("$my_global = 'Waffle'\n");
 
         String script =
-                "class Foobar\n" +
+                "def String.camelize(param_1)\n" +
+                "  return 'FooBar'\n" + // fake out functionality
+                "end\n" +
+                "class FooBar\n" +
                 "  def execute\n" +
                 "    \"JRuby and #{$my_global}\"\n" +
                 "  end\n" +
                 "end";
 
-        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("Foobar", script);
+        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("foobar", script);
         MutablePicoContainer picoContainer = new DefaultPicoContainer();
         picoContainer.registerComponentInstance(Ruby.class, runtime);
 

Modified: trunk/examples/jruby-example/jruby-example.iml (73 => 74)

--- trunk/examples/jruby-example/jruby-example.iml	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/examples/jruby-example/jruby-example.iml	2007-05-24 03:54:04 UTC (rev 74)
@@ -55,21 +55,12 @@
     <orderEntry type="module-library">
       <library>
         <CLASSES>
-          <root url="" />
+          <root url="" />
         </CLASSES>
         <JAVADOC />
         <SOURCES />
       </library>
     </orderEntry>
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
-          <root url="" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
     <orderEntryProperties />
   </component>
   <component name="WebModuleBuildComponent">
@@ -142,6 +133,11 @@
       <url>jar://$M2_REPOSITORY$/org/jmock/jmock/2.0.0/jmock-2.0.0.jar!/</url>
     </containerElement>
     <containerElement type="library" level="module">
+      <attribute name="method" value="1" />
+      <attribute name="URI" value="/WEB-INF/lib/jruby-complete-1.0RC2.jar" />
+      <url>jar://$M2_REPOSITORY$/org/jruby/jruby-complete/1.0RC2/jruby-complete-1.0RC2.jar!/</url>
+    </containerElement>
+    <containerElement type="library" level="module">
       <attribute name="method" value="0" />
       <attribute name="URI" value="/WEB-INF/lib/jruby-1.0RC2.jar" />
       <url>jar://$M2_REPOSITORY$/org/jruby/jruby/1.0RC2/jruby-1.0RC2.jar!/</url>

Modified: trunk/examples/jruby-example/resources/index.html (73 => 74)

--- trunk/examples/jruby-example/resources/index.html	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/examples/jruby-example/resources/index.html	2007-05-24 03:54:04 UTC (rev 74)
@@ -7,8 +7,8 @@
 <body>
      <h1>Waffle JRuby example</h1>
 <p>
-    <a href="" default method (index) on the Ruby Controller</a><br/>
-    <a href="" the 'bar' method on the Ruby Controller</a><br/>
+    <a href="" default method (index) on the Ruby Controller</a><br/>
+    <a href="" the 'bar' method on the Ruby Controller</a><br/>
 </p>
 </body>
 </html>
\ No newline at end of file

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

--- trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java	2007-05-23 23:05:26 UTC (rev 73)
+++ trunk/examples/jruby-example/src/main/java/org/codehaus/waffle/example/jruby/JRubyRegistrar.java	2007-05-24 03:54:04 UTC (rev 74)
@@ -20,7 +20,7 @@
     public void application() {
 
         String script =
-                "class Foo\n" +
+                "class FooBar\n" +
                 "  def index\n" +
                 "    'HELLO WORLD from the index method'\n" +
                 "  end\n" +
@@ -29,7 +29,7 @@
                 "  end\n" +
                 "end\n";
         
-        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("Foo", script);
+        ComponentAdapter componentAdapter = new RubyScriptComponentAdapter("foo_bar", script);
         picoRegistrar.registerComponentAdapter(componentAdapter);
     }
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to