diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-19 01:29:01 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-19 01:29:01 +0200 |
| commit | e37f1d7dfeb3ff40ee80c6e097cae30b9ec512c4 (patch) | |
| tree | 2e9f9a63b799f1e8901fdd6d08f09b7665cd6ab5 /lib/dslkeywords/given.rb | |
| parent | 13657c3c13dc62d6aba6e0633fc7f99e44170c06 (diff) | |
more on this
Diffstat (limited to 'lib/dslkeywords/given.rb')
| -rw-r--r-- | lib/dslkeywords/given.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/dslkeywords/given.rb b/lib/dslkeywords/given.rb new file mode 100644 index 0000000..fa14e68 --- /dev/null +++ b/lib/dslkeywords/given.rb @@ -0,0 +1,32 @@ +require 'socket' + +require_relative 'keyword' + +module RCM + # Given (e.g. run on host foo) + class Given < 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 given(&block) + conds = Given.new(id) + conds.instance_eval(&block) + @conds_met = conds.met? + end + end +end |
