lib/vegas/runner.rb in vegas-0.1.1 vs lib/vegas/runner.rb in vegas-0.1.2
- old
+ new
@@ -26,22 +26,32 @@
@runtime_args = runtime_args
self.class.logger.level = options[:debug] ? Logger::DEBUG : Logger::INFO
@rack_handler = @app.respond_to?(:detect_rack_handler) ?
@app.send(:detect_rack_handler) : Rack::Handler.get('thin')
- # load options from opt parser
+
+ # load options from opt parser
@args = define_options do |opts|
if block_given?
opts.separator ''
opts.separator "#{app_name} options:"
yield(self, opts, app)
end
end
+
+ # Call before run if before_run is a Proc
+ if before_run = options.delete(:before_run) and
+ before_run.is_a?(Proc)
+ before_run.call(self)
+ end
# set app options
@host = options[:host] || HOST
- @app.set(options) if @app.respond_to?(:set)
+ if @app.respond_to?(:set)
+ @app.set(options)
+ @app.set(:vegas, self)
+ end
# initialize app dir
FileUtils.mkdir_p(app_dir)
return if options[:start] === false
# evaluate the launch_path
path = if options[:launch_path] && options[:launch_path].respond_to?(:call)
@@ -179,9 +189,18 @@
logger.info "PID #{File.read(pid_file)}"
logger.info "URL #{File.read(url_file)}" if File.exists?(url_file)
else
logger.info "#{app_name} not running!"
end
+ end
+
+ # Loads a config file at config_path and evals it in the context of the @app.
+ def load_config_file(config_path)
+ abort "Can not find config file at #{config_path}" if !File.readable?(config_path)
+ config = File.read(config_path)
+ # trim off anything after __END__
+ config.sub!(/^__END__\n.*/, '')
+ @app.module_eval(config)
end
def self.logger=(logger)
@logger = logger
end