Module: Syncthing::Helper::CLI::InstanceMethods

Included in:
AbstractCommand
Defined in:
lib/syncthing/helper/cli/abstract_command.rb

Instance Method Summary collapse

Instance Method Details

#colObject



26
27
28
# File 'lib/syncthing/helper/cli/abstract_command.rb', line 26

def col
  self.class.name.split('::').last.underscore.split('_').first.pluralize
end

#delete_recordObject



19
20
21
22
23
24
# File 'lib/syncthing/helper/cli/abstract_command.rb', line 19

def delete_record
  idents.each do |ident|
    @ident = ident
    query ? API::Firestore.doc(col + '/' + query.first.document_id).delete : puts('record not found')
  end
end

#queryObject



13
14
15
16
17
# File 'lib/syncthing/helper/cli/abstract_command.rb', line 13

def query
  API::DB_FIELDS[col].map do |f|
    API::Firestore.col(col).where(f, :eq, @ident)
  end.map(&:get).find(&:first)
end

#tabled_stdout(header: nil, rows: nil) ⇒ Object

DB_FIELDS = => [:device_id, :label],

'folders' => [:id, :path, :label]


8
9
10
11
# File 'lib/syncthing/helper/cli/abstract_command.rb', line 8

def tabled_stdout header: nil, rows: nil
  puts (TTY::Table.new header: header, rows: rows).
         render(:unicode, alignment: [:center], multiline: true)
end

#trigger_updatesObject



30
31
32
33
34
35
# File 'lib/syncthing/helper/cli/abstract_command.rb', line 30

def trigger_updates
  API::Firestore.col('folders').get.map(&:document_id).each do |d|
    API::Firestore.col('folders').doc(d).update(devices: [])
  end
  Logger.tagged('trigger') {Logger.debug 'Update firestore folders'}
end