Class: Thrust::Tasks::Trim

Inherits:
Object
  • Object
show all
Defined in:
lib/thrust/tasks/trim.rb

Instance Method Summary collapse

Constructor Details

#initialize(executor = Thrust::Executor.new) ⇒ Trim

Returns a new instance of Trim.



4
5
6
# File 'lib/thrust/tasks/trim.rb', line 4

def initialize(executor = Thrust::Executor.new)
  @executor = executor
end

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/thrust/tasks/trim.rb', line 8

def run
  awk_statement = <<-AWK
  {
    if ($1 == "RM" || $1 == "R")
      print $4;
    else if ($1 != "D")
      print $2;
  }
  AWK

  awk_statement.gsub!(%r{\s+}, " ")

  @executor.system_or_exit %Q[git status --porcelain | awk '#{awk_statement}' | grep -e '.*\.[cmh]$' | xargs sed -i '' -e 's/	/    /g;s/ *$//g;']
end