Class: ActionTexter::FileDelivery

Inherits:
Object
  • Object
show all
Defined in:
lib/action_texter/file_delivery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ FileDelivery

Returns a new instance of FileDelivery.

Raises:

  • (ArgumentError)


4
5
6
7
8
# File 'lib/action_texter/file_delivery.rb', line 4

def initialize(config = {})
  @location = config[:location]
  raise ArgumentError, "you must specify config.action_texter.file_settings to contain a :location" unless @location
  Dir.mkdir(@location) unless Dir.exists?(@location)
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/action_texter/file_delivery.rb', line 3

def location
  @location
end

Instance Method Details

#deliver(message) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/action_texter/file_delivery.rb', line 10

def deliver(message)
  File.open(File.join(location, "#{message.to}.txt"), "a") do |file|
    file.puts("FROM: #{message.from}")
    file.puts(message.body)
    file.puts("-"*40)
  end
  true
end