Module: Repper::Command

Defined in:
lib/repper/command.rb

Overview

Service object for exe/repper

Constant Summary collapse

PARSE_ERROR_EXIT_STATUS =
1

Class Method Summary collapse

Class Method Details

.call(argv) ⇒ Object



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

def call(argv)
  if argv.count == 0
    format_stdio
  else
    format_files(argv)
  end
end

.format(string) ⇒ Object



22
23
24
25
26
27
# File 'lib/repper/command.rb', line 22

def format(string)
  Codemod.call(string)
rescue Repper::Error => e
  warn "Parsing failed: #{e.class} - #{e.message}"
  exit PARSE_ERROR_EXIT_STATUS
end

.format_file(path) ⇒ Object



33
34
35
36
37
# File 'lib/repper/command.rb', line 33

def format_file(path)
  code = File.read(path)
  formatted_code = format(code)
  File.write(path, formatted_code)
end

.format_files(paths) ⇒ Object



29
30
31
# File 'lib/repper/command.rb', line 29

def format_files(paths)
  paths.grep(/\.rb\z/).each { |path| format_file(path) }
end

.format_stdioObject



16
17
18
19
20
# File 'lib/repper/command.rb', line 16

def format_stdio
  input = STDIN.read
  output = format(input)
  print output
end