diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-16 23:08:46 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-16 23:08:46 +0200 |
| commit | 556d1d13ad6ce056fb52d920e36c08192c7103c5 (patch) | |
| tree | eeb07cd50aa32c943113bc00cd7ba892ecbd890c /lib/dslkeywords | |
| parent | 5c2865998aec2db34c42ee092952ec37ebd3cf16 (diff) | |
change foo[...] to foo(...) syntax for deps
test deps
Diffstat (limited to 'lib/dslkeywords')
| -rw-r--r-- | lib/dslkeywords/keyword.rb | 2 | ||||
| -rw-r--r-- | lib/dslkeywords/resource.rb | 20 |
2 files changed, 9 insertions, 13 deletions
diff --git a/lib/dslkeywords/keyword.rb b/lib/dslkeywords/keyword.rb index 2696e41..2dfff91 100644 --- a/lib/dslkeywords/keyword.rb +++ b/lib/dslkeywords/keyword.rb @@ -9,7 +9,7 @@ module RCM include Options include Log - def initialize(name) = @id = "#{self.class.to_s.sub('RCM::', '').downcase}['#{name}']" + def initialize(name) = @id = "#{self.class.to_s.sub('RCM::', '').downcase}('#{name}')" def to_s = @id end end diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb index c9098d4..18239fc 100644 --- a/lib/dslkeywords/resource.rb +++ b/lib/dslkeywords/resource.rb @@ -13,31 +13,27 @@ module RCM end end - # Only to have the resourcename[id] syntax available in the DSL - class SyntaxSugar - def initialize(name) = @name = name - def [](other) = "#{@name}['#{other}']" - end - class NoSuchResourceType < StandardError; end - def method_missing(method_name) + def method_missing(method_name, *args) raise NoSuchResourceType, "No such resource type: #{method_name}" unless @valid_resources.include?(method_name) - SyntaxSugar.new(method_name) + args.map { |arg| "#{method_name}('#{arg}')" } end def respond_to_missing? = true def depends_on(*others) - @dependencies = {} if @dependencies.nil? - others.each do |other| + @depends_on = {} if @depends_on.nil? + return @depends_on if others.empty? + + others.flatten.each do |other| info "Registered dependency on #{other}" - @dependencies[other] = {} + @depends_on[other] = {} end end - def dependencies = @dependencies.nil ? [] : @dependencies + def depends_on?(other) = @depends_on.nil? ? false : @depends_on.key?(other) end # A resource is something concrete to be managed, e.g. a file, or a CRON job. |
