class Translatomatic::CLI::Database

Database functions for the command line interface

Public Instance Methods

delete(text_id) click to toggle source

Delete a text and its translations from the database @param text_id [Number] id of text to delete @return [void]

# File lib/translatomatic/cli/database.rb, line 51
def delete(text_id)
  run do
    db = Translatomatic::Database.new(options)
    text = db.text.find(text_id)
    raise t('cli.database.text_not_found', id: text_id) unless text
    text.destroy
  end
end
drop() click to toggle source

Drop the database

# File lib/translatomatic/cli/database.rb, line 64
def drop
  run { Translatomatic::Database.new(options).drop }
end
info() click to toggle source

Show information about the database

# File lib/translatomatic/cli/database.rb, line 72
def info
  run do
    db = Translatomatic::Database.new(options)
    puts t('cli.database.text_count', count: db.text.count)
    texts_by_locale = db.text.group(:locale).count
    texts_by_locale.each do |locale, count|
      puts format('  (%<locale>s) %<count>d',
                  locale: locale.to_s, count: count)
    end
  end
end

Private Instance Methods

highlight(text, highlighted) click to toggle source
# File lib/translatomatic/cli/database.rb, line 86
def highlight(text, highlighted)
  text.gsub(highlighted) { |i| rainbow.wrap(i).bright.inverse }
end