Class: Dhall::Resolvers::ResolutionSet

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

Instance Method Summary collapse

Constructor Details

#initialize(reader, max_depth:) ⇒ ResolutionSet

Returns a new instance of ResolutionSet.



191
192
193
194
195
196
# File 'lib/dhall/resolve.rb', line 191

def initialize(reader, max_depth:)
	@reader = reader
	@max_depth = max_depth
	@parents = []
	@set = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#child(parent_source) ⇒ Object



228
229
230
231
232
233
234
235
# File 'lib/dhall/resolve.rb', line 228

def child(parent_source)
	dup.tap do |c|
		c.instance_eval do
			@parents = @parents.dup + [parent_source]
			@set = Hash.new { |h, k| h[k] = [] }
		end
	end
end

#readerObject



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/dhall/resolve.rb', line 216

def reader
	lambda do |sources|
		raise TimeoutException if sources.any? { |s| s.deadline.exceeded? }

		if @reader.arity == 2
			@reader.call(sources, @parents.last&.origin || "localhost")
		else
			@reader.call(sources)
		end
	end
end

#register(source) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/dhall/resolve.rb', line 198

def register(source)
	p = Promise.new
	if @parents.include?(source.canonical)
		p.reject(ImportLoopException.new(source))
	elsif @parents.length + 1 > @max_depth
		msg = "Max import depth of #{@max_depth} exceeded"
		p.reject(ImportFailedException.new(msg))
	else
		@set[source] << p
	end
	p
end

#resolutionsObject



211
212
213
214
# File 'lib/dhall/resolve.rb', line 211

def resolutions
	sources, promises = @set.to_a.transpose
	[Array(sources), Array(promises)]
end