Class: Kotoshu::CacheCommand
- Inherits:
-
Thor
- Object
- Thor
- Kotoshu::CacheCommand
- Defined in:
- lib/kotoshu/commands/cache_command.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #download(type, resource) ⇒ Object
- #info(type, resource) ⇒ Object
- #list(type = nil) ⇒ Object
- #purge(type = nil, resource = nil) ⇒ Object
- #status(type = nil) ⇒ Object
Instance Method Details
#clean ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kotoshu/commands/cache_command.rb', line 83 def clean total_removed = 0 total_reclaimed = 0 %w[language model frequency].each do |type| cache = cache_for_type(type) result = cache.clean total_removed += result[:expired_entries_removed] total_reclaimed += result[:bytes_reclaimed] end puts "Cleaned cache:" puts " Entries removed: #{total_removed}" puts " Bytes reclaimed: #{format_bytes(total_reclaimed)}" end |
#download(type, resource) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kotoshu/commands/cache_command.rb', line 24 def download(type, resource) cache = cache_for_type(type) case type when 'language', 'lang', 'l' download_language(cache, resource) when 'model', 'm' download_model(cache, resource) when 'frequency', 'freq', 'f' download_frequency(cache, resource) else puts "Error: Unknown cache type '#{type}'" puts "Available types: language, model, frequency" exit(1) end end |
#info(type, resource) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kotoshu/commands/cache_command.rb', line 42 def info(type, resource) cache = cache_for_type(type) case type when 'language', 'lang', 'l' info_language(cache, resource) when 'model', 'm' info_model(cache, resource) when 'frequency', 'freq', 'f' info_frequency(cache, resource) else puts "Error: Unknown cache type '#{type}'" puts "Available types: language, model, frequency" exit(1) end end |
#list(type = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/kotoshu/commands/cache_command.rb', line 12 def list(type = nil) type ||= [:type] || 'all' if type == 'all' list_all_types else list_type(type) end end |
#purge(type = nil, resource = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/kotoshu/commands/cache_command.rb', line 61 def purge(type = nil, resource = nil) type ||= [:type] if type.nil? || type == 'all' purge_all_types else purge_type(type, resource) end end |
#status(type = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/kotoshu/commands/cache_command.rb', line 72 def status(type = nil) type ||= [:type] || 'all' if type == 'all' status_all_types else status_type(type) end end |