Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/einfug.rb

Instance Method Summary collapse

Instance Method Details

#to_pastie(recursive = false, full = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/einfug.rb', line 4

def to_pastie(recursive = false, full = false)
  if self.file?
    return pastie(self, full)
  elsif self.directory?
    pathnames = []
    bad_paths = [Pathname.new('.'), Pathname.new('..')]
    
    self.children.each do |pathname|
      if recursive
        pathnames << pathname unless bad_paths.include?(pathname)
      elsif pathname.file?
        pathnames << pathname
      end
    end
    
    return pathnames.map { |pathname| pathname.to_pastie(recursive, full) }.join("\n")
  end
end