Module: Gat::Launcher::ClassMethods

Defined in:
lib/gat/launcher.rb

Instance Method Summary collapse

Instance Method Details

#launch(options, arguments) ⇒ Object

This method launches the Gatget Usage:

class ExampleGatget < Gat::Base
end

options = { :specific_gatget_options }

ExampleScript.launch(options, ARGV)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gat/launcher.rb', line 44

def launch(options, arguments)
  
  launch_error = false
  
  # Load Instance gatget. 
  #
  # Gatget exceptions are rescued by Instance Error if fails
  # Other exceptions are parsed as Undefined
  begin
    instance_gatget = self.new(options, arguments)
  rescue GatgetException, GatgetConfigException, GatgetArgumentException => error
    launch_error = GatgetInstanceException.new(error, error.exception_location)
  rescue => error
    launch_error = UndefinedException.new(error, 'initialize_gatget')
  end
  
  
  # If no error, continue with the process
  unless launch_error
    # Gatget exceptions are rescued and parsed as is.
    # Other exceptions are parsed as Undefined
    begin
      instance_gatget.execute
    rescue GatgetException, GatgetProcessException, GatgetConfigException, GatgetArgumentException  => error
      launch_error = error
    rescue => error
      launch_error = UndefinedException.new(error, 'launch_error')
    end
    

    # Rescue operations
    if launch_error and instance_gatget.methods.include?('onfail')
      begin
        instance_gatget.onfail_error = launch_error
        instance_gatget.logger.log("message", "failed_gatget", 'starting rescue operations for failed_gatget')
        instance_gatget.send('onfail')
      rescue => error
        $stderr.puts launch_error.exit_error
        # no controlled gatget failed, exit
        instance_gatget.logger.log("error", "failed_gatget", error.message)
        error_string = error.methods.include?('exception_message') ? error.exception_message : error
        launch_error = GatgetFatalException.new(error_string, 'launch')
      end
    end        
  end
  
  if launch_error   
    $stderr.puts launch_error.exit_error
    exit launch_error.exit_level  
  else
    # Success
    exit 0
  end
end