lib/splash/exiter.rb in prometheus-splash-0.5.3 vs lib/splash/exiter.rb in prometheus-splash-0.6.0
- old
+ new
@@ -1,7 +1,11 @@
# coding: utf-8
+
+# base Splash namespace
module Splash
+
+ # Exiter namespace
module Exiter
include Splash::Loggers
EXIT_MAP= {
# context execution
@@ -33,10 +37,14 @@
:status_ok => {:message => "Status OK", :code => 0},
:status_ko => {:message => "Status KO", :code => 31}
}
+ # exiter wrapper
+ # @param [Hash] options
+ # @option options [Symbol] :case an exit case
+ # @option options [String] :more a complementary string to display
def splash_exit(options = {})
log = get_logger
mess = ""
mess = EXIT_MAP[options[:case]][:message] if EXIT_MAP[options[:case]].include? :message
mess << " : " unless mess.empty? or not options[:more]
@@ -48,9 +56,15 @@
log.fatal mess unless mess.empty?
exit EXIT_MAP[options[:case]][:code]
end
end
+ def splash_return(options = {})
+ data = EXIT_MAP[options[:case]]
+ data[:status] = (data[:code]>0)? :failure : :success
+ data[:more] = options[:more] if options[:more]
+ return data
+ end
end
end