Class: FreezingEmail::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/freezing_email/storage.rb

Class Method Summary collapse

Class Method Details

.cleanup(mask = "") ⇒ Object



3
4
5
# File 'lib/freezing_email/storage.rb', line 3

def cleanup(mask = "")
  FileUtils.rm_rf(files_list(mask))
end

.dirObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/freezing_email/storage.rb', line 28

def dir
  dir = FreezingEmail::Config[:store_path]

  if defined?(Rails)
    dir = Rails.root.join(dir)
  end

  Dir.mkdir(dir) unless Dir.exists?(dir)

  dir
end

.indexObject



7
8
9
10
11
12
13
14
15
# File 'lib/freezing_email/storage.rb', line 7

def index
  emails = []

  files_list.each do |file|
    emails << load(file)
  end

  emails
end

.load(name) ⇒ Object



21
22
23
24
25
26
# File 'lib/freezing_email/storage.rb', line 21

def load(name)
  file_name = expand_name(name)
  if File.exists?(file_name)
    YAML::load(IO.read(file_name))
  end
end

.save(name, object) ⇒ Object



17
18
19
# File 'lib/freezing_email/storage.rb', line 17

def save(name, object)
  File.open(expand_name(name), 'w') { |f| f.puts YAML::dump(object) }
end