lib/fast_excel/binding.rb in fast_excel-0.4.0 vs lib/fast_excel/binding.rb in fast_excel-0.4.1
- old
+ new
@@ -3,18 +3,15 @@
require 'ffi'
module Libxlsxwriter
extend FFI::Library
- LIB_FILENAME = if RUBY_PLATFORM =~ /darwin/
- "libxlsxwriter.dylib"
- elsif ['x64-mingw32', 'i386-mingw32'].include? RUBY_PLATFORM
- "libxlsxwriter.dll"
- else
- "libxlsxwriter.so"
- end
+ LIB_FILENAME = "libxlsxwriter.#{FFI::Platform::LIBSUFFIX}".freeze
- ffi_lib File.expand_path("./../../../libxlsxwriter/lib/#{LIB_FILENAME}", __FILE__)
+ libs = [File.expand_path("../../#{LIB_FILENAME}", __FILE__)]
+ libs.unshift(File.join(Gem.loaded_specs['fast_excel'].extension_dir, LIB_FILENAME)) if Gem.loaded_specs['fast_excel']
+
+ ffi_lib(libs)
def self.attach_function(name, *_)
begin; super; rescue FFI::NotFoundError => e
(class << self; self; end).class_eval { define_method(name) { |*_| raise e } }
end