summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-01 23:14:29 +0200
committerPaul Buetow <paul@buetow.org>2026-03-01 23:14:29 +0200
commit85f1805bea38d5f1558c92ff354f2d5bf832f0e6 (patch)
tree963144d7f7aea9515f146fb7c3c02216aadcdf0b
parent98936da70412f87051e6237b882ce8f78d2431a2 (diff)
refactor: extract do? into DryRun concern module in resource.rb
do? (dry-run-aware block execution) was sitting inside ResourceDependencies, which is responsible for dependency tracking — an SRP violation. Move it into its own DryRun module and include that in Resource alongside the existing concerns. No logic changed; all 29 tests continue to pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--lib/dslkeywords/resource.rb28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb
index c48398b..143815f 100644
--- a/lib/dslkeywords/resource.rb
+++ b/lib/dslkeywords/resource.rb
@@ -3,6 +3,23 @@ require 'set'
require_relative 'keyword'
module RCM
+ # Concern that wraps side-effecting blocks so they are skipped (and
+ # logged as dry-run) when the --dry option is active. Kept separate
+ # from dependency tracking so each module has a single responsibility.
+ module DryRun
+ # Log the action and yield the block, unless --dry is active.
+ # In dry-run mode only logs the message (with " - dry run!" appended)
+ # and returns without executing the block.
+ def do?(message)
+ if option :dry
+ info("#{message} - dry run!")
+ return
+ end
+ info(message)
+ yield
+ end
+ end
+
# To track recource dependencies
module ResourceDependencies
def initialize(...)
@@ -38,16 +55,6 @@ module RCM
end
def requires?(*others) = others.flatten.none? { |other| !@requires&.include?(other) }
-
- # Only run the block when not in dry mode
- def do?(message)
- if option :dry
- info("#{message} - dry run!")
- return
- end
- info(message)
- yield
- end
end
# To resolve dependencies
@@ -79,6 +86,7 @@ module RCM
# A resource is something concrete to be managed, e.g. a file, or a CRON job.
class Resource < Keyword
+ include DryRun
include DependencyEvaluator
include ResourceDependencies