From 85f1805bea38d5f1558c92ff354f2d5bf832f0e6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Mar 2026 23:14:29 +0200 Subject: refactor: extract do? into DryRun concern module in resource.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/dslkeywords/resource.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3