Skip to content

Commit 583d901

Browse files
authored
jruby: Add StringIO::VERSION (#59)
Fixes GH-57
1 parent 2b5e2a5 commit 583d901

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

ext/java/org/jruby/ext/stringio/StringIO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public static RubyClass createStringIOClass(final Ruby runtime) {
8383
RubyClass stringIOClass = runtime.defineClass(
8484
"StringIO", runtime.getObject(), StringIO::new);
8585

86+
RubyString version = RubyString.newString(runtime, "3.0.8");
87+
stringIOClass.defineConstant("VERSION", version);
88+
8689
stringIOClass.defineAnnotatedMethods(StringIO.class);
8790
stringIOClass.includeModule(runtime.getEnumerable());
8891

rakelib/version.rake

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
class << (helper = Bundler::GemHelper.instance)
2-
SOURCE_PATH = "ext/stringio/stringio.c"
2+
C_SOURCE_PATH = "ext/stringio/stringio.c"
3+
JAVA_SOURCE_PATH = "ext/java/org/jruby/ext/stringio/StringIO.java"
34
def update_source_version
4-
path = SOURCE_PATH
5-
File.open(path, "r+b") do |f|
6-
d = f.read
7-
if d.sub!(/^#define\s+STRINGIO_VERSION\s+\K".*"/) {version.to_s.dump}
8-
f.rewind
9-
f.truncate(0)
10-
f.print(d)
11-
end
12-
end
5+
c_source = File.read(C_SOURCE_PATH)
6+
c_source.sub!(/^#define\s+STRINGIO_VERSION\s+\K".*"/) {version.to_s.dump}
7+
File.write(C_SOURCE_PATH, c_source)
8+
9+
java_source = File.read(JAVA_SOURCE_PATH)
10+
java_source.sub!(/version = RubyString\.newString\(runtime, \K".*"/) {version.to_s.dump}
11+
File.write(JAVA_SOURCE_PATH, java_source)
1312
end
1413

1514
def commit_bump

test/stringio/test_stringio.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def open_file(content)
1414

1515
include TestEOF::Seek
1616

17+
def test_version
18+
assert_kind_of(String, StringIO::VERSION)
19+
end
20+
1721
def test_initialize
1822
assert_kind_of StringIO, StringIO.new
1923
assert_kind_of StringIO, StringIO.new('str')

0 commit comments

Comments
 (0)