Class: Dhall::Resolvers::ResolutionSet

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

Instance Method Summary collapse

Constructor Details

#initialize(reader) ⇒ ResolutionSet

Returns a new instance of ResolutionSet.



121
122
123
124
125
# File 'lib/dhall/resolve.rb', line 121

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

Instance Method Details

#child(parent_source) ⇒ Object



152
153
154
155
156
157
158
159
# File 'lib/dhall/resolve.rb', line 152

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



142
143
144
145
146
147
148
149
150
# File 'lib/dhall/resolve.rb', line 142

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

#register(source) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/dhall/resolve.rb', line 127

def register(source)
  p = Promise.new
  if @parents.include?(source)
    p.reject(ImportLoopException.new(source))
  else
    @set[source] << p
  end
  p
end

#resolutionsObject



137
138
139
140
# File 'lib/dhall/resolve.rb', line 137

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