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 QA
module Factory module Factory
class Base class Base
extend SingleForwardable
def_delegators :evaluator, :dependency, :dependencies
def fabricate!(*_args) def fabricate!(*_args)
raise NotImplementedError raise NotImplementedError
end end
...@@ -17,13 +23,21 @@ module QA ...@@ -17,13 +23,21 @@ module QA
end end
end end
def self.dependencies def self.evaluator
@dependencies ||= {} @evaluator ||= Factory::Base::DSL.new(self)
end end
def self.dependency(factory, as:, &block) class DSL
attr_reader :dependencies
def initialize(base)
@base = base
@dependencies = {}
end
def dependency(factory, as:, &block)
as.tap do |name| as.tap do |name|
class_eval { attr_accessor name } @base.class_eval { attr_accessor name }
Dependency::Signature.new(factory, block).tap do |signature| Dependency::Signature.new(factory, block).tap do |signature|
dependencies.store(name, signature) dependencies.store(name, signature)
...@@ -32,4 +46,5 @@ module QA ...@@ -32,4 +46,5 @@ module QA
end end
end end
end 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