Module: FasterPath

Defined in:
lib/faster_path.rb,
lib/faster_path/version.rb,
lib/faster_path/optional/refinements.rb,
lib/faster_path/optional/monkeypatches.rb

Defined Under Namespace

Modules: RefineFile, RefinePathname

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.absolute?(pth) ⇒ Boolean

Spec to Pathname#absolute?

Returns:

  • (Boolean)


7
8
9
# File 'lib/faster_path.rb', line 7

def self.absolute?(pth)
  Rust.is_absolute(pth)
end

.basename(pth, ext = "") ⇒ Object



29
30
31
# File 'lib/faster_path.rb', line 29

def self.basename(pth, ext="")
  Rust.basename(pth, ext)
end

.blank?(str) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/faster_path.rb', line 25

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

.chop_basename(pth) ⇒ Object

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.



20
21
22
23
# File 'lib/faster_path.rb', line 20

def self.chop_basename(pth)
  d,b = [Rust.dirname_for_chop(pth), Rust.basename_for_chop(pth)]
  [d,b] unless Rust.both_are_blank(d,b)
end

.relative?(pth) ⇒ Boolean

Spec to Pathname#relative?

Returns:

  • (Boolean)


12
13
14
# File 'lib/faster_path.rb', line 12

def self.relative?(pth)
  Rust.is_relative(pth)
end

.sledgehammer_everything! ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/faster_path/optional/monkeypatches.rb', line 2

def self.sledgehammer_everything!
  ::File.class_eval do
    def basename(pth)
      FasterPath.basename(pth)
    end 
  end 

  ::Pathname.class_eval do
    def absolute?
      FasterPath.absolute?(@path)
    end
 
    def chop_basename(pth)
      FasterPath.chop_basename(pth)
    end
    private :chop_basename

    def relative?
      FasterPath.relative?(@path)
    end
  end
end