Add --sqlite-db option to allow for persistant storage

This commit is contained in:
Travis Burtrum 2016-08-10 15:38:34 -04:00
parent fb91dd0902
commit d42f2bf11d
2 changed files with 8 additions and 3 deletions

View File

@ -80,6 +80,7 @@ module MailCatcher extend self
:daemon => !windows?,
:browse => false,
:quit => true,
:sqlite_db => ':memory:',
}
def options
@ -120,6 +121,10 @@ module MailCatcher extend self
options[:quit] = false
end
parser.on("--sqlite-db PATH", "Set the path to the sqlite database, default in-memory only") do |db|
options[:sqlite_db] = db
end
if mac?
parser.on("--[no-]growl") do |growl|
puts "Growl is no longer supported"

View File

@ -6,9 +6,9 @@ require "sqlite3"
module MailCatcher::Mail extend self
def db
@__db ||= begin
SQLite3::Database.new(":memory:", :type_translation => true).tap do |db|
SQLite3::Database.new(MailCatcher.options[:sqlite_db], :type_translation => true).tap do |db|
db.execute(<<-SQL)
CREATE TABLE message (
CREATE TABLE IF NOT EXISTS message (
id INTEGER PRIMARY KEY ASC,
sender TEXT,
recipients TEXT,
@ -20,7 +20,7 @@ module MailCatcher::Mail extend self
)
SQL
db.execute(<<-SQL)
CREATE TABLE message_part (
CREATE TABLE IF NOT EXISTS message_part (
id INTEGER PRIMARY KEY ASC,
message_id INTEGER NOT NULL,
cid TEXT,