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 def locate_mime_database
# User provided path. # User provided path.
...@@ -16,7 +17,14 @@ def locate_mime_database ...@@ -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." 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 end
mime_database_path = locate_mime_database desc "Build a file pointing at the database"
$defs.push("-DMIMEDB_PATH=\\\"#{mime_database_path}\\\"") task :default do
create_header mime_database_path = locate_mime_database
create_makefile("mimemagic/mimemagic") open("../../lib/mimemagic/path.rb", "w") do |f|
\ No newline at end of file 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 @@ ...@@ -2,6 +2,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# Generated from script/freedesktop.org.xml # Generated from script/freedesktop.org.xml
require 'nokogiri' require 'nokogiri'
require 'mimemagic/path'
class MimeMagic class MimeMagic
EXTENSIONS = {} EXTENSIONS = {}
...@@ -55,7 +56,6 @@ class MimeMagic ...@@ -55,7 +56,6 @@ class MimeMagic
end end
def self.open_mime_database def self.open_mime_database
require "mimemagic/mimemagic"
path = MimeMagic::DATABASE_PATH path = MimeMagic::DATABASE_PATH
File.open(path) File.open(path)
end end
......
...@@ -12,7 +12,7 @@ Gem::Specification.new do |s| ...@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|script)/}) } s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|script)/}) }
s.require_paths = %w(lib) 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.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)' 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