Class: Imap::Backup::Mirror::Map
- Inherits:
-
Object
- Object
- Imap::Backup::Mirror::Map
- Defined in:
- lib/imap/backup/mirror/map.rb
Overview
Keeps track of the mapping between source and destination UIDs
Instance Method Summary collapse
-
#check_uid_validities(source:, destination:) ⇒ Boolean
Whether the supplied values match the existing UID validity values.
-
#destination_uid(source_uid) ⇒ Integer?
The destination UID that is equivalent to the given source UID or nil if it is not found.
-
#initialize(pathname:, destination:) ⇒ Map
constructor
A new instance of Map.
-
#map_uids(source:, destination:) ⇒ void
Creates a mapping between message UIDs on the source and destination servers.
-
#reset(source_uid_validity:, destination_uid_validity:) ⇒ void
Sets, or resets to an empty state.
-
#save ⇒ void
Saves the map to disk as JSON.
-
#source_uid(destination_uid) ⇒ Integer?
The source UID that is equivalent to the given destination UID or nil if it is not found.
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.
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.
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
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 |
#save ⇒ void
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.
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 |