lib/sc4ry/helpers.rb in sc4ry-0.2.0 vs lib/sc4ry/helpers.rb in sc4ry-0.2.1
- old
+ new
@@ -1,63 +1,58 @@
+# frozen_string_literal: true
+
# Sc4ry module
# @note namespace
module Sc4ry
-
-# Sc4ry::Helpers module
-# @note namespace
- module Helpers
-
+ # Sc4ry::Helpers module
+ # @note namespace
+ module Helpers
# class method (module) to help logging messages
# @param [Symbol] target a specific logger, restored old after
# @param [Symbol] level (default :info) a logging level (see Logger Stdlib)
# @param [String] message your message
# @return [Boolean]
- def Helpers.log(target: nil, level: :info, message: )
- save = Sc4ry::Loggers.current
+ def self.log(message:, target: nil, level: :info)
+ save = Sc4ry::Loggers.current
Sc4ry::Loggers.current = target if target
- Sc4ry::Loggers.get.send level, "Sc4ry : #{message}"
+ Sc4ry::Loggers.get.send level, "Sc4ry : #{message}"
Sc4ry::Loggers.current = save
- return true
+ true
end
# TCP/IP service checker
# @return [Bool] status
# @param [Hash] options
# @option options [String] :host hostname
# @option options [String] :port TCP port
# @option options [String] :url full URL, priority on :host and :port
- def Helpers.verify_service(options ={})
- begin
- if options[:url] then
- uri = URI.parse(options[:url])
- host = uri.host
- port = uri.port
- else
- host = options[:host]
- port = options[:port]
- end
- Timeout::timeout(1) do
- begin
- s = TCPSocket.new(host, port)
- s.close
- return true
- rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
- return false
- end
- end
- rescue Timeout::Error
+ def self.verify_service(options = {})
+ if options[:url]
+ uri = URI.parse(options[:url])
+ host = uri.host
+ port = uri.port
+ else
+ host = options[:host]
+ port = options[:port]
+ end
+ Timeout.timeout(1) do
+ s = TCPSocket.new(host, port)
+ s.close
+ return true
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
return false
end
+ rescue Timeout::Error
+ false
end
# class method (module) to help send notifiesby Sc4ry::Notifiers
# @param [Hash] options a Notifying structure
# @return [Boolean]
- def Helpers.notify(options = {})
+ def self.notify(options = {})
Sc4ry::Notifiers.list.each do |record|
notifier = Sc4ry::Notifiers.get name: record
- notifier[:class].notify(options) if options[:config][:notifiers].include? record
+ notifier[:class].notify(options) if options[:config][:notifiers].include? record
end
end
-
- end
-end
\ No newline at end of file
+ end
+end