summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile8
-rw-r--r--lib/dsl.rb (renamed from lib/rcm.rb)21
-rw-r--r--lib/dslkeywords/file.rb4
-rw-r--r--lib/dslkeywords/only_when.rb2
4 files changed, 18 insertions, 17 deletions
diff --git a/Rakefile b/Rakefile
index 8dff868..acb3c15 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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
diff --git a/lib/rcm.rb b/lib/dsl.rb
index a740cb2..160c1ac 100644
--- a/lib/rcm.rb
+++ b/lib/dsl.rb
@@ -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)