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.



199
200
201
202
203
204
# File 'lib/dhall/resolve.rb', line 199

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



236
237
238
239
240
241
242
243
# File 'lib/dhall/resolve.rb', line 236

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



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/dhall/resolve.rb', line 224

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



206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/dhall/resolve.rb', line 206

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



219
220
221
222
# File 'lib/dhall/resolve.rb', line 219

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