class Mailbot::Repository
Public Class Methods
new(path)
click to toggle source
@param path [String] The path to the text file to sync
# File lib/mailbot/repository.rb, line 6 def initialize(path) @path = path end
Public Instance Methods
entries()
click to toggle source
@return [Array<Mailbot::Entry>] An array of all entries in this repository
# File lib/mailbot/repository.rb, line 28 def entries Mailbot::Entry::Parser.new.parse read end
sync()
click to toggle source
# File lib/mailbot/repository.rb, line 10 def sync write(entries.map do |entry| if entry.synced? entry else begin Mailbot::Mailer.deliver subject: entry.subject, body: entry.render_body Mailbot::LOGGER.info "Succeeded to sync an entry: #{entry.subject}" entry.sync rescue => e Mailbot::LOGGER.warn "Failed to sync an entry: #{entry.subject}\n#{e.backtrace.join("\n")}" entry end end end.map(&:text).join("\n")) end
Private Instance Methods
read()
click to toggle source
# File lib/mailbot/repository.rb, line 38 def read open(@path, "r:UTF-8").read end
write(text)
click to toggle source
# File lib/mailbot/repository.rb, line 34 def write(text) open(@path, "w:UTF-8").write text end