Class: Tebako::CacheCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/tebako/build_commands.rb

Overview

tebako cache inspection and maintenance command group.

Instance Method Summary collapse

Instance Method Details

#cleanObject



236
237
238
239
# File 'lib/tebako/build_commands.rb', line 236

def clean
  catalog.clean
  render("cleaned" => true)
end

#explain(key) ⇒ Object

Raises:

  • (Thor::Error)


207
208
209
210
211
212
# File 'lib/tebako/build_commands.rb', line 207

def explain(key)
  matches = catalog.entries.select { |entry| entry.key == key || "#{entry.type}:#{entry.key}" == key }
  raise Thor::Error, "Cache artifact not found: #{key}" if matches.empty?

  render(matches.map(&:to_h))
end

#listObject



187
188
189
# File 'lib/tebako/build_commands.rb', line 187

def list
  render(catalog.entries.map(&:to_h))
end

#pruneObject

Raises:

  • (Thor::Error)


217
218
219
220
221
222
223
224
225
# File 'lib/tebako/build_commands.rb', line 217

def prune
  raise Thor::Error, "Specify --max-size or --older-than" unless options["max-size"] || options["older-than"]

  removed = catalog.prune(
    max_size: parse_size(options["max-size"]),
    older_than: parse_duration(options["older-than"])
  )
  render("removed" => removed.map(&:to_h), "removed_bytes" => removed.sum(&:byte_size))
end

#remove(key) ⇒ Object

Raises:

  • (Thor::Error)


228
229
230
231
232
233
# File 'lib/tebako/build_commands.rb', line 228

def remove(key)
  removed = catalog.remove(key)
  raise Thor::Error, "Cache artifact not found or currently in use: #{key}" if removed.empty?

  render("removed" => removed.map(&:to_h))
end

#statsObject



192
193
194
# File 'lib/tebako/build_commands.rb', line 192

def stats
  render(catalog.stats)
end

#verifyObject

Raises:

  • (Thor::Error)


197
198
199
200
201
202
203
204
# File 'lib/tebako/build_commands.rb', line 197

def verify
  invalid = catalog.verify
  render(
    "valid" => invalid.empty?,
    "invalid" => invalid.map(&:to_h)
  )
  raise Thor::Error, "#{invalid.length} corrupt cache artifact(s) found" unless invalid.empty?
end