Permalink
Browse files

first commit

  • Loading branch information...
rifraf committed Apr 4, 2010
0 parents commit 6ec26e8a8dd871da92dd25958a003540922b237b
Showing with 10,665 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +3 −0 ExampleApps/Applications/bottles.rb
  3. +6 −0 ExampleApps/Applications/list_args.rb
  4. +19 −0 ExampleApps/Applications/test_mocking_app.rb
  5. +16 −0 ExampleApps/Applications/test_unit_app.rb
  6. +75 −0 ExampleApps/ExampleApps.csproj
  7. +65 −0 ExampleApps/Program.cs
  8. +34 −0 ExampleApps/Properties/AssemblyInfo.cs
  9. BIN ExampleApps/bin/ExampleApps.exe
  10. BIN ExampleApps/bin/ExampleApps.pdb
  11. BIN ExampleApps/bin/ExampleApps.vshost.exe
  12. BIN ExampleApps/bin/IREmbeddedApp.dll
  13. BIN ExampleApps/bin/IREmbeddedApp.pdb
  14. BIN ExampleApps/bin/IRTestResources.dll
  15. BIN ExampleApps/bin/IRTestResources.pdb
  16. BIN ExampleApps/bin/IronRuby.Libraries.dll
  17. BIN ExampleApps/bin/IronRuby.dll
  18. BIN ExampleApps/bin/Microsoft.Dynamic.dll
  19. BIN ExampleApps/bin/Microsoft.Scripting.Core.dll
  20. BIN ExampleApps/bin/Microsoft.Scripting.ExtensionAttribute.dll
  21. BIN ExampleApps/bin/Microsoft.Scripting.dll
  22. BIN ExampleApps/bin/Serfs.dll
  23. +36 −0 IREmbeddedApp.sln
  24. BIN IREmbeddedApp.suo
  25. +63 −0 IREmbeddedApp/EmbeddedRuby.cs
  26. +57 −0 IREmbeddedApp/EmbeddedRuby/bootstrap.rb
  27. +66 −0 IREmbeddedApp/IREmbeddedApp.csproj
  28. +34 −0 IREmbeddedApp/Properties/AssemblyInfo.cs
  29. BIN IREmbeddedApp/Serfs.dll
  30. +1,796 −0 IRTestResources/Files/Core/optparse.rb
  31. +17 −0 IRTestResources/Files/Core/optparse/date.rb
  32. +6 −0 IRTestResources/Files/Core/optparse/shellwords.rb
  33. +10 −0 IRTestResources/Files/Core/optparse/time.rb
  34. +6 −0 IRTestResources/Files/Core/optparse/uri.rb
  35. +70 −0 IRTestResources/Files/Core/optparse/version.rb
  36. +275 −0 IRTestResources/Files/FlexMock/doc/GoogleExample.rdoc
  37. +99 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.4.0.rdoc
  38. +87 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.4.1.rdoc
  39. +87 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.4.2.rdoc
  40. +87 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.4.3.rdoc
  41. +103 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.5.0.rdoc
  42. +86 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.5.1.rdoc
  43. +136 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.6.0.rdoc
  44. +91 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.6.1.rdoc
  45. +101 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.6.2.rdoc
  46. +111 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.6.3.rdoc
  47. +117 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.6.4.rdoc
  48. +138 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.7.0.rdoc
  49. +93 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.7.1.rdoc
  50. +108 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.8.0.rdoc
  51. +100 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.8.2.rdoc
  52. +94 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.8.3.rdoc
  53. +93 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.8.4.rdoc
  54. +95 −0 IRTestResources/Files/FlexMock/doc/releases/flexmock-0.8.5.rdoc
  55. +13 −0 IRTestResources/Files/FlexMock/flexmock.rb
  56. +85 −0 IRTestResources/Files/FlexMock/flexmock/argument_matchers.rb
  57. +54 −0 IRTestResources/Files/FlexMock/flexmock/argument_types.rb
  58. +24 −0 IRTestResources/Files/FlexMock/flexmock/base.rb
  59. +10 −0 IRTestResources/Files/FlexMock/flexmock/composite.rb
  60. +218 −0 IRTestResources/Files/FlexMock/flexmock/core.rb
  61. +83 −0 IRTestResources/Files/FlexMock/flexmock/core_class_methods.rb
  62. +31 −0 IRTestResources/Files/FlexMock/flexmock/default_framework_adapter.rb
  63. +62 −0 IRTestResources/Files/FlexMock/flexmock/deprecated_methods.rb
  64. +23 −0 IRTestResources/Files/FlexMock/flexmock/errors.rb
  65. +476 −0 IRTestResources/Files/FlexMock/flexmock/expectation.rb
  66. +87 −0 IRTestResources/Files/FlexMock/flexmock/expectation_director.rb
  67. +327 −0 IRTestResources/Files/FlexMock/flexmock/mock_container.rb
  68. +13 −0 IRTestResources/Files/FlexMock/flexmock/noop.rb
  69. +51 −0 IRTestResources/Files/FlexMock/flexmock/ordering.rb
  70. +291 −0 IRTestResources/Files/FlexMock/flexmock/partial_mock.rb
  71. +15 −0 IRTestResources/Files/FlexMock/flexmock/rails.rb
  72. +144 −0 IRTestResources/Files/FlexMock/flexmock/rails/view_mocking.rb
  73. +71 −0 IRTestResources/Files/FlexMock/flexmock/recorder.rb
  74. +34 −0 IRTestResources/Files/FlexMock/flexmock/rspec.rb
  75. +32 −0 IRTestResources/Files/FlexMock/flexmock/test_unit.rb
  76. +53 −0 IRTestResources/Files/FlexMock/flexmock/test_unit_integration.rb
  77. +50 −0 IRTestResources/Files/FlexMock/flexmock/undefined.rb
  78. +77 −0 IRTestResources/Files/FlexMock/flexmock/validators.rb
  79. +281 −0 IRTestResources/Files/TestUnit/test/unit.rb
  80. +14 −0 IRTestResources/Files/TestUnit/test/unit/assertionfailederror.rb
  81. +622 −0 IRTestResources/Files/TestUnit/test/unit/assertions.rb
  82. +220 −0 IRTestResources/Files/TestUnit/test/unit/autorunner.rb
  83. +43 −0 IRTestResources/Files/TestUnit/test/unit/collector.rb
  84. +107 −0 IRTestResources/Files/TestUnit/test/unit/collector/dir.rb
  85. +34 −0 IRTestResources/Files/TestUnit/test/unit/collector/objectspace.rb
  86. +56 −0 IRTestResources/Files/TestUnit/test/unit/error.rb
  87. +51 −0 IRTestResources/Files/TestUnit/test/unit/failure.rb
  88. +160 −0 IRTestResources/Files/TestUnit/test/unit/testcase.rb
  89. +80 −0 IRTestResources/Files/TestUnit/test/unit/testresult.rb
  90. +76 −0 IRTestResources/Files/TestUnit/test/unit/testsuite.rb
  91. +127 −0 IRTestResources/Files/TestUnit/test/unit/ui/console/testrunner.rb
  92. +268 −0 IRTestResources/Files/TestUnit/test/unit/ui/fox/testrunner.rb
  93. +416 −0 IRTestResources/Files/TestUnit/test/unit/ui/gtk/testrunner.rb
  94. +465 −0 IRTestResources/Files/TestUnit/test/unit/ui/gtk2/testrunner.rb
  95. +68 −0 IRTestResources/Files/TestUnit/test/unit/ui/testrunnermediator.rb
  96. +46 −0 IRTestResources/Files/TestUnit/test/unit/ui/testrunnerutilities.rb
  97. +260 −0 IRTestResources/Files/TestUnit/test/unit/ui/tk/testrunner.rb
  98. +40 −0 IRTestResources/Files/TestUnit/test/unit/util/backtracefilter.rb
  99. +90 −0 IRTestResources/Files/TestUnit/test/unit/util/observable.rb
  100. +48 −0 IRTestResources/Files/TestUnit/test/unit/util/procwrapper.rb
  101. +100 −0 IRTestResources/IRTestResources.csproj
  102. +34 −0 IRTestResources/Properties/AssemblyInfo.cs
  103. +49 −0 README
  104. +86 −0 code_style.xml
  105. +14 −0 rakefile
@@ -0,0 +1,6 @@
+_ReSharper.IREmbeddedApp/*
+ExampleApps/obj/
+IREmbeddedApp/bin/
+IREmbeddedApp/obj/
+IRTestResources/bin/
+IRTestResources/obj/
@@ -0,0 +1,3 @@
+10.times { |i|
+ puts "#{i} green bottles"
+}
@@ -0,0 +1,6 @@
+puts "$0 is #{$0}"
+puts "__FILE__ is #{__FILE__}"
+puts "There are #{ARGV.length} command-line arguments"
+ARGV.each_with_index do |arg, index|
+ puts "#{index}: #{arg}"
+end
@@ -0,0 +1,19 @@
+require 'test/unit'
+require 'flexmock/test_unit'
+
+# ================================================
+class TestDog < Test::Unit::TestCase
+
+ def test_dog_wags
+ tail_mock = flexmock(:wag => :happy)
+ assert_equal :happy, tail_mock.wag
+ end
+
+ def test_dog_wags_not
+ tail_mock = flexmock(:wag => :sad)
+ assert_equal :happy, tail_mock.wag
+ end
+
+end
+
+# TODO: test failures fail on reporting. location??
@@ -0,0 +1,16 @@
+require 'test/unit'
+
+# ================================================
+class TestDemo < Test::Unit::TestCase
+
+ def test_should_pass
+ sum = 2 + 2
+ assert_equal 4, sum
+ end
+
+ def test_should_fail
+ sum = 2 + 2
+ assert_equal 5, sum
+ end
+
+end
@@ -0,0 +1,75 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F81E1902-C72C-4457-A526-A49AE80FEA1F}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ExampleApps</RootNamespace>
+ <AssemblyName>ExampleApps</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="IREmbeddedApp, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\IREmbeddedApp\bin\IREmbeddedApp.dll</HintPath>
+ </Reference>
+ <Reference Include="IronRuby.Libraries, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Program Files\IronRuby 1.0.0.0\bin\IronRuby.Libraries.dll</HintPath>
+ </Reference>
+ <Reference Include="IRTestResources, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\IRTestResources\bin\IRTestResources.dll</HintPath>
+ </Reference>
+ <Reference Include="Serfs, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\IREmbeddedApp\Serfs.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Applications\test_unit_app.rb" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Applications\test_mocking_app.rb" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Applications\bottles.rb" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Applications\list_args.rb" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,65 @@
+using System;
+using IREmbeddedApp;
+
+namespace IronRubyConsole {
+
+ class Program {
+
+ static int Main(string[] args) {
+ int exitcode = 0;
+
+ // First application : bottles
+ Console.WriteLine("bottles.rb");
+ Console.WriteLine("----------");
+ try {
+ EmbeddedRuby er1 = new EmbeddedRuby();
+ er1.Mount("Applications");
+ exitcode = er1.Run("bottles.rb");
+ } catch (Exception e) {
+ Console.WriteLine(e.Message);
+ }
+ Console.WriteLine();
+
+ // list_args.rb
+ Console.WriteLine("bottles.rb");
+ Console.WriteLine("----------");
+ try {
+ EmbeddedRuby er1 = new EmbeddedRuby();
+ er1.Mount("Applications");
+ exitcode = er1.Run("list_args.rb", args);
+ } catch (Exception e) {
+ Console.WriteLine(e.Message);
+ }
+ Console.WriteLine();
+
+ // Demo of test::unit
+ Console.WriteLine("test_unit_app.rb");
+ Console.WriteLine("----------------");
+ try {
+ EmbeddedRuby er2 = new EmbeddedRuby();
+ er2.AddAssembly("IRTestResources", "Files/Core").Mount("Files/TestUnit");
+ er2.Mount("Applications");
+ exitcode = er2.Run("test_unit_app.rb");
+ } catch (Exception e) {
+ Console.WriteLine(e.Message);
+ }
+ Console.WriteLine();
+
+ // Demo of test::unit and flexmock
+ Console.WriteLine("test_mocking_app.rb");
+ Console.WriteLine("-------------------");
+ try {
+ EmbeddedRuby er3 = new EmbeddedRuby();
+ er3.AddAssembly("IRTestResources", "Files/Core").Mount("Files/FlexMock").Mount("Files/TestUnit");
+ er3.Mount("Applications");
+ exitcode = er3.Run("test_mocking_app.rb");
+ } catch (Exception e) {
+ Console.WriteLine(e.Message);
+ }
+ Console.WriteLine();
+
+ return exitcode;
+ }
+ }
+}
+
@@ -0,0 +1,34 @@
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ExampleApps")]
+[assembly: AssemblyDescription("Executable demonstrating running Ruby programs embedded into the exe.")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("djlSoft")]
+[assembly: AssemblyProduct("ExampleApps")]
+[assembly: AssemblyCopyright("Copyright David Lake © 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("40e052ee-a6b3-441c-93b2-1768a97fb5a7")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("0.1.0.0")]
+[assembly: AssemblyFileVersion("0.1.0.0")]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,36 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IREmbeddedApp", "IREmbeddedApp\IREmbeddedApp.csproj", "{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IRTestResources", "IRTestResources\IRTestResources.csproj", "{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleApps", "ExampleApps\ExampleApps.csproj", "{F81E1902-C72C-4457-A526-A49AE80FEA1F}"
+ ProjectSection(ProjectDependencies) = postProject
+ {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C} = {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}
+ {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E} = {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F81E1902-C72C-4457-A526-A49AE80FEA1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F81E1902-C72C-4457-A526-A49AE80FEA1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F81E1902-C72C-4457-A526-A49AE80FEA1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F81E1902-C72C-4457-A526-A49AE80FEA1F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using IronRuby;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Hosting;
+using Microsoft.Scripting.Hosting.Providers;
+using SERFS;
+
+namespace IREmbeddedApp {
+ public class EmbeddedRuby {
+ private readonly Serfs _serfs;
+
+ public EmbeddedRuby() {
+ _serfs = new Serfs("EmbeddedRuby");
+ }
+
+ public AssemblyInfo Mount(string topFolder) {
+ return _serfs.AddAssembly(Assembly.GetCallingAssembly().FullName,topFolder);
+ }
+
+ public AssemblyInfo AddAssembly(string name) {
+ return _serfs.AddAssembly(name);
+ }
+
+ public AssemblyInfo AddAssembly(string name, string folder) {
+ return _serfs.AddAssembly(name, folder);
+ }
+
+ public int Run(string app) {
+ return Run(app, null);
+ }
+
+ public int Run(string app, string[] args) {
+ ScriptRuntime runtime = Ruby.CreateRuntime();
+ ScriptEngine engine = runtime.GetEngine("rb");
+ RubyContext context = (RubyContext)HostingHelpers.GetLanguageContext(engine);
+ context.ObjectClass.SetConstant("SerfsInstance", _serfs);
+
+ // Sort out ARGV
+ string argv;
+ if ((args != null) && (args.Length > 0)) {
+ List<string> quoted_args = new List<string>();
+ foreach (string s in args) {
+ quoted_args.Add("'" + s + "'");
+ }
+ argv = String.Format("ARGV << {0}\r\n", String.Join(" << ", quoted_args.ToArray()));
+ } else {
+ argv = "";
+ }
+ // Prefix bootstrap with $0 and ARGV
+ string boot = String.Format(
+ "$0='{0}'\r\n{1}{2}",
+ app, argv, _serfs.Read("bootstrap.rb")
+ );
+ ScriptSource source = engine.CreateScriptSourceFromString(boot, "bootstrap.rb", SourceCodeKind.File);
+ int ex = source.ExecuteProgram();
+ context.Shutdown();
+ return ex;
+ }
+ }
+}
@@ -0,0 +1,57 @@
+# Bootstrapper patches load and require so that files can be
+# read from SERFS (Simple Embedded Resource File System)
+# It finishes by loading $0 (which should be set up before entry)
+
+def read_embedded_file(path)
+ $LOAD_PATH.each do |loc|
+ test = "#{loc}/#{path}".gsub(/\\/,'/')
+ str = SerfsInstance.read(test)
+ return str.to_s if str
+ end
+ false
+end
+
+# TODO: If the optional wrap parameter is true, the loaded script will be executed under an anonymous module,
+# TODO: protecting the calling program's global namespace.
+# TODO: In no circumstance will any local variables in the loaded file be propagated to the loading environment.
+def load_embedded_file(path, wrap = false)
+ str = read_embedded_file(path)
+ if (str)
+ eval str, nil, path
+ return true
+ end
+ false
+end
+
+# Patch 'load'
+alias old_load load
+def load(filename, wrap = false)
+ old_load(filename, wrap)
+ rescue LoadError => load_error
+ if load_error.message =~ /#{Regexp.escape filename}\z/ and load_embedded_file(filename, wrap)
+ return true
+ end
+ raise load_error
+end
+
+# Patch 'require'
+alias old_require require
+def require(path)
+ return false if $".include?(path)
+ old_require(path)
+ rescue LoadError => load_error
+ if load_error.message =~ /#{Regexp.escape path}\z/
+ str = (read_embedded_file(path + ".rb") || read_embedded_file(path))
+ if str
+ $" << path
+ eval str, nil, path
+ return true
+ end
+ end
+ raise load_error
+end
+private :old_require
+private :require
+
+# Run
+load $0 if $0
Oops, something went wrong.

0 comments on commit 6ec26e8

Please sign in to comment.