Skip to content
Browse files

Added MAGIC_VERSION.

  • Loading branch information...
1 parent aa0f4ea commit 9de7f44d4eb0552c2f863910c977854e5a8b1b4e @blackwinter committed
Showing with 10 additions and 2 deletions.
  1. +0 −1 TODO
  2. +4 −0 ext/filemagic.c
  3. +2 −1 ext/filemagic.h
  4. +3 −0 info/example.rb
  5. +1 −0 lib/filemagic.rb
View
1 TODO
@@ -2,7 +2,6 @@
* Find a way to make magic_check work on NULL
* Refactor code into initialize instead of new
-* Expose magic(4) version (how?)
* Properly document C methods
* Convert tests to RSpec
* Add Rake tasks
View
4 ext/filemagic.c
@@ -271,6 +271,10 @@ void
Init_filemagic() {
cFileMagic = rb_define_class("FileMagic", rb_cObject);
+ char version[16];
+ sprintf(version, "%d.%02d", FILE_VERSION_MAJOR, patchlevel);
+ rb_define_const(cFileMagic, "MAGIC_VERSION", rb_str_new2(version));
+
rb_define_singleton_method(cFileMagic, "new", rb_magic_new, -1);
rb_define_method(cFileMagic, "initialize", rb_magic_init, -1);
View
3 ext/filemagic.h
@@ -2,8 +2,9 @@
#define __FILEMAGIC_H_
#include "ruby.h"
-#include <magic.h>
#include <math.h>
+#include <magic.h>
+#include <file/patchlevel.h>
/* Ruby 1.8.5 compatibility */
#ifndef RSTRING_LEN
View
3 info/example.rb
@@ -3,6 +3,9 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'filemagic'
+p FileMagic::VERSION
+p FileMagic::MAGIC_VERSION
+
p FileMagic.new.flags
FileMagic.open(:mime) { |fm|
View
1 lib/filemagic.rb
@@ -1,4 +1,5 @@
require 'filemagic.so'
+require 'filemagic/version'
class FileMagic

0 comments on commit 9de7f44

Please sign in to comment.
Something went wrong with that request. Please try again.