Commit 9140f64e by Jon Wood

Remove the C extension, using a Rakefile also works

parent f007b382
require "mkmf"
require "rubygems"
require "rake/clean"
def locate_mime_database
# User provided path.
......@@ -16,7 +17,14 @@ def locate_mime_database
raise "No database of MIME types could be found. Ensure you have either installed the shared-mime-types package for your distribution, or obtain a version of freedesktop.org.xml, and set FREEDESKTOP_MIME_TYPES_PATH to the location of that file."
end
mime_database_path = locate_mime_database
$defs.push("-DMIMEDB_PATH=\\\"#{mime_database_path}\\\"")
create_header
create_makefile("mimemagic/mimemagic")
\ No newline at end of file
desc "Build a file pointing at the database"
task :default do
mime_database_path = locate_mime_database
open("../../lib/mimemagic/path.rb", "w") do |f|
f.print(%Q{
module MimeMagic
DATABASE_PATH="#{mime_database_path}"
end
})
end
end
\ No newline at end of file
#include <ruby.h>
#include "extconf.h"
void Init_mimemagic(void) {
VALUE cMimeMagic;
cMimeMagic = rb_const_get(rb_cObject, rb_intern("MimeMagic"));
rb_define_const(cMimeMagic, "DATABASE_PATH", rb_str_new(MIMEDB_PATH, strlen(MIMEDB_PATH)));
}
......@@ -2,6 +2,7 @@
# frozen_string_literal: true
# Generated from script/freedesktop.org.xml
require 'nokogiri'
require 'mimemagic/path'
class MimeMagic
EXTENSIONS = {}
......@@ -55,7 +56,6 @@ class MimeMagic
end
def self.open_mime_database
require "mimemagic/mimemagic"
path = MimeMagic::DATABASE_PATH
File.open(path)
end
......
......@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|script)/}) }
s.require_paths = %w(lib)
s.extensions = %w(ext/mimemagic/extconf.rb)
s.extensions = %w(ext/mimemagic/Rakefile)
s.summary = 'Fast mime detection by extension or content'
s.description = 'Fast mime detection by extension or content in pure ruby (Uses freedesktop.org.xml shared-mime-info database)'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment