Author: jreidinger
Date: Mon Jan 16 15:47:37 2012
New Revision: 67201
URL: http://svn.opensuse.org/viewcvs/yast?rev=67201&view=rev
Log:
fix loading of ruby module when module follows ruby convention ( so ActiveSupport module in in active_support.rb )
Added:
trunk/ruby-bindings/tests/ycp/camel_case.rb
Modified:
trunk/ruby-bindings/src/ruby/Y2CCRuby.cc
trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc
trunk/ruby-bindings/src/ruby/Y2RubyComponent.h
trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp
Modified: trunk/ruby-bindings/src/ruby/Y2CCRuby.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2CCRuby.cc?rev=67201&r1=67200&r2=67201&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2CCRuby.cc (original)
+++ trunk/ruby-bindings/src/ruby/Y2CCRuby.cc Mon Jan 16 15:47:37 2012
@@ -46,6 +46,11 @@
// is there a ruby module?
// must be the same in Y2CCRuby and Y2RubyComponent
string module = YCPPathSearch::find (YCPPathSearch::Module, string (name) + ".rb");
+ //lets try convert it with rails coding convention
+ if (module.empty())
+ {
+ module = YCPPathSearch::find (YCPPathSearch::Module, Y2RubyComponent::CamelCase2DelimSepated(name) + ".rb");
+ }
if (!module.empty ())
{
Modified: trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc?rev=67201&r1=67200&r2=67201&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc (original)
+++ trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc Mon Jan 16 15:47:37 2012
@@ -57,8 +57,12 @@
string module = YCPPathSearch::find (YCPPathSearch::Module, string (name) + ".rb");
if (module.empty ())
{
- y2internal ("Couldn't find %s after Y2CCRuby pointed to us", name);
- return NULL;
+ module = YCPPathSearch::find (YCPPathSearch::Module, Y2RubyComponent::CamelCase2DelimSepated(name) + ".rb");
+ if (module.empty ())
+ {
+ y2internal ("Couldn't find %s after Y2CCRuby pointed to us", name);
+ return NULL;
+ }
}
y2milestone("Found in '%s'", module.c_str());
module.erase (module.size () - 3 /* strlen (".pm") */);
@@ -73,3 +77,22 @@
return ns;
}
+
+const string Y2RubyComponent::CamelCase2DelimSepated( const char* name)
+{
+ string res(name);
+ size_t size = res.size();
+ if (size==0)
+ return res;
+ res[0] = tolower(res[0]); //first character breaks rule with replace upper with _lower
+ for (size_t i = 1; i< res.size();i++)
+ {
+ if (isupper(res[i]))
+ {
+ string tmp = "_";
+ tmp.push_back (tolower(res[i]));
+ res.replace(i,1,tmp); //replace upper by _lower
+ }
+ }
+ return res;
+}
Modified: trunk/ruby-bindings/src/ruby/Y2RubyComponent.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyComponent.h?rev=67201&r1=67200&r2=67201&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyComponent.h (original)
+++ trunk/ruby-bindings/src/ruby/Y2RubyComponent.h Mon Jan 16 15:47:37 2012
@@ -23,6 +23,7 @@
#define Y2RubyComponent_h
#include "Y2.h"
+#include