summaryrefslogtreecommitdiff
path: root/lib/dsl.rb
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-07 14:36:21 +0200
committerPaul Buetow <paul@buetow.org>2024-12-07 14:36:21 +0200
commitf0b0dae5bb2e16cf45223fc31396708bd069d06c (patch)
tree5a7f3cd159c8d7029006fb900ec79dad05e0e212 /lib/dsl.rb
parent7d5264aea075c3845e6d5e4be65aaacdea54e71f (diff)
cosmetics
Diffstat (limited to 'lib/dsl.rb')
-rw-r--r--lib/dsl.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/dsl.rb b/lib/dsl.rb
new file mode 100644
index 0000000..160c1ac
--- /dev/null
+++ b/lib/dsl.rb
@@ -0,0 +1,48 @@
+require_relative 'config'
+require_relative 'options'
+require_relative 'log'
+
+Dir["#{Dir.pwd}/lib/dslkeywords/*.rb"].each { |m| require m }
+
+# Ruby Configiration Management system
+module RCM
+ # Here all starts
+ class DSL
+ attr_reader :id
+
+ @@rcm_counter = -1
+ @@objs = {}
+
+ include Config
+ include Options
+ include Log
+
+ def initialize
+ @id = "#{self.class}(#{@@rcm_counter += 1})"
+ @conds_met = true
+ @scheduled = []
+ yield self if block_given?
+ end
+
+ def to_s
+ "RCM #{@number}"
+ end
+
+ def evaluate!
+ @scheduled.each(&:evaluate!)
+ end
+
+ def <<(obj)
+ fatal_exit "Object #{obj.id} already declared!" if @@objs.key?(obj.id)
+ @scheduled << @@objs[obj.id] = obj
+ end
+ end
+end
+
+def configure(&block)
+ RCM::DSL.new do |rcm|
+ rcm.info('Configuring...')
+ rcm.instance_eval(&block)
+ rcm.evaluate!
+ end
+end