Class: Filegen::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/filegen/runner.rb

Overview

Commandline from end

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel) ⇒ Runner

Create runner

Parameters:

  • argv (Array)

    Commandline arguments

  • stdin (IO) (defaults to: $stdin)

    Stdin

  • stdout (IO) (defaults to: $stdout)

    Stdout

  • stderr (IO) (defaults to: $stderr)

    Stderr

  • kernel (Kernel) (defaults to: Kernel)

    Kernel class



22
23
24
# File 'lib/filegen/runner.rb', line 22

def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel)
  @argv, $stdin, $stdout, Ui.logger, @kernel = argv, stdin, stdout, stderr, kernel
end

Instance Method Details

#execute!Object

Execute runner



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/filegen/runner.rb', line 27

def execute!
  begin
    options   = Options.new(argv)

    generator = ErbGenerator.new(Data.new(options.data_sources))
    generator.compile(options.source, options.destination)

    exitstatus = 0
  rescue Interrupt
    Filegen::Ui.warning 'You told me to stop command execution.'
    exitstatus = 2
  rescue Exceptions::ErbTemplateHasSyntaxErrors => e
    Filegen::Ui.error "Syntax error in ERB-Template: \n" + e.message
    exitstatus = 3
  rescue Exceptions::YamlFileNotFound => e
    Filegen::Ui.error "Yaml-file \"#{JSON.parse(e.message)['file']}\" not found."
    exitstatus = 4
  rescue StandardError => e
    Filegen::Ui.error "#{e.class} - #{e.message}"
    exitstatus = 99
  end

  @kernel.exit(exitstatus)
end