diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dslkeywords/file.rb | 1 | ||||
| -rw-r--r-- | lib/dslkeywords/notify.rb | 6 | ||||
| -rw-r--r-- | lib/dslkeywords/resource.rb | 31 |
3 files changed, 33 insertions, 5 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index 501b7c8..b42f223 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -25,6 +25,7 @@ module RCM def ensure_line(line) = @ensure_line = line def evaluate! + return unless super return evaluate_ensure_line! unless @ensure_line.nil? write_content!(real_content) diff --git a/lib/dslkeywords/notify.rb b/lib/dslkeywords/notify.rb index 602d216..e1d8a3d 100644 --- a/lib/dslkeywords/notify.rb +++ b/lib/dslkeywords/notify.rb @@ -15,7 +15,11 @@ module RCM @message = msg unless msg.nil? end - def evaluate! = puts "#{id} => #{@message}" + def evaluate! + return unless super + + puts "#{id} => #{@message}" + end end # Add notify keyword to the DSL diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb index 4c28809..1634061 100644 --- a/lib/dslkeywords/resource.rb +++ b/lib/dslkeywords/resource.rb @@ -29,19 +29,42 @@ module RCM others.flatten.each do |other| info "Registered dependency on #{other}" - @depends_on[other] = {} + @depends_on[other] = nil end end - def depends_on?(*others) - return false if @depends_on.nil? + def depends_on?(*others) = others.flatten.none? { |other| !@depends_on&.key?(other) } + end + + # To resolve dependencies + module DependencyEvaluator + attr_reader :evaluated + + def evaluate! + return false if @evaluated + + @depends_on = {} if @depends_on.nil? + @depends_on.each_key do |id| + dependency = Resource.find(id) + end - others.flatten.none? { |other| !@depends_on.key?(other) } + @evaluated = true end end # A resource is something concrete to be managed, e.g. a file, or a CRON job. class Resource < Keyword + include DependencyEvaluator include ResourceDependencies + + class NoSuchResourceObject < StandardError; end + + def self.find(id) + klass = Object.const_get("RCM::#{id.split('(').first.capitalize}") + resource = ObjectSpace.each_object(klass).find { |obj| obj.id == id } + raise NoSuchResourceObject, "Unable to find resource #{id}" if resource.nil? + + resource + end end end |
