Class: Kettle::Dev::PreReleaseCLI::ImageUrlCache
- Inherits:
-
Object
- Object
- Kettle::Dev::PreReleaseCLI::ImageUrlCache
- Defined in:
- lib/kettle/dev/pre_release_cli.rb,
sig/kettle/dev/pre_release_cli.rbs
Overview
Persistent cache of successfully validated Markdown image URLs.
Constant Summary collapse
- VERSION =
1
Class Method Summary collapse
Instance Method Summary collapse
- #fresh_success?(url) ⇒ Boolean
-
#initialize(path:, ttl_seconds: IMAGE_URL_CACHE_TTL_SECONDS, clock: -> { Time.now }) ⇒ ImageUrlCache
constructor
A new instance of ImageUrlCache.
- #to_h ⇒ Hash[String, untyped]
- #write_success(url) ⇒ void
Constructor Details
#initialize(path:, ttl_seconds: IMAGE_URL_CACHE_TTL_SECONDS, clock: -> { Time.now }) ⇒ ImageUrlCache
Returns a new instance of ImageUrlCache.
114 115 116 117 118 119 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 114 def initialize(path:, ttl_seconds: IMAGE_URL_CACHE_TTL_SECONDS, clock: -> { Time.now }) @path = path @ttl_seconds = ttl_seconds @clock = clock @data = nil end |
Class Method Details
.default_path ⇒ String?
106 107 108 109 110 111 112 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 106 def self.default_path state_home = ENV["XDG_STATE_HOME"] state_home = File.join(Dir.home, ".local", "state") if state_home.to_s.empty? File.join(state_home, "kettle-dev", "image-url-cache.json") rescue ArgumentError nil end |
Instance Method Details
#fresh_success?(url) ⇒ Boolean
121 122 123 124 125 126 127 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 121 def fresh_success?(url) entry = data.fetch("images")[url.to_s] return false unless entry.is_a?(Hash) return false unless entry["ok"] == true fresh_entry?(entry) end |
#to_h ⇒ Hash[String, untyped]
140 141 142 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 140 def to_h data end |
#write_success(url) ⇒ void
This method returns an undefined value.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 129 def write_success(url) return if @path.to_s.empty? return if url.to_s.empty? data.fetch("images")[url.to_s] = { "ok" => true, "cached_at" => @clock.call.utc.iso8601 } save! end |