Class: LetterOpenerWeb::Letter
Instance Attribute Summary
Attributes inherited from BaseLetter
#id, #sent_at
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseLetter
#default_style, find, #headers, #initialize, letters_location, #plain_text, #rich_text, #to_param
Class Method Details
.destroy_all ⇒ Object
12
13
14
|
# File 'app/models/letter_opener_web/letter.rb', line 12
def self.destroy_all
FileUtils.rm_rf(letters_location)
end
|
.search ⇒ Object
5
6
7
8
9
10
|
# File 'app/models/letter_opener_web/letter.rb', line 5
def self.search
letters = Dir.glob("#{letters_location}/*").map do |folder|
new(id: File.basename(folder), sent_at: File.mtime(folder))
end
letters.sort_by(&:sent_at).reverse
end
|
Instance Method Details
#attachments ⇒ Object
16
17
18
19
20
|
# File 'app/models/letter_opener_web/letter.rb', line 16
def attachments
@attachments ||= Dir["#{base_dir}/attachments/*"].each_with_object({}) do |file, hash|
hash[File.basename(file)] = File.expand_path(file)
end
end
|
#delete ⇒ Object
22
23
24
25
26
|
# File 'app/models/letter_opener_web/letter.rb', line 22
def delete
return unless valid?
FileUtils.rm_rf(base_dir.to_s)
end
|
#valid? ⇒ Boolean
28
29
30
|
# File 'app/models/letter_opener_web/letter.rb', line 28
def valid?
exists? && base_dir_within_letters_location?
end
|