Class: Postpeek::Storage::FileSystem
- Inherits:
-
Base
- Object
- Base
- Postpeek::Storage::FileSystem
show all
- Defined in:
- lib/postpeek/storage/file_system.rb
Constant Summary
collapse
- ID_PATTERN =
/\A\d{8}T\d{6}_[0-9a-f]{8}\z/
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#clear ⇒ Object
37
38
39
|
# File 'lib/postpeek/storage/file_system.rb', line 37
def clear
email_dirs.each { |d| FileUtils.rm_rf(d) }
end
|
#count ⇒ Object
41
42
43
|
# File 'lib/postpeek/storage/file_system.rb', line 41
def count
email_dirs.length
end
|
#delete(id) ⇒ Object
33
34
35
|
# File 'lib/postpeek/storage/file_system.rb', line 33
def delete(id)
FileUtils.rm_rf(email_dir(id))
end
|
#fetch(id) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/postpeek/storage/file_system.rb', line 25
def fetch(id)
path = email_dir(id).join("metadata.json")
return nil unless path.exist?
JSON.parse(path.read, symbolize_names: true)
end
|
#list ⇒ Object
21
22
23
|
# File 'lib/postpeek/storage/file_system.rb', line 21
def list
email_dirs.sort_by { |d| -File.mtime(d).to_i }.map { |d| File.basename(d) }
end
|
#save(message) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/postpeek/storage/file_system.rb', line 12
def save(message)
dir = email_dir(message.id)
FileUtils.mkdir_p(dir)
write_artifacts(dir, message)
prune_if_needed
message.id
end
|