dstrelau (owner)

Revisions

gist: 31165 Download_button fork
public
Public Clone URL: git://gist.github.com/31165.git
Embed All Files: show embed
source.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# module: source
 
class Source < Thor
  class Clean < Thor
 
    desc "whitespace", "Clean trailing whitespace."
    method_options :extension => :optional
    def whitespace
      Dir.glob("./**/*#{options[:extension]}").each do |file|
        next unless File.file?(file)
        cleaned = []
        File.open(file) do |f|
          f.readlines.inject(cleaned) do |cleaned, line|
            cleaned << if line =~ /^\s+$/ then "\n" else line.sub(/[ ]+$/, '') end
          end
        end
        File.open(file, 'w') {|f| f.write(cleaned) }
      end
    end # def whitespace
 
  end # class Clean
end # class Source