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.7"

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

.add_trailing_separator(pth) ⇒ Object



38
39
40
# File 'lib/faster_path.rb', line 38

def self.add_trailing_separator(pth)
  Rust.add_trailing_separator(pth)
end

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



34
35
36
# File 'lib/faster_path.rb', line 34

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

.blank?(str) ⇒ Boolean

Returns:

  • (Boolean)


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

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.



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

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

.directory?(pth) ⇒ Boolean

Spec to Pathname#directory?

Returns:

  • (Boolean)


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

def self.directory?(pth)
  Rust.is_directory(pth)
end

.relative?(pth) ⇒ Boolean

Spec to Pathname#relative?

Returns:

  • (Boolean)


17
18
19
# File 'lib/faster_path.rb', line 17

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
24
25
26
27
28
29
30
31
32
# 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 directory?
      FasterPath.directory?(@path)
    end

    def chop_basename(pth)
      FasterPath.chop_basename(pth)
    end
    private :chop_basename

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

   def add_trailing_separator(pth)
      FasterPath.add_trailing_separator(pth)
   end
   private :add_trailing_separator
  end
end