From ed5d2a050c206e7d8035c60e86a25cbcd4329361 Mon Sep 17 00:00:00 2001 From: kmiller Date: Wed, 4 Jan 2023 10:04:17 -0500 Subject: [PATCH] Attempt to load compiled library from lib and ext to handle rubygems moving the library --- lib/levenshtein.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/levenshtein.rb b/lib/levenshtein.rb index f2f120d..4e48acc 100644 --- a/lib/levenshtein.rb +++ b/lib/levenshtein.rb @@ -4,10 +4,10 @@ module Levenshtein class << self extend FFI::Library - # Try loading in order. - library = File.dirname(__FILE__) + "/../ext/levenshtein/levenshtein" - candidates = ['.bundle', '.so', '.dylib', ''].map { |ext| library + ext } - ffi_lib(candidates) + library = "levenshtein.#{RbConfig::MAKEFILE_CONFIG['DLEXT']}" + candidates = ["#{__FILE__}/..", "#{__FILE__}/../../ext/levenshtein"] + candidates.unshift(Gem.loaded_specs['levenshtein-ffi'].extension_dir) if Gem.loaded_specs['levenshtein-ffi'] + ffi_lib(candidates.map { |dir| File.expand_path(library, dir) }) # Safe version of distance, checks that arguments are really strings. def distance(str1, str2)