Class: Syncthing::Helper::API::UpdaterBase

Inherits:
Object
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/syncthing/helper/api/updater.rb

Direct Known Subclasses

DevicesUpdater, FoldersUpdater

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_obj: nil, col: nil) ⇒ UpdaterBase

Returns a new instance of UpdaterBase.



8
9
10
11
12
13
# File 'lib/syncthing/helper/api/updater.rb', line 8

def initialize config_obj: nil, col: nil
  super()
  @config_obj = config_obj
  @col = col
  listen
end

Instance Attribute Details

#config_objObject

Returns the value of attribute config_obj.



6
7
8
# File 'lib/syncthing/helper/api/updater.rb', line 6

def config_obj
  @config_obj
end

#current_snapshotObject

Returns the value of attribute current_snapshot.



6
7
8
# File 'lib/syncthing/helper/api/updater.rb', line 6

def current_snapshot
  @current_snapshot
end

#listenerObject

Returns the value of attribute listener.



6
7
8
# File 'lib/syncthing/helper/api/updater.rb', line 6

def listener
  @listener
end

Instance Method Details

#listenObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/syncthing/helper/api/updater.rb', line 15

def listen
  Logger.tagged('firestore/' + @col) {Logger.info 'Starting query listener'}
  @listener = (Firestore.col @col).listen do |snapshot|
    if snapshot.changes.count > 0
      @config_obj.retrieve
      @current_snapshot = snapshot
      snapshot.changes.each do |chng|
        @chng_obj = chng
        send "#{@col}_#{chng.type.to_s}".to_sym
      end
      @config_obj.update
      Logger.tagged('config_api: ' + @col.singularize + '/update') { Logger.debug 'Written' }
    end
  end
end

#removedObject Also known as: folders_removed, devices_removed



31
32
33
34
35
# File 'lib/syncthing/helper/api/updater.rb', line 31

def removed
  id_field = API::DB_FIELDS_CONFIG_OBJ[@col]
  @config_obj[@col].delete_if { |f| f[id_field] == @chng_obj.doc.document_id }
  Logger.tagged('config_api: ' + @col.singularize + '/rm') { Logger.debug @chng_obj.doc.document_id }
end