Class: Dhall::Resolvers::Standard

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/resolve.rb

Direct Known Subclasses

Default, LocalOnly

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_reader: ReadPathSources, http_reader: StandardReadHttpSources, https_reader: http_reader, environment_reader: ReadEnvironmentSources, cache: StandardFileCache.new, max_depth: Float::INFINITY) ⇒ Standard

Returns a new instance of Standard.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/dhall/resolve.rb', line 257

def initialize(
	path_reader: ReadPathSources,
	http_reader: StandardReadHttpSources,
	https_reader: http_reader,
	environment_reader: ReadEnvironmentSources,
	cache: StandardFileCache.new,
	max_depth: Float::INFINITY
)
	@path_resolutions = ResolutionSet.new(path_reader, max_depth: max_depth)
	@http_resolutions = ResolutionSet.new(http_reader, max_depth: max_depth)
	@https_resolutions = ResolutionSet.new(https_reader, max_depth: max_depth)
	@env_resolutions = ResolutionSet.new(
		environment_reader, max_depth: max_depth
	)
	@deadline = Util::NoDeadline.new
	@cache = cache
end

Instance Attribute Details

#deadlineObject (readonly)

Returns the value of attribute deadline.



255
256
257
# File 'lib/dhall/resolve.rb', line 255

def deadline
  @deadline
end

Instance Method Details

#cache_fetch(key, &fallback) ⇒ Object



283
284
285
286
287
# File 'lib/dhall/resolve.rb', line 283

def cache_fetch(key, &fallback)
	@cache.fetch(key) do
		Promise.resolve(nil).then(&fallback)
	end
end

#child(parent_source) ⇒ Object



337
338
339
340
341
342
343
344
345
346
# File 'lib/dhall/resolve.rb', line 337

def child(parent_source)
	dup.tap do |c|
		c.instance_eval do
			@path_resolutions = @path_resolutions.child(parent_source)
			@env_resolutions = @env_resolutions.child(parent_source)
			@http_resolutions = @http_resolutions.child(parent_source)
			@https_resolutions = @https_resolutions.child(parent_source)
		end
	end
end

#finish!Object



325
326
327
328
329
330
331
332
333
334
335
# File 'lib/dhall/resolve.rb', line 325

def finish!
	[
		@path_resolutions,
		@env_resolutions,
		@http_resolutions,
		@https_resolutions
	].each do |rset|
		Util.match_result_promises(*rset.resolutions, &rset.reader)
	end
	freeze
end

#resolve_environment(env_source) ⇒ Object



295
296
297
298
299
# File 'lib/dhall/resolve.rb', line 295

def resolve_environment(env_source)
	@env_resolutions.register(
		SourceWithDeadline.new(env_source, @deadline)
	)
end

#resolve_http(http_source) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
# File 'lib/dhall/resolve.rb', line 301

def resolve_http(http_source)
	http_source.headers.resolve(
		resolver:    self,
		relative_to: Dhall::Import::RelativePath.new
	).then do |headers|
		source = http_source.with(headers: headers.normalize)
		@http_resolutions.register(
			SourceWithDeadline.new(source, @deadline)
		)
	end
end

#resolve_https(https_source) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
# File 'lib/dhall/resolve.rb', line 313

def resolve_https(https_source)
	https_source.headers.resolve(
		resolver:    self,
		relative_to: Dhall::Import::RelativePath.new
	).then do |headers|
		source = https_source.with(headers: headers.normalize)
		@https_resolutions.register(
			SourceWithDeadline.new(source, @deadline)
		)
	end
end

#resolve_path(path_source) ⇒ Object



289
290
291
292
293
# File 'lib/dhall/resolve.rb', line 289

def resolve_path(path_source)
	@path_resolutions.register(
		SourceWithDeadline.new(path_source, @deadline)
	)
end

#with_deadline(deadline) ⇒ Object



275
276
277
278
279
280
281
# File 'lib/dhall/resolve.rb', line 275

def with_deadline(deadline)
	dup.tap do |c|
		c.instance_eval do
			@deadline = deadline
		end
	end
end