From e37f1d7dfeb3ff40ee80c6e097cae30b9ec512c4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 19 Feb 2025 01:29:01 +0200 Subject: more on this --- lib/dslkeywords/only_when.rb | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 lib/dslkeywords/only_when.rb (limited to 'lib/dslkeywords/only_when.rb') diff --git a/lib/dslkeywords/only_when.rb b/lib/dslkeywords/only_when.rb deleted file mode 100644 index f23c33e..0000000 --- a/lib/dslkeywords/only_when.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'socket' - -require_relative 'keyword' - -module RCM - # OnlyWhen (e.g. run on host foo) - class OnlyWhen < Keyword - def initialize(dsl_id) - super(dsl_id) - @conds = {} - end - - def is(arg) = arg - def method_missing(method_name, *args) = @conds[method_name] = args.first - def respond_to_missing? = true - - def met? - return false if @conds.key?(:hostname) && Socket.gethostname != @conds[:hostname].to_s - - true - end - end - - # Add 'only_when' to DSL - class DSL - def only_when(&block) - conds = OnlyWhen.new(id) - conds.instance_eval(&block) - @conds_met = conds.met? - end - end -end -- cgit v1.2.3