Mailinglist Archive: yast-commit (265 mails)

< Previous Next >
[yast-commit] r67201 - in /trunk/ruby-bindings: src/ruby/Y2CCRuby.cc src/ruby/Y2RubyComponent.cc src/ruby/Y2RubyComponent.h tests/ycp/camel_case.rb tests/ycp/ruby_from_ycp.ycp
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 <string.h>


/**
@@ -71,6 +72,13 @@
* free it. Thus, it's possible to share the instance.
*/
Y2Namespace *import (const char* name);
+
+ /**
+ * Utility method to translate camelcase name of module to delimeter
+ * separated one. It is useful for loading modules which follows
conventions
+ * so ActiveSupport namespace is from active_support.rb.
+ */
+ static const std::string CamelCase2DelimSepated (const char* name);
};

#endif // Y2RubyComponent_h

Added: trunk/ruby-bindings/tests/ycp/camel_case.rb
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/tests/ycp/camel_case.rb?rev=67201&view=auto
==============================================================================
--- trunk/ruby-bindings/tests/ycp/camel_case.rb (added)
+++ trunk/ruby-bindings/tests/ycp/camel_case.rb Mon Jan 16 15:47:37 2012
@@ -0,0 +1,5 @@
+module CamelCase
+ def self.inc (n)
+ n+1
+ end
+end

Modified: trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp?rev=67201&r1=67200&r2=67201&view=diff
==============================================================================
--- trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp (original)
+++ trunk/ruby-bindings/tests/ycp/ruby_from_ycp.ycp Mon Jan 16 15:47:37 2012
@@ -3,4 +3,7 @@
import "InRuby";
string result = tostring(InRuby::multiply_by_eight(10));
y2milestone("result: %1", result);
+ import "CamelCase";
+ result = tostring(CamelCase::inc(10));
+ y2milestone("result: %1", result);
}

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages