tonytonyjan / jaro_winkler

Ruby & C implementation of Jaro-Winkler distance algorithm which supports UTF-8 string.
MIT License
192 stars 29 forks source link

Fall back to pure Ruby when native extension not available #28

Closed Footpad closed 5 years ago

Footpad commented 5 years ago

In scenarios where there are issues loading the native extension, can this library fall back to the pure Ruby implementation? I wanted to check if this was an acceptable behavior for this library before sending a PR.

Why? In the build environment I work in, it's very difficult to make native extensions for the necessary platforms available. Since this gem has become a runtime dependency of RuboCop, we can no longer use newer versions of RuboCop because it fast fails trying to load the native extension.

Here's an example from fuzzy-string-match that would be similar to how it could be done.

tonytonyjan commented 5 years ago

I tried to make this gem be able to fall back to pure Ruby version when the native extension is not available by adding platform checking to jaro_winkler.gemspec, ext/jaro_winkler/extconf.rb, lib/jaro_winkler.rb, and even generating a dummy Makefile while Ruby gem is trying to compile without building environment, that's a lot of work. unfortunately, I still couldn't make it work and eventually gave up.

fuzzy-string-match depends on a gem called RubyInline, which can put inline C code in Ruby file. Compilation happens in runtime, so falling back dynamically is possible.

However, by preference, I do not like RubyInline at all. It not only makes C code hard to maintain/share but also makes the editor's dev tool for C useless (ctags for example). Solutions using RubyInline is not acceptable unless someone can convince me.

Pull request (without RubyInline) welcome, I would really appreciate your contribution. :)