Class: Store

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/store.rb

Overview

Message storage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



10
11
12
# File 'lib/store.rb', line 10

def initialize
  self.messages = []
end

Instance Attribute Details

#messagesObject

Returns the value of attribute messages.



8
9
10
# File 'lib/store.rb', line 8

def messages
  @messages
end

Instance Method Details

#add(mail_from, rcpt_to, message_data) ⇒ Object

Saves message in storage



20
21
22
# File 'lib/store.rb', line 20

def add(mail_from, rcpt_to, message_data)
  messages.push message_data
end

#getObject

Returns array of messages



15
16
17
# File 'lib/store.rb', line 15

def get
  return messages
end

#remove(index) ⇒ Object

Removes message from storage



25
26
27
# File 'lib/store.rb', line 25

def remove(index)
  self.messages[index] = nil
end

#truncateObject

Remove empty messages



30
31
32
# File 'lib/store.rb', line 30

def truncate
  self.messages = self.messages.reject{ |message| message.nil? }
end