Sha256: db9825d2c34d581302591ea47613218261b05a8358472e3f8a25273e8f5edf09
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
require "simple_speaker/version" module SimpleSpeaker class Speaker def initialize(logger_path = nil, logger_error_path = nil, daemon_server = nil, user_input = nil) @logger = Logger.new(logger_path) unless logger_path.nil? @logger_error = Logger.new(logger_error_path) unless logger_error_path.nil? @daemon = daemon_server @user_input = user_input end def ask_if_needed(question, no_prompt = 0, default = 'y') ask_if_needed = default if no_prompt.to_i == 0 self.speak_up(question, 0) if Daemon.is_daemon? wtime = 0 while @user_input.nil? sleep 1 ask_if_needed = @user_input break if (wtime += 1) > USER_INPUT_TIMEOUT end @user_input = nil else ask_if_needed = STDIN.gets.strip end end ask_if_needed end def speak_up(str, in_mail = 1) puts str @daemon.send_data "#{str}\n" unless @daemon.nil? @logger.info(str) if @logger Thread.current[:email_msg] += str + NEW_LINE if Thread.current[:email_msg] && in_mail.to_i > 0 str end def log(str) @logger.info(str) if @logger end def tell_error(e, src) puts "In #{src}" @daemon.send_data "In #{src}\n" unless @daemon.nil? puts e @daemon.send_data "#{e}\n" unless @daemon.nil? @logger_error.error("ERROR #{Time.now.utc.to_s} #{src}") if @logger_error @logger_error.error(e) if @logger_error Thread.current[:email_msg] += "ERROR #{Time.now.utc.to_s} #{src}" + NEW_LINE if Thread.current[:email_msg] Thread.current[:email_msg] += e.to_s + NEW_LINE if Thread.current[:email_msg] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_speaker-0.1.8 | lib/simple_speaker.rb |