Class: Imap::Backup::Serializer::Mbox

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/serializer/mbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_path) ⇒ Mbox

Returns a new instance of Mbox.



5
6
7
# File 'lib/imap/backup/serializer/mbox.rb', line 5

def initialize(folder_path)
  @folder_path = folder_path
end

Instance Attribute Details

#folder_pathObject (readonly)

Returns the value of attribute folder_path.



3
4
5
# File 'lib/imap/backup/serializer/mbox.rb', line 3

def folder_path
  @folder_path
end

Instance Method Details

#append(message) ⇒ Object



13
14
15
16
17
# File 'lib/imap/backup/serializer/mbox.rb', line 13

def append(message)
  File.open(pathname, "ab") do |file|
    file.write message
  end
end

#deleteObject



19
20
21
22
23
# File 'lib/imap/backup/serializer/mbox.rb', line 19

def delete
  return if !exist?

  File.unlink(pathname)
end

#lengthObject



25
26
27
28
29
# File 'lib/imap/backup/serializer/mbox.rb', line 25

def length
  return nil if !exist?

  File.stat(pathname).size
end

#pathnameObject



31
32
33
# File 'lib/imap/backup/serializer/mbox.rb', line 31

def pathname
  "#{folder_path}.mbox"
end

#rename(new_path) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/imap/backup/serializer/mbox.rb', line 35

def rename(new_path)
  if exist?
    old_pathname = pathname
    @folder_path = new_path
    File.rename(old_pathname, pathname)
  else
    @folder_path = new_path
  end
end

#rewind(length) ⇒ Object



45
46
47
48
49
# File 'lib/imap/backup/serializer/mbox.rb', line 45

def rewind(length)
  File.open(pathname, File::RDWR | File::CREAT, 0o644) do |f|
    f.truncate(length)
  end
end

#touchObject



51
52
53
# File 'lib/imap/backup/serializer/mbox.rb', line 51

def touch
  File.open(pathname, "a") {}
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/imap/backup/serializer/mbox.rb', line 9

def valid?
  exist?
end