Class: CoffeeTrace::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(insert_logging = CoffeeTrace::InsertLogging.new) ⇒ CLI

Returns a new instance of CLI.



3
4
5
6
# File 'lib/coffee_trace/cli.rb', line 3

def initialize insert_logging=CoffeeTrace::InsertLogging.new
  @insert_logging = insert_logging
  @files = Dir.glob "**/*.coffee"
end

Instance Method Details

#insert_loggingObject



8
9
10
11
12
13
14
# File 'lib/coffee_trace/cli.rb', line 8

def insert_logging
  @files.each do |file|
    prefix =File.basename file, ".coffee"
    result = @insert_logging.into File.readlines(file), prefix
    write_lines file, result 
  end
end

#remove_loggingObject



16
17
18
19
20
21
22
23
24
# File 'lib/coffee_trace/cli.rb', line 16

def remove_logging
  @files.each do |file|
    lines = @insert_logging.into File.readlines(file)
    result = lines.select do |line|
      /console\.log.*#coffee_trace.*/.match(line).nil?
    end
    write_lines file, result
  end
end