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

Returns a new instance of Map.



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

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

Returns whether the supplied values match the existing UID validity values.

Returns:

  • (Boolean)

    whether the supplied values match the existing UID validity values



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

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.

Parameters:

  • source_uid (Integer)

    a message UID from the source server

Returns:

  • (Integer, nil)

    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



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

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



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

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



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

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



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

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.

Parameters:

  • destination_uid (Integer)

    a message UID from the destination server

Returns:

  • (Integer, nil)

    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



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

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

  map.key(destination_uid)
end