Class: JunitMerge::App

Inherits:
Object
  • Object
show all
Defined in:
lib/junit_merge/app.rb

Defined Under Namespace

Classes: SummaryDiff

Constant Summary collapse

Error =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ App



9
10
11
12
13
# File 'lib/junit_merge/app.rb', line 9

def initialize(options={})
  @stdin  = options[:stdin ] || STDIN
  @stdout = options[:stdout] || STDOUT
  @stderr = options[:stderr] || STDERR
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



15
16
17
# File 'lib/junit_merge/app.rb', line 15

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



15
16
17
# File 'lib/junit_merge/app.rb', line 15

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



15
16
17
# File 'lib/junit_merge/app.rb', line 15

def stdout
  @stdout
end

Instance Method Details

#run(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/junit_merge/app.rb', line 17

def run(*args)
  source_path, target_path = parse_args(args)

  not_found = [source_path, target_path].select { |path| !File.exist?(path) }
  not_found.empty? or
    raise Error, "no such file: #{not_found.join(', ')}"

  if File.directory?(source_path)
    Find.find(source_path) do |source_file_path|
      next if !File.file?(source_file_path)
      target_file_path = source_file_path.sub(source_path, target_path)
      if File.exist?(target_file_path)
        merge_file(source_file_path, target_file_path)
      else
        FileUtils.mkdir_p(File.dirname(target_file_path))
        FileUtils.cp(source_file_path, target_file_path)
      end
    end
  elsif File.exist?(source_path)
    merge_file(source_path, target_path)
  else
    raise Error, "no such file: #{source_path}"
  end
  0
rescue Error => error
  stderr.puts error.message
  1
end