Skip to content

Commit

Permalink
Add version.rb and load it from stringio.rb
Browse files Browse the repository at this point in the history
Fixes ruby#57
  • Loading branch information
headius committed Aug 9, 2023
1 parent 2b5e2a5 commit 0229d78
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
4 changes: 0 additions & 4 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
**********************************************************************/

#define STRINGIO_VERSION "3.0.8"

#include "ruby.h"
#include "ruby/io.h"
#include "ruby/encoding.h"
Expand Down Expand Up @@ -1832,8 +1830,6 @@ Init_stringio(void)

VALUE StringIO = rb_define_class("StringIO", rb_cObject);

rb_define_const(StringIO, "VERSION", rb_str_new_cstr(STRINGIO_VERSION));

rb_include_module(StringIO, rb_mEnumerable);
rb_define_alloc_func(StringIO, strio_s_allocate);
rb_define_singleton_method(StringIO, "new", strio_s_new, -1);
Expand Down
2 changes: 2 additions & 0 deletions lib/stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
else
require 'stringio.so'
end

require 'stringio/version'
3 changes: 3 additions & 0 deletions lib/stringio/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class StringIO
VERSION = "3.0.6"
end
4 changes: 2 additions & 2 deletions rakelib/version.rake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class << (helper = Bundler::GemHelper.instance)
SOURCE_PATH = "ext/stringio/stringio.c"
SOURCE_PATH = "lib/stringio/version.rb"
def update_source_version
path = SOURCE_PATH
File.open(path, "r+b") do |f|
d = f.read
if d.sub!(/^#define\s+STRINGIO_VERSION\s+\K".*"/) {version.to_s.dump}
if d.sub!(/^\s+VERSION\s+=\s+\K".*"/) {version.to_s.dump}
f.rewind
f.truncate(0)
f.print(d)
Expand Down
17 changes: 6 additions & 11 deletions stringio.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true

source_version = ["", "ext/stringio/"].find do |dir|
begin
break File.open(File.join(__dir__, "#{dir}stringio.c")) {|f|
f.gets("\n#define STRINGIO_VERSION ")
f.gets[/\s*"(.+)"/, 1]
}
rescue Errno::ENOENT
end
end
source_version = File.open("lib/stringio/version.rb") {|f|
f.gets("\n VERSION = ")
f.gets[/\s*"(.+)"/, 1]
}
Gem::Specification.new do |s|
s.name = "stringio"
s.version = source_version
Expand All @@ -18,10 +13,10 @@ Gem::Specification.new do |s|
s.authors = ["Nobu Nakada", "Charles Oliver Nutter"]
s.description = "Pseudo `IO` class from/to `String`."
s.email = ["nobu@ruby-lang.org", "headius@headius.com"]
s.files = ["README.md"]
s.files = ["README.md", "lib/stringio.rb", "lib/stringio/version.rb"]
jruby = true if Gem::Platform.new('java') =~ s.platform or RUBY_ENGINE == 'jruby'
if jruby
s.files += ["lib/stringio.rb", "lib/stringio.jar"]
s.files += ["lib/stringio.jar"]
s.platform = "java"
else
s.extensions = ["ext/stringio/extconf.rb"]
Expand Down

0 comments on commit 0229d78

Please sign in to comment.