Commit 1011ca49 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add a DSL evaluator to QA base factory class

parent 2de8fb7b
require 'forwardable'
module QA
module Factory
class Base
extend SingleForwardable
def_delegators :evaluator, :dependency, :dependencies
def fabricate!(*_args)
raise NotImplementedError
end
......@@ -17,16 +23,25 @@ module QA
end
end
def self.dependencies
@dependencies ||= {}
def self.evaluator
@evaluator ||= Factory::Base::DSL.new(self)
end
def self.dependency(factory, as:, &block)
as.tap do |name|
class_eval { attr_accessor name }
class DSL
attr_reader :dependencies
def initialize(base)
@base = base
@dependencies = {}
end
def dependency(factory, as:, &block)
as.tap do |name|
@base.class_eval { attr_accessor name }
Dependency::Signature.new(factory, block).tap do |signature|
dependencies.store(name, signature)
Dependency::Signature.new(factory, block).tap do |signature|
dependencies.store(name, signature)
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment