Module: Flunkey::PathnameExtensions
- Defined in:
- lib/flunkey/pathname_extensions.rb
Constant Summary collapse
- BUNDLE_TEST =
/com\.apple\.bundle/
- EXCLUDE_PATTERNS =
[ /^\..*/ ]
Instance Method Summary collapse
- #browsable? ⇒ Boolean
- #bundle? ⇒ Boolean
- #compressable? ⇒ Boolean
- #downloadable? ⇒ Boolean
- #exclude_patterns ⇒ Object
- #excluded? ⇒ Boolean
- #filtered_children ⇒ Object
- #is_parent_of?(path) ⇒ Boolean
- #metadata(*keys) ⇒ Object
Instance Method Details
#browsable? ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/flunkey/pathname_extensions.rb', line 13 def browsable? return false unless exist? && readable? return false if bundle? return true if directory? false end |
#bundle? ⇒ Boolean
31 32 33 34 35 |
# File 'lib/flunkey/pathname_extensions.rb', line 31 def bundle? return false unless directory? return true if `/usr/bin/mdls -name kMDItemContentTypeTree #{to_s}` =~ BUNDLE_TEST false end |
#compressable? ⇒ Boolean
26 27 28 29 |
# File 'lib/flunkey/pathname_extensions.rb', line 26 def compressable? return false unless exist? && readable? true end |
#downloadable? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/flunkey/pathname_extensions.rb', line 20 def downloadable? return false unless exist? && readable? return false if directory? true end |
#exclude_patterns ⇒ Object
9 10 11 |
# File 'lib/flunkey/pathname_extensions.rb', line 9 def exclude_patterns @exclude_patterns || EXCLUDE_PATTERNS end |
#excluded? ⇒ Boolean
37 38 39 |
# File 'lib/flunkey/pathname_extensions.rb', line 37 def excluded? return true if exclude_patterns.any?{|pat| pat.match self.basename.to_s} end |
#filtered_children ⇒ Object
56 57 58 |
# File 'lib/flunkey/pathname_extensions.rb', line 56 def filtered_children children.delete_if(&:excluded?) end |
#is_parent_of?(path) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/flunkey/pathname_extensions.rb', line 45 def is_parent_of?(path) return false if path.nil? return false unless self.absolute? && path.absolute? return false if self == path p = path.to_s.split('/') self.to_s.split('/').each_with_index { |elem, idx| return false unless elem == p[idx] } true end |