Skip to content

Commit

Permalink
[Truffle] Initial implementation of File.readable?.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Feb 3, 2015
1 parent 4614c64 commit 05e122d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/file/readable_tags.txt
@@ -1,3 +1 @@
fails:File.readable? returns true if named file is readable by the effective user id of the process, otherwise false
fails:File.readable? accepts an object that has a #to_path method
fails:File.readable? returns false if the file does not exist
20 changes: 20 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Expand Up @@ -455,6 +455,26 @@ public RubyString read(RubyFile file) {

}

@CoreMethod(names = "readable?", onSingleton = true, needsSelf = false, required = 1)
public abstract static class ReadableQueryNode extends CoreMethodNode {

public ReadableQueryNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ReadableQueryNode(ReadableQueryNode prev) {
super(prev);
}

@Specialization
public boolean isReadable(RubyString file) {
notDesignedForCompilation();

return new File(file.toString()).canRead();
}

}

@CoreMethod(names = "size?", onSingleton = true, required = 1)
public abstract static class SizeNode extends CoreMethodNode {

Expand Down

0 comments on commit 05e122d

Please sign in to comment.