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
-
#finder ⇒ Object
Returns the value of attribute finder.
Instance Method Summary collapse
-
#directory? ⇒ Boolean
Checks if this path represents a directory.
-
#exist? ⇒ Boolean
Checks if this path exists.
-
#file ⇒ File?
Opens the file if it’s a regular file.
-
#file? ⇒ Boolean
Checks if this path represents a regular file.
-
#finder_stat ⇒ File::Stat?
Gets the stat information for this path, handling errors appropriately.
-
#lstat ⇒ File::Stat?
Gets the stat information for this path (does not follow symlinks).
-
#pathname ⇒ Pathname
Creates a Pathname object from this path.
-
#stat ⇒ File::Stat?
Gets the stat information for this path (follows symlinks).
-
#suffix ⇒ String
Gets the file extension without the leading dot.
Instance Attribute Details
#finder ⇒ Object
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
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
79 80 81 |
# File 'lib/tins/find.rb', line 79 def exist? finder.protect_from_errors { File.exist?(self) } end |
#file ⇒ File?
Opens the file if it’s a regular 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
67 68 69 |
# File 'lib/tins/find.rb', line 67 def file? finder.protect_from_errors { s = finder_stat and s.file? } end |
#finder_stat ⇒ File::Stat?
Gets the stat information for this path, handling errors appropriately
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 |
#lstat ⇒ File::Stat?
Gets the stat information for this path (does not follow symlinks)
91 92 93 |
# File 'lib/tins/find.rb', line 91 def lstat finder.protect_from_errors { File.lstat(self) } end |
#pathname ⇒ Pathname
Creates a Pathname object from this path
97 98 99 |
# File 'lib/tins/find.rb', line 97 def pathname Pathname.new(self) end |
#stat ⇒ File::Stat?
Gets the stat information for this path (follows symlinks)
85 86 87 |
# File 'lib/tins/find.rb', line 85 def stat finder.protect_from_errors { File.stat(self) } end |
#suffix ⇒ String
Gets the file extension without the leading dot
103 104 105 |
# File 'lib/tins/find.rb', line 103 def suffix pathname.extname[1..-1] || '' end |