]> icculus.org git repositories - duncan/yast2-ruby-bindings.git/blob - src/ruby/Y2RubyComponent.cc
- Lot of fixes and support for the UI!!!
[duncan/yast2-ruby-bindings.git] / src / ruby / Y2RubyComponent.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                                                                      |
10 | ruby language support                              (C) Novell Inc.   |
11 \----------------------------------------------------------------------/
12
13 Author: Duncan Mac-Vicar <dmacvicar@suse.de>
14
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version
18 2 of the License, or (at your option) any later version.
19
20 */
21
22 #define y2log_component "Y2Ruby"
23 #include <ycp/y2log.h>
24 #include <ycp/pathsearch.h>
25
26 #include "Y2RubyComponent.h"
27 #include "YRuby.h"
28 #include "YRubyNamespace.h"
29 using std::string;
30
31
32 Y2RubyComponent::Y2RubyComponent()
33 {
34   // Actual creation of a Ruby interpreter is postponed until one of the
35   // YRuby static methods is used. They handle that.
36
37   y2milestone( "Creating Y2RubyComponent" );
38 }
39
40
41 Y2RubyComponent::~Y2RubyComponent()
42 {
43   y2milestone( "Destroying Y2RubyComponent" );
44   YRuby::destroy();
45 }
46
47
48 void Y2RubyComponent::result( const YCPValue & )
49 {}
50
51
52 Y2Namespace *Y2RubyComponent::import (const char* name)
53 {
54   y2milestone("Creating namespace for import '%s'", name);
55   // TODO where to look for it
56   // must be the same in Y2CCRuby and Y2RubyComponent
57   string module = YCPPathSearch::find (YCPPathSearch::Module, string (name) + ".rb");
58   if (module.empty ())
59   {
60     y2internal ("Couldn't find %s after Y2CCRuby pointed to us", name);
61     return NULL;
62   }
63   y2milestone("Found in '%s'", module.c_str());
64   module.erase (module.size () - 3 /* strlen (".pm") */);
65   YCPList args;
66   args->add (YCPString(/*module*/ name));
67   args->add (YCPString(/*module*/ module));
68   // load it
69   YRuby::loadModule (args);
70   y2milestone("Module '%s' loaded", name);
71   // introspect, create data structures for the interpreter
72   Y2Namespace *ns = new YRubyNamespace (name);
73
74   return ns;
75 }