Class: Syncthing::Helper::API::UpdaterBase
- Inherits:
-
Object
- Object
- Syncthing::Helper::API::UpdaterBase
- Includes:
- Concurrent::Async
- Defined in:
- lib/syncthing/helper/api/updater.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config_obj ⇒ Object
Returns the value of attribute config_obj.
-
#current_snapshot ⇒ Object
Returns the value of attribute current_snapshot.
-
#listener ⇒ Object
Returns the value of attribute listener.
Instance Method Summary collapse
-
#initialize(config_obj: nil, col: nil) ⇒ UpdaterBase
constructor
A new instance of UpdaterBase.
- #listen ⇒ Object
- #removed ⇒ Object (also: #folders_removed, #devices_removed)
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_obj ⇒ Object
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_snapshot ⇒ Object
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 |
#listener ⇒ Object
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
#listen ⇒ Object
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 |
#removed ⇒ Object 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 |