class Rzo::App
The application controller. An instance of this class models the application lifecycle. Input configuration follows the 12 factor model.
The general lifecycle is:
* app = App.new() * app.parse_options! * app.run
Public Class Methods
new(argv = ARGV.dup, env = ENV.to_hash, stdout = $stdout, stderr = $stderr)
click to toggle source
@param [Array] argv The argument vector, passed to the option parser.
@param [Hash] env The environment hash, passed to the option parser to
supply defaults not specified on the command line argument vector.
@return [App] the application instance.
# File lib/rzo/app.rb, line 43 def initialize(argv = ARGV.dup, env = ENV.to_hash, stdout = $stdout, stderr = $stderr) @argv = argv @env = env @stdout = stdout @stderr = stderr reset! end
Public Instance Methods
config()
click to toggle source
Accessor to Subcommand::Config
# File lib/rzo/app.rb, line 67 def config @config ||= Config.new(opts, @stdout, @stderr) end
educate()
click to toggle source
Override this later to allow trollop to write to an intercepted file descriptor for testing. This will avoid trollop's behavior of calling exit()
# File lib/rzo/app.rb, line 75 def educate Trollop.educate end
generate()
click to toggle source
Accessor to Subcommand::Generate
# File lib/rzo/app.rb, line 61 def generate @generate ||= Generate.new(opts, @stdout, @stderr) end
reset!()
click to toggle source
Reset all state associated with this application instance.
# File lib/rzo/app.rb, line 53 def reset! reset_options! reset_logging!(opts) @api = nil end
run()
click to toggle source
The main application run method
@return [Fixnum] the system exit code
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
# File lib/rzo/app.rb, line 85 def run case opts[:subcommand] when 'config' config.run when 'generate' generate.run when 'roles' Roles.new(opts, @stdout, @stderr).run else educate end rescue ErrorAndExit => e log.fatal e.message e.log_fatal.each { |m| log.fatal(m) } e.backtrace.each { |l| log.debug(l) } e.exit_status end