diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-11 10:47:49 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-01-11 10:47:49 +0100 |
commit | 1011ca49495eb1f48d43694bfbb2a96951fd45ba (patch) | |
tree | 2c011a4bd2e348757e79de8eca44e3fe3ac811d0 | |
parent | 2de8fb7bab49c1a5168ee56fc12e1f3ceb0ad1c7 (diff) | |
download | gitlab-ce-1011ca49495eb1f48d43694bfbb2a96951fd45ba.tar.gz |
Add a DSL evaluator to QA base factory class
-rw-r--r-- | qa/qa/factory/base.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/qa/qa/factory/base.rb b/qa/qa/factory/base.rb index 00851a7bece..3e5227ea426 100644 --- a/qa/qa/factory/base.rb +++ b/qa/qa/factory/base.rb @@ -1,6 +1,12 @@ +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 |