summaryrefslogtreecommitdiff
path: root/lib/dslkeywords
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-19 01:29:01 +0200
committerPaul Buetow <paul@buetow.org>2025-02-19 01:29:01 +0200
commite37f1d7dfeb3ff40ee80c6e097cae30b9ec512c4 (patch)
tree2e9f9a63b799f1e8901fdd6d08f09b7665cd6ab5 /lib/dslkeywords
parent13657c3c13dc62d6aba6e0633fc7f99e44170c06 (diff)
more on this
Diffstat (limited to 'lib/dslkeywords')
-rw-r--r--lib/dslkeywords/file.rb3
-rw-r--r--lib/dslkeywords/given.rb (renamed from lib/dslkeywords/only_when.rb)8
-rw-r--r--lib/dslkeywords/keyword.rb6
-rw-r--r--lib/dslkeywords/notify.rb3
-rw-r--r--lib/dslkeywords/resource.rb8
5 files changed, 17 insertions, 11 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb
index eeff82f..40daecb 100644
--- a/lib/dslkeywords/file.rb
+++ b/lib/dslkeywords/file.rb
@@ -3,6 +3,7 @@ require 'erb'
require 'fileutils'
require_relative 'resource'
+require_relative '../chained'
module RCM
# Backup the file on change
@@ -23,6 +24,7 @@ module RCM
# Managing files
class File < Resource
include FileBackup
+ include Chained
class UnsupportedOperation < StandardError; end
@@ -46,6 +48,7 @@ module RCM
def without(what) = @without_backup = validate_op(__method__, what, backup) == backup
def from(what) = @from = validate_op(__method__, what, sourcefile, template)
+ # TODO: Delete this, as should not be required anymore due to Chained module
def method_missing(method_name, *args)
if %i[present absent directory backup sourcefile template].include?(method_name)
method_name
diff --git a/lib/dslkeywords/only_when.rb b/lib/dslkeywords/given.rb
index f23c33e..fa14e68 100644
--- a/lib/dslkeywords/only_when.rb
+++ b/lib/dslkeywords/given.rb
@@ -3,8 +3,8 @@ require 'socket'
require_relative 'keyword'
module RCM
- # OnlyWhen (e.g. run on host foo)
- class OnlyWhen < Keyword
+ # Given (e.g. run on host foo)
+ class Given < Keyword
def initialize(dsl_id)
super(dsl_id)
@conds = {}
@@ -23,8 +23,8 @@ module RCM
# Add 'only_when' to DSL
class DSL
- def only_when(&block)
- conds = OnlyWhen.new(id)
+ def given(&block)
+ conds = Given.new(id)
conds.instance_eval(&block)
@conds_met = conds.met?
end
diff --git a/lib/dslkeywords/keyword.rb b/lib/dslkeywords/keyword.rb
index ee3cfba..1cbda9f 100644
--- a/lib/dslkeywords/keyword.rb
+++ b/lib/dslkeywords/keyword.rb
@@ -15,11 +15,5 @@ module RCM
def to_s = @id
class KeywordError < StandardError; end
-
- def method_missing(method_name, *args)
- raise KeywordError, "No such method: #{method_name}"
- end
-
- def respond_to_missing? = true
end
end
diff --git a/lib/dslkeywords/notify.rb b/lib/dslkeywords/notify.rb
index e1d8a3d..6616cb0 100644
--- a/lib/dslkeywords/notify.rb
+++ b/lib/dslkeywords/notify.rb
@@ -2,10 +2,13 @@ require 'erb'
require 'fileutils'
require_relative 'resource'
+require_relative '../chained'
module RCM
# Only to print out something
class Notify < Resource
+ include Chained
+
def initialize(message)
super(message)
@message = message
diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb
index 3aff069..2358ff5 100644
--- a/lib/dslkeywords/resource.rb
+++ b/lib/dslkeywords/resource.rb
@@ -26,6 +26,12 @@ module RCM
return @requires if others.empty?
others.flatten.each do |other|
+ unless other.include?('(')
+ # Convert "notify foo" to "notify('foo')"
+ resource, rest = other.split(' ', 2)
+ other = "#{resource}('#{rest}')"
+ end
+
info "Registered dependency on #{other}"
@requires << other
end
@@ -74,7 +80,7 @@ module RCM
def self.find(id)
return @@resource_find_cache[id] if @@resource_find_cache.key?(id)
- klass = Object.const_get("RCM::#{id.split('(').first.capitalize}")
+ klass = Object.const_get("RCM::#{id.split(/[( ]/).first.capitalize}")
resource = ObjectSpace.each_object(klass).find { _1.id == id }
raise NoSuchResourceObject, "Unable to find resource #{id}" if resource.nil?