module CFManifests::Resolver
Public Instance Methods
resolve(manifest, resolver)
click to toggle source
# File lib/manifests/loader/resolver.rb, line 3 def resolve(manifest, resolver) new = {} new[:applications] = manifest[:applications].collect do |app| resolve_lexically(resolver, app, [manifest]) end resolve_lexically(resolver, new, [new]) end
Private Instance Methods
find_in_hash(hash, where)
click to toggle source
helper for following a path of values in a hash
# File lib/manifests/loader/resolver.rb, line 69 def find_in_hash(hash, where) what = hash where.each do |x| return nil unless what.is_a?(Hash) what = what[x] end what end
find_symbol(sym, ctx)
click to toggle source
search for a symbol introduced in the lexical context
# File lib/manifests/loader/resolver.rb, line 52 def find_symbol(sym, ctx) ctx.each do |h| if val = resolve_in(h, sym) return val end end nil end
resolve_in(hash, *where)
click to toggle source
find a value, searching in explicit properties first
# File lib/manifests/loader/resolver.rb, line 63 def resolve_in(hash, *where) find_in_hash(hash, [:properties] + where) || find_in_hash(hash, where) end
resolve_lexically(resolver, val, ctx)
click to toggle source
resolve symbols, with hashes introducing new lexical symbols
# File lib/manifests/loader/resolver.rb, line 16 def resolve_lexically(resolver, val, ctx) case val when Hash new = {} val.each do |k, v| new[k] = resolve_lexically(resolver, v, [val] + ctx) end new when Array val.collect do |v| resolve_lexically(resolver, v, ctx) end when String val.gsub(/\$\{([^\}]+)\}/) do resolve_symbol(resolver, $1, ctx) end else val end end
resolve_symbol(resolver, sym, ctx)
click to toggle source
resolve a symbol to its value, and then resolve that value
# File lib/manifests/loader/resolver.rb, line 40 def resolve_symbol(resolver, sym, ctx) if found = find_symbol(sym.to_sym, ctx) resolve_lexically(resolver, found, ctx) found elsif dynamic = resolver.resolve_symbol(sym) dynamic else fail("Unknown symbol in manifest: #{sym}") end end