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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kotoshu/commands/cache_command.rb', line 86 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kotoshu/commands/cache_command.rb', line 27 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kotoshu/commands/cache_command.rb', line 45 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
15 16 17 18 19 20 21 22 23 |
# File 'lib/kotoshu/commands/cache_command.rb', line 15 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
64 65 66 67 68 69 70 71 72 |
# File 'lib/kotoshu/commands/cache_command.rb', line 64 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
75 76 77 78 79 80 81 82 83 |
# File 'lib/kotoshu/commands/cache_command.rb', line 75 def status(type = nil) type ||= [:type] || 'all' if type == 'all' status_all_types else status_type(type) end end |