class FakeSMTPd::MessageStore

Attributes

message_dir[R]

Public Class Methods

new(message_dir) click to toggle source
# File lib/fakesmtpd/server.rb, line 366
def initialize(message_dir)
  @message_dir = message_dir
end

Public Instance Methods

[](message_id) click to toggle source
# File lib/fakesmtpd/server.rb, line 390
def [](message_id)
  message_file = "#{message_dir}/fakesmtpd-client-#{message_id}.json"
  if File.exists?(message_file)
    return message_file
  end
  nil
end
clear() click to toggle source
# File lib/fakesmtpd/server.rb, line 398
def clear
  FileUtils.rm_f(message_files)
end
store(message_id, from, recipients, body) click to toggle source
# File lib/fakesmtpd/server.rb, line 370
def store(message_id, from, recipients, body)
  outfile = File.join(message_dir, "fakesmtpd-client-#{message_id}.json")
  File.open(outfile, 'w:UTF-8') do |f|
    f.write JSON.pretty_generate(
      message_id: message_id,
      from: from,
      recipients: recipients,
      body: body,
    )
  end
  outfile
end
to_hash() click to toggle source
# File lib/fakesmtpd/server.rb, line 383
def to_hash
  message_files.each_with_object({}) do |filename, h|
    message_id = File.basename(filename, '.json').gsub(/[^0-9]+/, '')
    h[message_id] = File.expand_path(filename)
  end
end

Private Instance Methods

message_files() click to toggle source
# File lib/fakesmtpd/server.rb, line 404
def message_files
  Dir.glob("#{message_dir}/fakesmtpd-client-*.json")
end