module MotoRecall::Sampler::Util
Public Instance Methods
fetch_with_caching_and_logging(key, label, &block)
click to toggle source
# File lib/moto_recall/sampler/util.rb, line 5 def fetch_with_caching_and_logging(key, label, &block) result = CACHE.read(key) if result.nil? result = fetch_with_logging(label, &block) CACHE.write(key, result) else log("Reading #{label} from cache... #{result.length} found", { color: :yellow }) end result end
fetch_with_logging(label) { || ... }
click to toggle source
# File lib/moto_recall/sampler/util.rb, line 18 def fetch_with_logging(label, &block) print "Fetching #{label}... " t_0 = Time.now results = yield t_elapsed = (Time.now - t_0) * 1000 log_colored_count(results.length, "found (#{t_elapsed}ms)") results end
log(message, opts = {})
click to toggle source
# File lib/moto_recall/sampler/util.rb, line 36 def log(message, opts = {}) puts message.colorize(opts.slice(:color)) end
log_colored_count(count, message)
click to toggle source
# File lib/moto_recall/sampler/util.rb, line 30 def log_colored_count(count, message) log("#{count} #{message}", { color: count == 0 ? :red : :green }) end