Discussion:
[jruby-dev] Is forcing all FileResources to reference Ruby a good idea?
(too old to reply)
Dmitry Ratnikov
2014-02-19 22:53:55 UTC
Permalink
Hey all,

This in regards of replacing NonExistentFile.NOT_EXIST check with a special
EmptyFileResource (or NotExistsFileResource, if you strongly prefer):
https://github.com/jruby/jruby/blob/jruby-1_7/core/src/main/java/org/jruby/util/JRubyFile.java#L67

What I realized is that some of the filestat methods (e.g. size,
lastModified and others) should raise ErrorNoENOENTError like MRI does, but
I don't have a reference to Ruby object to raise it from. Technically, I
can probably get away with throwing some sort of RTE (e.g.
OperationUnsupportedException) since I'm pretty sure FileTest checks for
existence and raises "Not found" error for me, but that sounds ugly.

Before I make JRubyFile.createResource(Ruby, String) method mandatory, kill
createResource(String, String) and will have to rewrite most of
org.jruby.util.Dir to conform to the new interface, maybe you have some
other suggestions?

Thanks!
Thomas E Enebo
2014-02-20 21:28:33 UTC
Permalink
I know this will sound mildly icky but I prefer that we pass ThreadContext
instead of Ruby in most cases. When you need to call a ruby method you
must get ThreadContext and Ruby.getCurrentContext() is an expensive
method. If you go the opposite direction getting Ruby from ThreadContext
is only a field context.runtime. In your case (atm), you don't need to
call a Ruby method from a *Resource; but I think ThreadContext will be a
bit more futureproof.

With that said I suspect originally we tried to decouple this code from
having Runtime knowledge but I see no important reason why we should have
this decoupling. So it seems fine to me.

-Tom
Post by Dmitry Ratnikov
Hey all,
This in regards of replacing NonExistentFile.NOT_EXIST check with a
special EmptyFileResource (or NotExistsFileResource, if you strongly
https://github.com/jruby/jruby/blob/jruby-1_7/core/src/main/java/org/jruby/util/JRubyFile.java#L67
What I realized is that some of the filestat methods (e.g. size,
lastModified and others) should raise ErrorNoENOENTError like MRI does, but
I don't have a reference to Ruby object to raise it from. Technically, I
can probably get away with throwing some sort of RTE (e.g.
OperationUnsupportedException) since I'm pretty sure FileTest checks for
existence and raises "Not found" error for me, but that sounds ugly.
Before I make JRubyFile.createResource(Ruby, String) method mandatory,
kill createResource(String, String) and will have to rewrite most of
org.jruby.util.Dir to conform to the new interface, maybe you have some
other suggestions?
Thanks!
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: tom.enebo-***@public.gmane.org
Loading...