diff options
| author | Paul Buetow <paul@buetow.org> | 2024-12-07 14:36:21 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-12-07 14:36:21 +0200 |
| commit | f0b0dae5bb2e16cf45223fc31396708bd069d06c (patch) | |
| tree | 5a7f3cd159c8d7029006fb900ec79dad05e0e212 | |
| parent | 7d5264aea075c3845e6d5e4be65aaacdea54e71f (diff) | |
cosmetics
| -rw-r--r-- | Rakefile | 8 | ||||
| -rw-r--r-- | lib/dsl.rb (renamed from lib/rcm.rb) | 21 | ||||
| -rw-r--r-- | lib/dslkeywords/file.rb | 4 | ||||
| -rw-r--r-- | lib/dslkeywords/only_when.rb | 2 |
4 files changed, 18 insertions, 17 deletions
@@ -1,8 +1,8 @@ -require_relative 'lib/rcm' +require_relative 'lib/dsl' desc 'Set up wireguard mesh' task :wireguard do - make_it_so do + configure do # p option :verbose # dump_config only_when { hostname is :earth } @@ -23,9 +23,9 @@ end desc 'foo task' task :foo do - make_it_so do + configure do file '/tmp/test.txt' do [ 'foo', 'bar', 'baz' ].sort end end -end +end @@ -7,7 +7,7 @@ Dir["#{Dir.pwd}/lib/dslkeywords/*.rb"].each { |m| require m } # Ruby Configiration Management system module RCM # Here all starts - class RCM + class DSL attr_reader :id @@rcm_counter = -1 @@ -18,18 +18,18 @@ module RCM include Log def initialize - @@rcm_counter += 1 - @id = "#{self.class}(#{@@rcm_counter})" + @id = "#{self.class}(#{@@rcm_counter += 1})" @conds_met = true @scheduled = [] + yield self if block_given? end def to_s "RCM #{@number}" end - def do! - @scheduled.each(&:do!) + def evaluate! + @scheduled.each(&:evaluate!) end def <<(obj) @@ -39,9 +39,10 @@ module RCM end end -def make_it_so(&block) - rcm = RCM::RCM.new - rcm.info('Making it so...') - rcm.instance_eval(&block) - rcm.do! +def configure(&block) + RCM::DSL.new do |rcm| + rcm.info('Configuring...') + rcm.instance_eval(&block) + rcm.evaluate! + end end diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index 746b41c..35db9c2 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -39,7 +39,7 @@ module RCM @from_template = true end - def do! + def evaluate! content = real_content dirname = ::File.dirname(@path) @@ -65,7 +65,7 @@ module RCM end # Add file keyword to the DSL - class RCM + class DSL def file(path, &block) return unless @conds_met diff --git a/lib/dslkeywords/only_when.rb b/lib/dslkeywords/only_when.rb index 2700bee..2f493b2 100644 --- a/lib/dslkeywords/only_when.rb +++ b/lib/dslkeywords/only_when.rb @@ -27,7 +27,7 @@ module RCM end # Add 'only_when' to DSL - class RCM + class DSL def only_when(&block) conds = OnlyWhen.new conds.instance_eval(&block) |
