Class: Finitio::ProxyResolver
- Inherits:
-
Object
- Object
- Finitio::ProxyResolver
- Defined in:
- lib/finitio/support/proxy_resolver.rb
Overview
Part of the compilation schema, this proxy resolver replaces proxies by their real Type instance.
Given that Finitio can support recursive types, we do this in two passes:
1. Replace proxy types by rewrite (see Type#resolve_proxies)
in a depth first search.
2. If a loop is found, recreate a late ProxyType, that is then
bound later by mutation.
So ProxyType may still be present in the type chain, but will only correspond to recursive types.
Instance Method Summary collapse
- #build_it(name) ⇒ Object
- #fetch(name, &bl) ⇒ Object
- #import_it(name, &bl) ⇒ Object
- #resolve!(system) ⇒ Object
Instance Method Details
#build_it(name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/finitio/support/proxy_resolver.rb', line 33 def build_it(name) if under_build = @building[name] proxy = ProxyType.new(name) @late_proxies << proxy proxy else return nil unless type = @system.fetch(name, false){ nil } @building[name] = type @built[name] = type.resolve_proxies(self) @building[name] = nil @built[name] end end |
#fetch(name, &bl) ⇒ Object
29 30 31 |
# File 'lib/finitio/support/proxy_resolver.rb', line 29 def fetch(name, &bl) @built[name] || build_it(name) || import_it(name, &bl) end |
#import_it(name, &bl) ⇒ Object
48 49 50 |
# File 'lib/finitio/support/proxy_resolver.rb', line 48 def import_it(name, &bl) @system.fetch_on_imports(name, &bl) end |
#resolve!(system) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/finitio/support/proxy_resolver.rb', line 15 def resolve!(system) @system = system @built = {} @building = {} @late_proxies = [] system.types.each_key do |name| fetch(name) end @late_proxies.each do |proxy| proxy.bind!(self) end system.dup(@built) end |