module Smitty
Constants
- USAGE
- VERSION
Public Class Methods
croak(*messages)
click to toggle source
Prints variable amount of messages and exits
# File lib/smitty/croak.rb, line 3 def self.croak(*messages) messages.each { |message| puts "Error: #{message}"} exit(1) end
smtp_connect(server, port, ssl, username, password)
click to toggle source
# File lib/smitty/smtp_connect.rb, line 4 def self.smtp_connect(server, port, ssl, username, password) begin smtp_server = server.nil? ? 'localhost' : server smtp_port = port.nil? ? 25 : port.to_i smtp_conn = Net::SMTP.new(smtp_server, smtp_port) smtp_conn.enable_starttls() if ssl if username Smitty.croak('No password provided') if password.nil? if ssl smtp_conn.start(smtp_server, username, password, :login) else smtp_conn.start(smtp_server, username, password, :plain) end else smtp_conn.start() end smtp_conn rescue Exception => e Smitty.croak("Could not connect to SMTP server #{smtp_server}:#{smtp_port}", e.message) end end
variable_parser(variable_string, mail_length)
click to toggle source
# File lib/smitty/variable_parser.rb, line 2 def self.variable_parser(variable_string, mail_length) pairs = variable_string.split('=') # content is a file begin with_content = File.readlines(pairs[1]).map(&:chomp) Smitty.croak("#{pairs[0]} != recipient length") if with_content.length != mail_length rescue Errno::ENOENT with_content = pairs[1] rescue croak("Could not parse key value pair #{variable_string}") end {replace_string: pairs[0], with: with_content } end