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



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

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

#explain(key) ⇒ Object

Raises:

  • (Thor::Error)


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

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



179
180
181
# File 'lib/tebako/build_commands.rb', line 179

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

#pruneObject

Raises:

  • (Thor::Error)


209
210
211
212
213
214
215
216
217
# File 'lib/tebako/build_commands.rb', line 209

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)


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

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



184
185
186
# File 'lib/tebako/build_commands.rb', line 184

def stats
  render(catalog.stats)
end

#verifyObject

Raises:

  • (Thor::Error)


189
190
191
192
193
194
195
196
# File 'lib/tebako/build_commands.rb', line 189

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