~singpolyma/dhall-ruby

95511b2dc03c6fdcd95c98db258ac7b686e21f24 — Stephen Paul Weber 1 year, 15 days ago 1f61d16 0.4.0
Helper to get ipfs path based on integrity check
3 files changed, 17 insertions(+), 0 deletions(-)

M dhall.gemspec
M lib/dhall/ast.rb
M test/test_resolve.rb
M dhall.gemspec => dhall.gemspec +1 -0
@@ 25,6 25,7 @@ Gem::Specification.new do |spec|
	spec.executables   = spec.files.grep(/^bin\//) { |f| File.basename(f) }
	spec.require_paths = ["lib"]

	spec.add_dependency "base32", "~> 0.3.2"
	spec.add_dependency "cbor", "~> 0.5.9.3"
	spec.add_dependency "citrus", "~> 3.0"
	spec.add_dependency "lazy_object", "~> 0.0.3"

M lib/dhall/ast.rb => lib/dhall/ast.rb +5 -0
@@ 1,5 1,6 @@
# frozen_string_literal: true

require "base32"
require "lazy_object"
require "multihashes"
require "uri"


@@ 1290,6 1291,10 @@ module Dhall
				digest.unpack("H*").first.encode(Encoding::UTF_8)
			end

			def ipfs
				"/ipfs/b#{Base32.encode("\x01\x55" + as_json).downcase.sub(/=*$/, "")}"
			end

			def check(expr)
				expr = expr.normalize
				return expr if expr.cache_key == to_s

M test/test_resolve.rb => test/test_resolve.rb +11 -0
@@ 254,6 254,17 @@ class TestResolve < Minitest::Test
		assert_equal Dhall::Variable["_"], subject(expr)
	end

	def test_integrity_check_ipfs
		check = Dhall::Import::IntegrityCheck.new(
			code:   0x12,
			digest: Dhall::Variable["_"].digest.digest
		)
		assert_equal(
			"/ipfs/bafkreidogqfzz75tpkmjzjke425xqcrmpcib2p5tg44hnbirumdbpl5adu",
			check.ipfs
		)
	end

	def test_cache
		req = stub_request(:get, "http://example.com/thing.dhall")
		      .to_return(status: 200, body: "\x00".b)