Class: FileMessageObserver

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/message_observers.rb

Instance Method Summary collapse

Constructor Details

#initialize(message_directory, system_time = SystemTime.new) ⇒ FileMessageObserver

Returns a new instance of FileMessageObserver.



9
10
11
12
13
# File 'lib/message_observers.rb', line 9

def initialize(message_directory, system_time = SystemTime.new)
  @message_directory = message_directory
  @system_time = system_time
  mkdir_p(message_directory)
end

Instance Method Details

#update(message_string) ⇒ Object



15
16
17
18
19
20
# File 'lib/message_observers.rb', line 15

def update(message_string)
  mail = Mail.read_from_string(message_string)

  file_name = File.join(@message_directory, "#{@system_time.current_time_in_seconds}_#{mail.to.first}.txt")    
  File.open(file_name, 'w') {|file| file << message_string }
end