Class: Imap::Backup::Mirror::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/mirror/map.rb

Overview

Keeps track of the mapping between source and destination UIDs

Instance Method Summary collapse

Constructor Details

#initialize(pathname:, destination:) ⇒ Map



12
13
14
15
16
17
18
19
20
# File 'lib/imap/backup/mirror/map.rb', line 12

def initialize(pathname:, destination:)
  @pathname = pathname
  @destination = destination
  @store = nil
  @destination_store = nil
  @source_uid_validity = nil
  @destination_uid_validity = nil
  @map = nil
end

Instance Method Details

#check_uid_validities(source:, destination:) ⇒ Boolean



23
24
25
26
27
28
29
# File 'lib/imap/backup/mirror/map.rb', line 23

def check_uid_validities(source:, destination:)
  store
  return false if source != source_uid_validity
  return false if destination != destination_uid_validity

  true
end

#destination_uid(source_uid) ⇒ Integer?

Returns the destination UID that is equivalent to the given source UID or nil if it is not found.

Raises:

  • (RuntimeError)

    if the UID validity is not set



60
61
62
63
64
65
66
# File 'lib/imap/backup/mirror/map.rb', line 60

def destination_uid(source_uid)
  if destination_store == {}
    raise "Assign UID validities with #reset before calling #destination_uid"
  end

  map[source_uid]
end

#map_uids(source:, destination:) ⇒ void

This method returns an undefined value.

Creates a mapping between message UIDs on the source and destination servers

Raises:

  • (RuntimeError)

    if the UID validity is not set



72
73
74
75
76
# File 'lib/imap/backup/mirror/map.rb', line 72

def map_uids(source:, destination:)
  raise "Assign UID validities with #reset before calling #map_uids" if destination_store == {}

  map[source] = destination
end

#reset(source_uid_validity:, destination_uid_validity:) ⇒ void

This method returns an undefined value.

Sets, or resets to an empty state



33
34
35
36
37
38
39
40
# File 'lib/imap/backup/mirror/map.rb', line 33

def reset(source_uid_validity:, destination_uid_validity:)
  destination_store["source_uid_validity"] = source_uid_validity
  @source_uid_validity = nil
  destination_store["destination_uid_validity"] = destination_uid_validity
  @destination_uid_validity = nil
  destination_store["map"] = {}
  @map = nil
end

#savevoid

This method returns an undefined value.

Saves the map to disk as JSON



80
81
82
# File 'lib/imap/backup/mirror/map.rb', line 80

def save
  File.write(pathname, store.to_json)
end

#source_uid(destination_uid) ⇒ Integer?

Returns the source UID that is equivalent to the given destination UID or nil if it is not found.

Raises:

  • (RuntimeError)

    if the UID validity is not set



47
48
49
50
51
52
53
# File 'lib/imap/backup/mirror/map.rb', line 47

def source_uid(destination_uid)
  if destination_store == {}
    raise "Assign UID validities with #reset before calling #source_uid"
  end

  map.key(destination_uid)
end