Beispiel #1
0
        private void InitRack()
        {
            IronRubyEngine.SetToplevelBinding();

            if (GemPath != null && GemPath.Length > 0)
            {
                Utils.Log("=> Setting GEM_PATH: " + IronRubyEngine.Context.Inspect(GemPath));
                Environment.SetEnvironmentVariable("GEM_PATH", GemPath);
            }

            if (RackEnv != null)
            {
                Utils.Log("=> Setting RACK_ENV: " + IronRubyEngine.Context.Inspect(RackEnv));
                Environment.SetEnvironmentVariable("RACK_ENV", RackEnv);
            }

            Utils.Log("=> Loading RubyGems");
            IronRubyEngine.Require("rubygems");

            Utils.Log("=> Loading Rack " + RackVersion);
            IronRubyEngine.Require("rack", RackVersion);
            Utils.Log(string.Format("=> Loaded rack-{0}", Utils.Join(ActualRackVersion, ".")));

            Utils.Log("=> Application root: " + IronRubyEngine.Context.Inspect(AppRoot));
            IronRubyEngine.AddLoadPath(AppRoot);
        }
        // TODO: also include overload which takes a RubyObject and uses it as
        // the Rack application (to truely support rackup).
        public IronRubyApplication(string appPath)
        {
            PhysicalAppPath = appPath;

            IronRubyEngine.Init();
            InitRack();
            _app = Rackup();
        }
Beispiel #3
0
        private object Rackup()
        {
            Utils.Log("=> Loading Rack application");
            var fullPath = Path.Combine(_appRoot, "config.ru");

            if (File.Exists(fullPath))
            {
                return(IronRubyEngine.ExecuteMethod <RubyArray>(
                           IronRubyEngine.Execute("Rack::Builder"),
                           "parse_file", MutableString.CreateAscii(fullPath))[0]);
            }
            return(null);
        }
Beispiel #4
0
        internal static void ReportErrorAsHTML(HttpContext /*!*/ context, Exception /*!*/ e, Action <string> write)
        {
            var trace = IronRubyEngine.Engine == null ?
                        e.Message + "\n" + e.StackTrace + "\n" :
                        IronRubyEngine.Engine.GetService <ExceptionOperations>().FormatException(e);

            write("<html>\r\n");
            write(String.Format(@"
<h4>Error: {0}</h4>
<pre>
{1}
</pre>
", HttpUtility.HtmlEncode(e.Message), HttpUtility.HtmlEncode(trace)));

            if (IronRubyEngine.Engine != null)
            {
                write("<h4>Search paths</h4>\r\n");
                write("<pre>\r\n");
                foreach (var path in IronRubyEngine.Engine.GetSearchPaths())
                {
                    write(HttpUtility.HtmlEncode(path));
                    write("\r\n");
                }
                write("</pre>\r\n");

                try {
                    var gempaths = IronRubyEngine.Execute <RubyArray>("require 'rubygems'; Gem.path");
                    write("<h4>Gem paths</h4>\r\n");
                    write("<pre>\r\n");
                    foreach (var gempath in gempaths)
                    {
                        write(HttpUtility.HtmlEncode(((MutableString)gempath).ToString()));
                        write("\r\n");
                    }
                    write("</pre>\r\n");
                } catch {
                    // who cares if it fails
                }
            }
            write("</html>\r\n");
        }
Beispiel #5
0
 public RubyArray Call(Hash env)
 {
     return(IronRubyEngine.ExecuteMethod <RubyArray>(App, "call", env));
 }