summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dslkeywords/file.rb26
-rw-r--r--lib/dslkeywords/resource.rb14
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