Permalink
Browse files

Remove complicated logic of finding libtidy, let ffi do it.

This should work in most cases.
  • Loading branch information...
1 parent 49cbaa1 commit ef07729a53524d028be96affe1bdab4e134a9fa4 @libc committed Feb 13, 2012
Showing with 3 additions and 33 deletions.
  1. +2 −2 lib/tidy_ffi/lib_tidy.rb
  2. +1 −19 lib/tidy_ffi/tidy_ffi_extensions.rb
  3. +0 −12 spec/extensions_spec.rb
View
@@ -37,7 +37,7 @@ class TidyFFI::LibTidy #:nodoc:
attach_function :tidyOptIsReadOnly, [:pointer], :int
attach_function :tidyOptGetPickList, [:pointer], :pointer
attach_function :tidyOptGetNextPick, [:pointer, :pointer], :string
-
+
#types
# /** Option data types
# */
@@ -48,7 +48,7 @@ class TidyFFI::LibTidy #:nodoc:
# TidyBoolean /**< Boolean flag */
# } TidyOptionType;
TIDY_OPTION_TYPE = [:string, :integer, :boolean].freeze
-
+
end
class TidyFFI::LibTidy::TidyBuf < FFI::Struct #:nodoc:
@@ -6,25 +6,7 @@ def library_path=(path)
# Returns path to libtidy.{dylib,so}
def library_path
- @libtidy_path ||= find_tidy
+ @libtidy_path ||= 'tidy'
end
-
- def find_tidy
- fnames = ['libtidy.dylib', 'libtidy.so']
- paths = []
- paths += ENV['LD_LIBRARY_PATH'].split(':') if ENV['LD_LIBRARY_PATH']
- paths += ENV['DYLD_LIBRARY_PATH'].split(':') if ENV['DYLD_LIBRARY_PATH']
- paths += ENV['PATH'].split(':').reject { |a| a['sbin'] }.map { |a| a.sub('/bin', '/lib') } if ENV['PATH']
- paths = ['/usr/lib', '/usr/local/lib'] if paths.size == 0
- paths.uniq.each do |path|
- fnames.each do |fname|
- library_path = File.join(path, fname)
- return library_path if File.exists? library_path
- end
- end
- raise TidyFFI::LibTidyNotInstalled, "Could not find libtidy"
- nil
- end
- private :find_tidy
end
TidyFFI.extend TidyFFI::TidyFFIExtensions
View
@@ -1,12 +0,0 @@
-require 'spec_helper'
-
-describe TidyFFI::TidyFFIExtensions do
- include TidyFFI::TidyFFIExtensions
-
- describe '#find_tidy' do
- it 'raises TidyFFI::LibTidyNotInstalled if the library could not be found' do
- stub(File).exists? { false }
- expect { find_tidy }.to raise_error(TidyFFI::LibTidyNotInstalled)
- end
- end
-end

0 comments on commit ef07729

Please sign in to comment.