Class: Dhall::Resolvers::StandardFileCache
- Inherits:
-
Object
- Object
- Dhall::Resolvers::StandardFileCache
- Defined in:
- lib/dhall/resolve.rb
Instance Method Summary collapse
- #fetch(key, &block) ⇒ Object
-
#initialize(dir = Pathname.new(ENV.fetch( "XDG_CACHE_HOME", ENV.fetch("HOME") + "/.cache/" )) + "dhall/") ⇒ StandardFileCache
constructor
A new instance of StandardFileCache.
Constructor Details
#initialize(dir = Pathname.new(ENV.fetch( "XDG_CACHE_HOME", ENV.fetch("HOME") + "/.cache/" )) + "dhall/") ⇒ StandardFileCache
Returns a new instance of StandardFileCache.
166 167 168 169 170 171 172 173 174 |
# File 'lib/dhall/resolve.rb', line 166 def initialize( dir=Pathname.new(ENV.fetch( "XDG_CACHE_HOME", ENV.fetch("HOME") + "/.cache/" )) + "dhall/" ) dir.mkpath @dir = dir @ram = RamCache.new end |
Instance Method Details
#fetch(key, &block) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/dhall/resolve.rb', line 176 def fetch(key, &block) if key.is_a?(String) && key.start_with?("sha256:") file = @dir + key.sub(/^sha256:/, "1220") return Dhall.from_binary(file.binread) if file.exist? Promise.resolve(nil).then(&block).then do |result| file.open("wb") { |fh| fh.write(result.to_cbor) } result end else @ram.fetch(key, &block) end end |