Class: Mailbot::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/mailbot/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

Returns a new instance of Repository.

Parameters:

  • path (String)

    The path to the text file to sync



6
7
8
# File 'lib/mailbot/repository.rb', line 6

def initialize(path)
  @path = path
end

Instance Method Details

#entriesArray<Mailbot::Entry>

Returns An array of all entries in this repository.

Returns:

  • (Array<Mailbot::Entry>)

    An array of all entries in this repository



28
29
30
# File 'lib/mailbot/repository.rb', line 28

def entries
  Mailbot::Entry::Parser.new.parse read
end

#syncObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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