Class: Consist::Commands::Mutate

Inherits:
Object
  • Object
show all
Includes:
Erbable
Defined in:
lib/consist/commands/mutate.rb

Instance Method Summary collapse

Methods included from Erbable

#erb_template, included

Constructor Details

#initialize(command) ⇒ Mutate

Returns a new instance of Mutate.



8
9
10
# File 'lib/consist/commands/mutate.rb', line 8

def initialize(command)
  @command = command
end

Instance Method Details

#perform!(executor) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/consist/commands/mutate.rb', line 12

def perform!(executor)
  delim = @command[:delim]
  target_file = @command[:target_file]
  target_string = erb_template(@command[:target_string])
  match = erb_template(@command[:match])

  case @command[:mode]
  when :replace
    cmd = "sed -i -E 's#{delim}#{match}#{delim}#{target_string}#{delim}' #{target_file} "
  end

  executor.execute(cmd, interaction_handler: Consist::Commands::StreamLogger.new)
end