Class: MessageStore

Inherits:
Object
  • Object
show all
Defined in:
lib/imap-feeder/messagestore.rb

Constant Summary collapse

MESSAGES_TO_STORE =
100

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ MessageStore

Returns a new instance of MessageStore.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/imap-feeder/messagestore.rb', line 7

def initialize(file)
  @file = file
  @root = {}
  if File.exist? @file
    File.open(@file) do |f|
      @root = YAML.load(f) || {}
    end
  else
    $log.warn "#{file} does not exist, creating a new one."
  end
end

Instance Method Details

#add_new(folder, titles, number_of_entries = MESSAGES_TO_STORE) ⇒ Object



19
20
21
22
23
24
# File 'lib/imap-feeder/messagestore.rb', line 19

def add_new(folder, titles, number_of_entries = MESSAGES_TO_STORE)
  @root[folder] ||= []
  @root[folder].unshift(*titles)
  @root[folder].slice!((number_of_entries * 10)..-1)
  @root[folder].compact!
end

#get_archived(folder) ⇒ Object



26
27
28
# File 'lib/imap-feeder/messagestore.rb', line 26

def get_archived(folder)
  @root[folder] || []
end

#saveObject



30
31
32
33
34
# File 'lib/imap-feeder/messagestore.rb', line 30

def save
  File.open(@file, "w") do |f|
    YAML.dump(@root, f)
  end
end