summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-19 11:31:50 +0200
committerPaul Buetow <paul@buetow.org>2025-02-19 11:31:50 +0200
commit5d866242fd0816c0999cfe66d56c15e1d7313971 (patch)
treedb37a86440c429fbaf24777be481249084b0fa58
parentf28b8eba4937486e43292bbf2a62087a642c000d (diff)
make this work
-rw-r--r--lib/dslkeywords/file.rb31
1 files changed, 12 insertions, 19 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb
index 40daecb..788ff4f 100644
--- a/lib/dslkeywords/file.rb
+++ b/lib/dslkeywords/file.rb
@@ -43,21 +43,10 @@ module RCM
def line(line) = @ensure_line = line
def path(file_path = nil) = file_path.nil? ? @file_path : @file_path = file_path
- def is(what) = @is = validate_op(__method__, what, present, absent)
- def manage(what) = @manage_directory = validate_op(__method__, what, directory) == directory
- 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
- else
- super
- end
- end
-
- def respond_to_missing? = true
+ def is(what) = @is = validate(__method__, what, :present, :absent)
+ def manage(what) = @manage_directory = validate(__method__, what, :directory) == :directory
+ def without(what) = @without_backup = validate(__method__, what, :backup) == :backup
+ def from(what) = @from = validate(__method__, what, :sourcefile, :template)
def evaluate!
return unless super
@@ -69,9 +58,13 @@ module RCM
private
- def validate_op(matter, what, *valids)
+ # Validate whether we can use this up in this context or not
+ def validate(matter, what, *valids)
what = what.to_sym
- raise UnsupportedOperation, "Unsupported '#{matter}' operation #{what}" unless valids.include?(what)
+ unless valids.include?(what)
+ raise UnsupportedOperation,
+ "Unsupported '#{matter}' operation #{what} (#{what.class})"
+ end
what
end
@@ -141,8 +134,8 @@ module RCM
end
def real_content
- text = @from == sourcefile ? ::File.read(@content) : @content
- @from == template ? ERB.new(text).result : text
+ text = @from == :sourcefile ? ::File.read(@content) : @content
+ @from == :template ? ERB.new(text).result : text
end
end