lib/faster_path.rb in faster_path-0.2.3 vs lib/faster_path.rb in faster_path-0.2.4
- old
+ new
@@ -1,127 +1,75 @@
require "faster_path/version"
require 'pathname'
-require "ffi"
+require 'faster_path/platform'
require 'faster_path/asset_resolution'
+require 'fiddle'
+require 'fiddle/import'
module FasterPath
- FFI_LIBRARY = begin
- prefix = Gem.win_platform? ? "" : "lib"
- "#{File.expand_path("../target/release/", __dir__)}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
- end
- require 'fiddle'
- library = Fiddle.dlopen(FFI_LIBRARY)
+ FFI_LIBRARY = FasterPath::Platform.ffi_library()
+
Fiddle::Function.
- new(library['Init_faster_pathname'], [], Fiddle::TYPE_VOIDP).
+ new(Fiddle.dlopen(FFI_LIBRARY)['Init_faster_pathname'], [], Fiddle::TYPE_VOIDP).
call
- FasterPathname::Public.class_eval do
- private_class_method :absolute?
- private_class_method :add_trailing_separator
+ Public.class_eval do
private_class_method :basename
- private_class_method :children # String results
- private_class_method :children_compat # wrap Pathname on each
+ private_class_method :children
+ private_class_method :children_compat
private_class_method :chop_basename
- private_class_method :cleanpath_aggressive
- private_class_method :directory?
- private_class_method :dirname
- private_class_method :entries # String results
- private_class_method :entries_compat # wrap Pathname on each
- private_class_method :extname
- private_class_method :has_trailing_separator?
- private_class_method :plus
- private_class_method :relative?
+ private_class_method :entries
+ private_class_method :entries_compat
end
- FasterPathname.class_eval do
- def initialize(arg)
- unless arg.is_a? String
- arg = arg.to_s
- end
- raise(ArgumentError, "null byte found") if arg.include?("\0")
- @path = arg
- end
-
- # BAD; exposes private methods
- # Need to reprivatize specific methods
- def method_missing(method_name, *a, &b)
- Public.send(method_name, @path, *a, &b)
- end
-
- def respond_to?(method_name, include_private = false)
- Public.send(:respond_to?, method_name) || super
- end
- end
-
def self.rust_arch_bits
Rust.rust_arch_bits
end
def self.ruby_arch_bits
1.size * 8
end
- def self.absolute?(pth)
- FasterPathname::Public.send(:absolute?, pth)
- end
-
- def self.add_trailing_separator(pth)
- FasterPathname::Public.send(:add_trailing_separator, pth)
- end
-
def self.blank?(str)
"#{str}".strip.empty?
end
def self.basename(pth, ext="")
- FasterPathname::Public.send(:basename, pth, ext)
+ Public.send(:basename, pth, ext)
end
def self.children(pth, with_directory=true)
- FasterPathname::Public.send(:children, pth, with_directory)
+ result = Public.send(:children, pth, with_directory)
+ return result if result
+ raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
end
+ def self.children_compat(pth, with_directory=true)
+ result = Public.send(:children_compat, pth, with_directory)
+ return result if result
+ raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
+ end
+
def self.chop_basename(pth)
- result = FasterPathname::Public.send(:chop_basename, pth)
+ result = Public.send(:chop_basename, pth)
result unless result.empty?
end
- def self.cleanpath_aggressive(pth)
- FasterPathname::Public.send(:cleanpath_aggressive, pth)
- end
-
- def self.directory?(pth)
- FasterPathname::Public.send(:directory?, pth)
- end
-
- def self.dirname(pth)
- FasterPathname::Public.send(:dirname, pth)
- end
-
def self.entries(pth)
- FasterPathname::Public.send(:entries, pth)
+ result = Public.send(:entries, pth)
+ return result if result
+ raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
end
- def self.extname(pth)
- FasterPathname::Public.send(:extname, pth)
+ def self.entries_compat(pth)
+ result = Public.send(:entries_compat, pth)
+ return result if result
+ raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
end
- def self.has_trailing_separator?(pth)
- FasterPathname::Public.send(:has_trailing_separator?, pth)
- end
-
- def self.plus(pth, pth2)
- FasterPathname::Public.send(:plus, pth, pth2)
- end
-
- def self.relative?(pth)
- FasterPathname::Public.send(:relative?, pth)
- end
-
module Rust
- extend FFI::Library
- ffi_lib ::FasterPath::FFI_LIBRARY
-
- attach_function :rust_arch_bits, [], :int32
+ extend Fiddle::Importer
+ dlload FFI_LIBRARY
+ extern 'int rust_arch_bits()'
end
private_constant :Rust
end