class Dhall::Resolvers::StandardFileCache

Public Class Methods

new( dir=Pathname.new(ENV.fetch( "XDG_CACHE_HOME", ENV.fetch("HOME") + "/.cache/" )) + "dhall/" ) click to toggle source
# File lib/dhall/resolve.rb, line 165
def initialize(
        dir=Pathname.new(ENV.fetch(
                "XDG_CACHE_HOME", ENV.fetch("HOME") + "/.cache/"
        )) + "dhall/"
)
        dir.mkpath
        @dir = dir
        @ram = RamCache.new
end

Public Instance Methods

fetch(key, &block) click to toggle source
# File lib/dhall/resolve.rb, line 175
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