Class: Dhall::Resolvers::ResolutionSet
- Inherits:
-
Object
- Object
- Dhall::Resolvers::ResolutionSet
- Defined in:
- lib/dhall/resolve.rb
Instance Method Summary collapse
- #child(parent_source) ⇒ Object
-
#initialize(reader, max_depth:) ⇒ ResolutionSet
constructor
A new instance of ResolutionSet.
- #reader ⇒ Object
- #register(source) ⇒ Object
- #resolutions ⇒ Object
Constructor Details
#initialize(reader, max_depth:) ⇒ ResolutionSet
Returns a new instance of ResolutionSet.
192 193 194 195 196 197 |
# File 'lib/dhall/resolve.rb', line 192 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
229 230 231 232 233 234 235 236 |
# File 'lib/dhall/resolve.rb', line 229 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 |
#reader ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/dhall/resolve.rb', line 217 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
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/dhall/resolve.rb', line 199 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 |
#resolutions ⇒ Object
212 213 214 215 |
# File 'lib/dhall/resolve.rb', line 212 def resolutions sources, promises = @set.to_a.transpose [Array(sources), Array(promises)] end |