Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/factory/dependency.rb')
-rw-r--r--qa/qa/factory/dependency.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/qa/qa/factory/dependency.rb b/qa/qa/factory/dependency.rb
new file mode 100644
index 00000000000..fc5dc82ce29
--- /dev/null
+++ b/qa/qa/factory/dependency.rb
@@ -0,0 +1,39 @@
+module QA
+ module Factory
+ class Dependency
+ Signature = Struct.new(:factory, :block)
+
+ def initialize(name, factory, signature)
+ @name = name
+ @factory = factory
+ @signature = signature
+ end
+
+ def overridden?
+ !!@factory.public_send(@name)
+ end
+
+ def build!
+ return if overridden?
+
+ Builder.new(@signature, @factory).fabricate!.tap do |product|
+ @factory.public_send("#{@name}=", product)
+ end
+ end
+
+ class Builder
+ def initialize(signature, caller_factory)
+ @factory = signature.factory
+ @block = signature.block
+ @caller_factory = caller_factory
+ end
+
+ def fabricate!
+ @factory.fabricate! do |factory|
+ @block&.call(factory, @caller_factory)
+ end
+ end
+ end
+ end
+ end
+end