Module: Tins::Find::Finder::PathExtension

Defined in:
lib/tins/find.rb

Overview

Extension module that adds convenience methods to Pathname objects during the find operation. These methods provide access to finder functionality and handle errors gracefully.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#finderObject

Returns the value of attribute finder.



47
48
49
# File 'lib/tins/find.rb', line 47

def finder
  @finder
end

Instance Method Details

#directory?Boolean

Checks if this path represents a directory

Returns:

  • (Boolean)

    true if the path is a directory



73
74
75
# File 'lib/tins/find.rb', line 73

def directory?
  finder.protect_from_errors { s = finder_stat and s.directory? }
end

#exist?Boolean

Checks if this path exists

Returns:

  • (Boolean)

    true if the path exists



79
80
81
# File 'lib/tins/find.rb', line 79

def exist?
  finder.protect_from_errors { File.exist?(self) }
end

#fileFile?

Opens the file if it’s a regular file

Returns:

  • (File, nil)

    File object or nil if not a file



59
60
61
62
63
# File 'lib/tins/find.rb', line 59

def file
  finder.protect_from_errors do
    File.new(self) if file?
  end
end

#file?Boolean

Checks if this path represents a regular file

Returns:

  • (Boolean)

    true if the path is a regular file



67
68
69
# File 'lib/tins/find.rb', line 67

def file?
  finder.protect_from_errors { s = finder_stat and s.file? }
end

#finder_statFile::Stat?

Gets the stat information for this path, handling errors appropriately

Returns:

  • (File::Stat, nil)

    File statistics or nil on error



51
52
53
54
55
# File 'lib/tins/find.rb', line 51

def finder_stat
  finder.protect_from_errors do
    finder.follow_symlinks ? File.stat(self) : File.lstat(self)
  end
end

#lstatFile::Stat?

Gets the stat information for this path (does not follow symlinks)

Returns:

  • (File::Stat, nil)

    File statistics or nil on error



91
92
93
# File 'lib/tins/find.rb', line 91

def lstat
  finder.protect_from_errors { File.lstat(self) }
end

#pathnamePathname

Creates a Pathname object from this path

Returns:

  • (Pathname)

    Pathname object for this path



97
98
99
# File 'lib/tins/find.rb', line 97

def pathname
  Pathname.new(self)
end

#statFile::Stat?

Gets the stat information for this path (follows symlinks)

Returns:

  • (File::Stat, nil)

    File statistics or nil on error



85
86
87
# File 'lib/tins/find.rb', line 85

def stat
  finder.protect_from_errors { File.stat(self) }
end

#suffixString

Gets the file extension without the leading dot

Returns:

  • (String)

    File extension or empty string if no extension



103
104
105
# File 'lib/tins/find.rb', line 103

def suffix
  pathname.extname[1..-1] || ''
end