Module: Flunkey::PathnameExtensions

Defined in:
lib/flunkey/pathname_extensions.rb

Constant Summary collapse

BUNDLE_TEST =
/com\.apple\.bundle/
EXCLUDE_PATTERNS =
[
  /^\..*/
]

Instance Method Summary collapse

Instance Method Details

#browsable?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/flunkey/pathname_extensions.rb', line 26

def compressable?
  return false unless exist? && readable?
  true
end

#downloadable?Boolean

Returns:

  • (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_patternsObject



9
10
11
# File 'lib/flunkey/pathname_extensions.rb', line 9

def exclude_patterns
  @exclude_patterns || EXCLUDE_PATTERNS
end

#excluded?Boolean

Returns:

  • (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_childrenObject



56
57
58
# File 'lib/flunkey/pathname_extensions.rb', line 56

def filtered_children
  children.delete_if(&:excluded?)
end

#is_parent_of?(path) ⇒ Boolean

Returns:

  • (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

#metadata(*keys) ⇒ Object



41
42
43
# File 'lib/flunkey/pathname_extensions.rb', line 41

def (*keys)
  @metadata ||= Flunkey::Metadata.parse `/usr/bin/mdls #{to_s}`
end