lib/faster_path.rb in faster_path-0.0.1 vs lib/faster_path.rb in faster_path-0.0.2
- old
+ new
@@ -1,32 +1,39 @@
require "faster_path/version"
+require 'pathname'
require "ffi"
module FasterPath
+ # Spec to Pathname#absolute?
def self.absolute?(pth)
- Rust.absolute(pth)
+ Rust.is_absolute(pth)
end
- def self.monkeypatch_pathname
- class << ::Pathname
- def absolute?
- FasterPath.absolute?(@path)
- end
+ # Spec to Pathname#chop_basename
+ # WARNING! Pathname#chop_basename in STDLIB doesn't handle blank strings correctly!
+ # This implementation correctly handles blank strings just as Pathname had intended
+ # to handle non-path strings.
+ def self.chop_basename(pth)
+ d,b = [Rust.dirname(pth), Rust.basename(pth)]
+ if blank?(d) && blank?(b)
+ nil
+ else
+ [d,b]
end
end
- module RefinePathname
- refine Pathname do
- def absolute?
- FasterPath.absolute?(@path)
- end
- end
+ def self.blank?(str)
+ Rust.is_blank(str)
end
private
module Rust
extend FFI::Library
ffi_lib 'target/release/libfaster_path.so'
- attach_function :absolute, [ :string ], :bool
+ attach_function :is_absolute, [ :string ], :bool
+ attach_function :is_blank, [ :string ], :bool
+ attach_function :basename, [ :string ], :string
+ attach_function :dirname, [ :string ], :string
+ #attach_function :chop_basename, [ :string ], [:string]
end
private_constant :Rust
end