lib/finitio/support/compilation.rb in finitio-0.7.0 vs lib/finitio/support/compilation.rb in finitio-0.8.0

- old
+ new

@@ -1,21 +1,21 @@ module Finitio class Compilation - def initialize(system = System.new, factory = TypeFactory.new, source = nil) + def initialize(system = System.new, factory = TypeFactory.new, scope = nil, source = nil) @system = system @factory = factory - @proxies = [] + @scope = scope || FetchScope.new(system, {}) @source = source end - attr_reader :system, :factory, :proxies, :source + attr_reader :system, :factory, :scope, :source def self.coerce(arg, source = nil) case arg - when NilClass then new(System.new, TypeFactory.new, source) - when System then new(arg, arg.factory, source) - when TypeFactory then new(System.new, arg, source) + when NilClass then new(System.new, TypeFactory.new, nil, source) + when System then new(arg, arg.factory, nil, source) + when TypeFactory then new(System.new, arg, nil, source) else raise ArgumentError, "Unable to coerce `#{arg}`" end end @@ -46,40 +46,40 @@ file = File.expand_path("../#{url}.fio", source.to_path) raise Error, "No such file `#{file}`" unless File.file?(file) Pathname.new(file) end - def resolve_proxies! - proxies.each do |p| - p.resolve(system) - end - self + def resolve_proxies + system.resolve_proxies end # Delegation to Factory TypeFactory::DSL_METHODS.each do |dsl_method| define_method(dsl_method){|*args, &bl| factory.public_send(dsl_method, *args, &bl) } end - def proxy(*args, &bl) - proxy = factory.proxy(*args, &bl) - proxies << proxy - proxy - end - # Delegation to System [ :add_type, - :fetch, :main, ].each do |meth| define_method(meth) do |*args, &bl| system.public_send(meth, *args, &bl) end + end + + # Delegation to FetchScope + + def fetch(type_name, &bl) + scope.fetch(type_name, &bl) + end + + def with_scope(overrides) + Compilation.new(system, factory, scope.with(overrides), source) end end # class Compilation end # module Finitio