Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Implement a couple things to make MSpec auto add tags work.
* Fix order of methods.
* File#exist? should just check existance, not file type.
* Will not work if the directory does not exist, but that sounds rather rare.
  • Loading branch information
eregon committed Nov 5, 2014
1 parent 01d560c commit a15f7c2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
44 changes: 32 additions & 12 deletions core/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Expand Up @@ -175,42 +175,42 @@ public RubyNilClass eachLine(VirtualFrame frame, RubyFile file, RubyProc block)

}

@CoreMethod(names = {"exist?", "exists?"}, onSingleton = true, required = 1)
public abstract static class ExistsNode extends CoreMethodNode {
@CoreMethod(names = "executable?", onSingleton = true, required = 1)
public abstract static class ExecutableNode extends CoreMethodNode {

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

public ExistsNode(ExistsNode prev) {
public ExecutableNode(ExecutableNode prev) {
super(prev);
}

@Specialization
public boolean exists(RubyString path) {
public boolean executable(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).isFile();
return new File(path.toString()).canExecute();
}

}

@CoreMethod(names = "executable?", onSingleton = true, required = 1)
public abstract static class ExecutableNode extends CoreMethodNode {
@CoreMethod(names = {"exist?", "exists?"}, onSingleton = true, required = 1)
public abstract static class ExistsNode extends CoreMethodNode {

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

public ExecutableNode(ExecutableNode prev) {
public ExistsNode(ExistsNode prev) {
super(prev);
}

@Specialization
public boolean executable(RubyString path) {
public boolean exists(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).canExecute();
return new File(path.toString()).exists();
}

}
Expand Down Expand Up @@ -298,6 +298,26 @@ public static void join(StringBuilder builder, Object[] parts) {
}
}

@CoreMethod(names = "path", onSingleton = true, required = 1)
public abstract static class PathNode extends CoreMethodNode {

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

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

@Specialization
public RubyString path(RubyString path) {
notDesignedForCompilation();

return getContext().makeString(path.toString());
}

}

@CoreMethod(names = "puts", required = 1)
public abstract static class PutsNode extends CoreMethodNode {

Expand Down
Expand Up @@ -98,6 +98,14 @@ public static RubyFile open(RubyContext context, String fileName, String mode) {
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else if (mode.equals("a") || mode.equals("ab")) {
reader = null;

try {
writer = new OutputStreamWriter(new FileOutputStream(fileName, true));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else {
throw new UnsupportedOperationException();
}
Expand Down

0 comments on commit a15f7c2

Please sign in to comment.