diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-19 00:00:06 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-19 00:00:06 +0200 |
| commit | 13657c3c13dc62d6aba6e0633fc7f99e44170c06 (patch) | |
| tree | b3569dab6df4c1b1d0ed94082524cad304a6a3b6 /lib/dslkeywords | |
| parent | 21c96e516044cf59a3b89c3b40c7efb279b0767c (diff) | |
nicer
Diffstat (limited to 'lib/dslkeywords')
| -rw-r--r-- | lib/dslkeywords/file.rb | 26 | ||||
| -rw-r--r-- | lib/dslkeywords/resource.rb | 14 |
2 files changed, 20 insertions, 20 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index e17cfeb..eeff82f 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -41,20 +41,20 @@ module RCM def line(line) = @ensure_line = line def path(file_path = nil) = file_path.nil? ? @file_path : @file_path = file_path - # TODO: Replace :is with current method name dynamically - def is(what) = @is = validate_op(:is, what, present, absent) - def present = :present - def absent = :absent - - def manage(what) = @manage_directory = validate_op(:is, what, directory) == directory - def directory = :directory - - def without(what) = @without_backup = validate_op(:without, what, backup) == backup - def backup = :backup + 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) + + def method_missing(method_name, *args) + if %i[present absent directory backup sourcefile template].include?(method_name) + method_name + else + super + end + end - def from(what) = @from = validate_op(:from, what, sourcefile, template) - def sourcefile = :sourcefile - def template = :template + def respond_to_missing? = true def evaluate! return unless super diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb index be67b0a..3aff069 100644 --- a/lib/dslkeywords/resource.rb +++ b/lib/dslkeywords/resource.rb @@ -7,7 +7,7 @@ module RCM module ResourceDependencies def initialize(...) super(...) - @depends_on = Set.new + @requires = Set.new @valid_resources = Set.new ObjectSpace.each_object(Class).each do |klass| @valid_resources << klass.to_s.sub('RCM::', '').downcase.to_sym if klass < Resource @@ -22,16 +22,16 @@ module RCM def respond_to_missing? = true - def depends_on(*others) - return @depends_on if others.empty? + def requires(*others) + return @requires if others.empty? others.flatten.each do |other| info "Registered dependency on #{other}" - @depends_on << other + @requires << other end end - def depends_on?(*others) = others.flatten.none? { |other| !@depends_on&.include?(other) } + def requires?(*others) = others.flatten.none? { |other| !@requires&.include?(other) } end # To resolve dependencies @@ -49,10 +49,10 @@ module RCM @loop_detection = true # Try to evaluate all dependencies recursively. - @depends_on.each.map { Resource.find(_1) }.each(&:evaluate!) + @requires.each.map { Resource.find(_1) }.each(&:evaluate!) # Raise an exception when there are still unresolved dependencies. - unresolved = @depends_on.each.map { Resource.find(_1) }.reject(&:evaluated) + unresolved = @requires.each.map { Resource.find(_1) }.reject(&:evaluated) raise UnresolvedDependency, "Unresolved dependencies: #{unresolved.map(&:id)}" if unresolved.count.positive? @loop_detection = false |
