Expose MRuby source as a gem
authorSeba Gamboa <[email protected]>
Tue, 1 Sep 2015 21:45:53 +0000 (1 18:45 -0300)
committerSeba Gamboa <[email protected]>
Tue, 1 Sep 2015 21:45:53 +0000 (1 18:45 -0300)
.gitignore
lib/mruby/source.rb [new file with mode: 0644]
lib/mruby/source/path.rb [new file with mode: 0644]
lib/mruby/source/version.rb [new file with mode: 0644]
mruby-source.gemspec [new file with mode: 0644]

index 1a8c599..6d10a9c 100644 (file)
@@ -20,4 +20,4 @@ cscope.out
 /src/y.tab.c
 /bin
 /build
-/lib
+/mruby-source-*.gem
diff --git a/lib/mruby/source.rb b/lib/mruby/source.rb
new file mode 100644 (file)
index 0000000..bf33d44
--- /dev/null
@@ -0,0 +1,2 @@
+require "mruby/source/path"
+require "mruby/source/version"
diff --git a/lib/mruby/source/path.rb b/lib/mruby/source/path.rb
new file mode 100644 (file)
index 0000000..dbeaef5
--- /dev/null
@@ -0,0 +1,9 @@
+require "pathname"
+
+module MRuby
+  module Source
+    def self.path
+      Pathname.new(File.expand_path('../../../../',__FILE__))
+    end
+  end
+end
diff --git a/lib/mruby/source/version.rb b/lib/mruby/source/version.rb
new file mode 100644 (file)
index 0000000..22bf9c0
--- /dev/null
@@ -0,0 +1,13 @@
+require "mruby/source/path"
+
+module MRuby
+  module Source
+    # Reads a constant defined at version.h
+    MRUBY_READ_VERSION_CONSTANT = -> (name) { Source.path.join('include','mruby','version.h').read.match(/^#define #{name} "?(\w+)"?$/)[1] }
+
+    MRUBY_RELEASE_MAJOR = Integer(MRUBY_READ_VERSION_CONSTANT['MRUBY_RELEASE_MAJOR'])
+    MRUBY_RELEASE_MINOR = Integer(MRUBY_READ_VERSION_CONSTANT['MRUBY_RELEASE_MINOR'])
+    MRUBY_RELEASE_TEENY = Integer(MRUBY_READ_VERSION_CONSTANT['MRUBY_RELEASE_TEENY'])
+    MRUBY_VERSION = [MRUBY_RELEASE_MAJOR,MRUBY_RELEASE_MINOR,MRUBY_RELEASE_TEENY].join('.')
+  end
+end
diff --git a/mruby-source.gemspec b/mruby-source.gemspec
new file mode 100644 (file)
index 0000000..6ccd5d2
--- /dev/null
@@ -0,0 +1,18 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'mruby/source/version'
+
+Gem::Specification.new do |spec|
+  spec.name          = "mruby-source"
+  spec.version       = MRuby::Source::MRUBY_VERSION
+  spec.authors       = ["mruby developers"]
+
+  spec.summary       = %q{MRuby source code wrapper.}
+  spec.description   = %q{MRuby source code wrapper for use with Ruby libs.}
+  spec.homepage      = "http://www.mruby.org/"
+  spec.license       = "MIT"
+
+  spec.files         = `git ls-files -z`.split("\x0")
+  spec.require_paths = ["lib"]
+end