Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d22e0f0df015
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0a56927cd17b
Choose a head ref
  • 4 commits
  • 3 files changed
  • 2 contributors

Commits on Nov 20, 2016

  1. Add Pathname#empty?

    * Add `Pathname#empty?`
    * Remove `empty?` implementation on `File` since `FileTest` will assign its implementation of `empty?` to `File` (see `RubyFileTest.FileTestFileMethods`)
    * Add `FileTest.empty?`
    
    The last two steps were down in this PR in order to base the implementation of `Pathname#empty?` on the MRI implementation.
    
    See #4293
    kcdragon committed Nov 20, 2016
    Copy the full SHA
    e62be22 View commit details

Commits on Nov 21, 2016

  1. Use direct calls to RubyFileTest and RubyDir instead of `callMeth…

    …od`. Fix `else` style problem.
    kcdragon committed Nov 21, 2016
    Copy the full SHA
    e6a5888 View commit details

Commits on Nov 22, 2016

  1. Copy the full SHA
    45dc119 View commit details
  2. Merge pull request #4322 from kcdragon/md/feature/add-pathname-empty

    Add `Pathname#empty?`
    enebo authored Nov 22, 2016
    Copy the full SHA
    0a56927 View commit details
Showing with 12 additions and 14 deletions.
  1. +0 −12 core/src/main/java/org/jruby/RubyFile.java
  2. +2 −2 core/src/main/java/org/jruby/RubyFileTest.java
  3. +10 −0 core/src/main/java/org/jruby/ext/pathname/RubyPathname.java
12 changes: 0 additions & 12 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -784,18 +784,6 @@ public static String dirname(ThreadContext context, String jfilename) {
return result;
}

@JRubyMethod(name = {"empty?", "zero?"}, required = 1, meta = true)
public static IRubyObject empty_p(ThreadContext context, IRubyObject self, IRubyObject str) {
Ruby runtime = context.runtime;
String filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, str)).getUnicodeValue();

if (!new File(filename).exists()) return runtime.getFalse();

int size = runtime.newFileStat(filename, false).size().convertToInteger().getIntValue();

return runtime.newBoolean(size == 0);
}

/**
* Returns the extension name of the file. An empty string is returned if
* the filename (not the entire path) starts or ends with a dot.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyFileTest.java
Original file line number Diff line number Diff line change
@@ -307,7 +307,7 @@ public static RubyBoolean zero_p(IRubyObject recv, IRubyObject filename) {
return zero_p(recv.getRuntime().getCurrentContext(), recv, filename);
}

@JRubyMethod(name = "zero?", required = 1, module = true)
@JRubyMethod(name = {"empty?", "zero?"}, required = 1, module = true)
public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) {
Ruby runtime = context.runtime;

@@ -444,7 +444,7 @@ public static RubyBoolean writable_p(IRubyObject recv, IRubyObject filename) {
return RubyFileTest.writable_p(recv, filename);
}

@JRubyMethod(name = "zero?", required = 1)
@JRubyMethod(name = {"empty?", "zero?"}, required = 1)
public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) {
return RubyFileTest.zero_p(context, recv, filename);
}
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/ext/pathname/RubyPathname.java
Original file line number Diff line number Diff line change
@@ -406,6 +406,16 @@ public IRubyObject unlink(ThreadContext context) {
}
}

@JRubyMethod(name = "empty?")
public IRubyObject empty_p(ThreadContext context) {
RubyModule fileTest = context.runtime.getFileTest();
if (fileTest.callMethod(context, "directory?", getPath()).isTrue()) {
return context.runtime.getDir().callMethod(context, "empty?", getPath());
} else {
return fileTest.callMethod(context, "empty?", getPath());
}
}

/* Helpers */

private IRubyObject[] insertPath(IRubyObject[] args, int i) {