Support For Referencing Ruby Libs As Embedded Resources?

A recent inquiry on the Ruby.NET list brought up the question as to
whether or not the ability to reference ruby libs as embedded resources
is
supported or will be supported via IronRuby. e.g.,

require ‘res://assembly.dll/foo/bar’

Yes/No/Maybe? Reasons For/Against/Agnostic?


/M:D

M. David P.
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: [email protected] | [email protected]
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
M. David Peterson

M. David P.:

A recent inquiry on the Ruby.NET list brought up the question as to
whether or not the ability to reference ruby libs as embedded resources
is supported or will be supported via IronRuby. e.g.,

require ‘res://assembly.dll/foo/bar’

Yes/No/Maybe? Reasons For/Against/Agnostic?

Is the embedded resource a Ruby file or something else?
What is the feature used for?

  • John

On Feb 8, 2008 5:48 PM, John M. [email protected] wrote:

M. David P.:

A recent inquiry on the Ruby.NET list brought up the question as to
whether or not the ability to reference ruby libs as embedded resources
is supported or will be supported via IronRuby. e.g.,

require ‘res://assembly.dll/foo/bar’

Is the embedded resource a Ruby file or something else?
What is the feature used for?

I imagine the idea is to make deployment more robust by putting the
Ruby source somewhere that a user can’t screw up. :wink:

At least, that’s what I’d want it for…


Curt H.
[email protected]

On Fri, 08 Feb 2008 19:00:26 -0700, Curt H.
[email protected] wrote:

I imagine the idea is to make deployment more robust by putting the
Ruby source somewhere that a user can’t screw up.

Yup!

At least, that’s what I’d want it for…

You and I both, Curt! :smiley:


/M:D

M. David P.
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: [email protected] | [email protected]
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
M. David Peterson

On Fri, 08 Feb 2008 18:48:39 -0700, John M. [email protected]
wrote:

Is the embedded resource a Ruby file or something else?

Yes, a Ruby file.

What is the feature used for?

Here’s a copy of the pertinent pieces from the related thread on the
Ruby.NET list. In short, for ease of redistribution of stdlib source
files.

On Fri, 08 Feb 2008 18:26:57 -0700, M. David P.
[email protected] wrote:

On Fri, 08 Feb 2008 13:33:47 -0700, chriso [email protected] wrote:

for anything beyond experimentation) via creating an assembly who’s only
they plan to provide support for embedded resources, and if so, the
namespace ResourceLib
Ruby.String(m_encoding.GetString((byte[])manager.GetObject(stdLibName)));

puts erb.run(bind)

puts ‘Bye .net’


/M:D

M. David P.
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: [email protected] | [email protected]
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
M. David Peterson

Curt H.:

What is the feature used for?

I imagine the idea is to make deployment more robust by putting the
Ruby source somewhere that a user can’t screw up. :wink:

At least, that’s what I’d want it for…

Right, but if you have a DLL already, you can just host IronRuby from C#
and feed it Ruby code however you want to.

I guess I’d be hesitant to change the meaning of “require”. The way we
have it now (require ‘mscorlib’) is nice because it’s not changing the
behavior. If you really wanted to you could write mscorlib.rb and run
your code on another Ruby implementation.

  • John

On Fri, 08 Feb 2008 19:09:25 -0700, John M. [email protected]
wrote:

Right, but if you have a DLL already, you can just host IronRuby from C#
and feed it Ruby code however you want to.

True. So would that then be the prefered way to go about providing
support?

I guess I’d be hesitant to change the meaning of “require”. The way we
have it now (require ‘mscorlib’) is nice because it’s not changing the
behavior. If you really wanted to you could write mscorlib.rb and run
your code on another Ruby implementation.

Oh, I’m not suggesting changing the meaning, just adding a handler for
the
‘res’ protocol that would locate the source file via an assembly rather
than the file system. To me, anyway, I don’t see any difference between
what,

require ‘C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll’

… means and what,

require ‘res://assemblyname.dll/foo/bar’

… means, at least in regards to the fact that they both represent
references to external libraries.


/M:D

M. David P.
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: [email protected] | [email protected]
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
M. David Peterson

On Feb 8, 2008 6:16 PM, M. David P. [email protected] wrote:

than the file system.

After all, if urirequire can do this for “http:”…

On Fri, 08 Feb 2008 20:11:27 -0700, Michael L.
[email protected] wrote:

heck if it’s that needed, someone can write resrequire

Assuming this would be seen as standard practice for implementing core
language extensions, this would probably make the most sense, avoiding
any
compromise and ensuring that there’s a simple escape hatch to fallback
to
require if the resrequire method isn’t supported or if the requested
embedded resource is unavailable.


/M:D

M. David P.
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: [email protected] | [email protected]
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
M. David Peterson

I’d personally much rather see it done via something like urirequire
(heck if it’s that needed, someone can write resrequire :wink: )

Though there is a debate in there about if require should handle URIs
in general or not, I think it’s one for Ruby in general to have…

On Feb 8, 2008 9:54 PM, Curt H. [email protected] wrote:

have it now (require ‘mscorlib’) is nice because it’s not changing the


Curt H.
[email protected]


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

My /personal/ view is that IronRuby should be Ruby first and .NET
second. Anything that’s done outside of “normal” behaviour should be
implemented outside of the core implementation. I’d almost go as far
as to say that the current method of loading .NET assemblies is
pushing it, but that’s an extreme view.

So yes, if we’re doing something specific to this platform it should
be implemented ontop of the core language not in it. It would be up
to the person writing the code that uses resrequire (or urirequire) to
perform the graceful fallback.

On Feb 8, 2008 10:35 PM, M. David P. [email protected]
wrote:

Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

On Fri, 08 Feb 2008 20:57:58 -0700, Michael L.
[email protected] wrote:

So yes, if we’re doing something specific to this platform it should
be implemented ontop of the core language not in it. It would be up
to the person writing the code that uses resrequire (or urirequire) to
perform the graceful fallback.

That makes complete sense and I can’t help but agree. :slight_smile:


/M:D

M. David P.
Co-Founder & Chief Architect, 3rd&Urban, LLC
Email: [email protected] | [email protected]
Mobile: (206) 418-9027
http://3rdandUrban.com | http://amp.fm |
M. David Peterson

For what it’s worth, this /is/ possible today:

require ‘mscorlib’

def resrequire(assembly, resource)

assem = System::Reflection::Assembly.LoadFile assembly

stream = assem.GetManifestResourceStream(resource)

streamreader = System::IO::StreamReader.new stream

filetext = streamreader.ReadToEnd

file = File.new resource, ‘w’

file.write filetext

file.close

require resource

File.delete resource

end

I think I’d rather use eval then create a file, but we don’t have that
yet :wink:

On Feb 9, 2008 12:45 AM, M. David P. [email protected]
wrote:


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com