Sha256: a089d5055f6051cba452a90d0c8423f29151c3d4b5fcb49ac8f9727de3aaced1

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require "faster_path/version"
require 'pathname'
require "ffi"

module FasterPath
  # Spec to Pathname#absolute?
  def self.absolute?(pth)
    Rust.is_absolute(pth)
  end

  def self.relative?(pth)
    Rust.is_relative(pth)
  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

  def self.blank?(str)
    Rust.is_blank(str)
  end

  private
  module Rust
    extend FFI::Library
    ffi_lib begin
      prefix = Gem.win_platform? ? "" : "lib"
      "#{File.expand_path("../target/release/", File.dirname(__FILE__))}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
    end
    attach_function :is_absolute, [ :string ], :bool
    attach_function :is_relative, [ :string ], :bool
    attach_function :is_blank, [ :string ], :bool
    attach_function :basename, [ :string ], :string
    attach_function :dirname, [ :string ], :string
  end
  private_constant :Rust
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faster_path-0.0.6 lib/faster_path.rb