summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--lib/config.rb4
-rw-r--r--lib/dsl.rb5
-rw-r--r--lib/dslkeywords/file.rb33
-rw-r--r--lib/dslkeywords/only_when.rb19
-rw-r--r--lib/log.rb20
-rw-r--r--lib/options.rb4
7 files changed, 31 insertions, 62 deletions
diff --git a/README.md b/README.md
index e6e04a2..d9de495 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,9 @@
# rcm
-Ruby configuration management system (rcm) - KISS and for my personal use. \ No newline at end of file
+Ruby configuration management system (rcm) - KISS and for my personal use.
+
+## Invokation
+
+```sh
+rake wireguard -- --debug
+```
diff --git a/lib/config.rb b/lib/config.rb
index b9dc5ac..b0123e0 100644
--- a/lib/config.rb
+++ b/lib/config.rb
@@ -11,8 +11,6 @@ module RCM
@@config[key]
end
- def dump_config
- p @@config
- end
+ def dump_config = p @@config
end
end
diff --git a/lib/dsl.rb b/lib/dsl.rb
index 682330f..f6f8e8e 100644
--- a/lib/dsl.rb
+++ b/lib/dsl.rb
@@ -25,10 +25,7 @@ module RCM
end
def to_s = "RCM #{@number}"
-
- def evaluate!
- @scheduled.each(&:evaluate!)
- end
+ def evaluate! = @scheduled.each(&:evaluate!)
def <<(obj)
fatal_exit "Object #{obj.id} already declared!" if @@objs.key?(obj.id)
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb
index 35db9c2..7e24801 100644
--- a/lib/dslkeywords/file.rb
+++ b/lib/dslkeywords/file.rb
@@ -17,9 +17,7 @@ module RCM
@path = path
end
- def to_s
- id
- end
+ def to_s = id
def content(content = nil)
return @content if content.nil?
@@ -27,27 +25,14 @@ module RCM
@content = content.instance_of?(Array) ? content.join("\n") : content
end
- def create_parent_directory
- @create_parent = true
- end
-
- def from_sourcefile
- @from_sourcefile = true
- end
-
- def from_template
- @from_template = true
- end
+ def create_parent_directory = @create_parent = true
+ def from_sourcefile = @from_sourcefile = true
+ def from_template = @from_template = true
def evaluate!
+ create_parent_directory!
content = real_content
- dirname = ::File.dirname(@path)
- if !::File.directory?(dirname) && @create_parent
- info "Creating parent directory #{parent}"
- FileUtils.mkdir_p(dirname)
- end
-
info "Creating file #{@path}"
debug content if option :debug
@@ -58,6 +43,14 @@ module RCM
private
+ def create_parent_directory!
+ dirname = ::File.dirname(@path)
+ return unless !::File.directory?(dirname) && @create_parent
+
+ info "Creating parent directory #{parent}"
+ FileUtils.mkdir_p(dirname)
+ end
+
def real_content
content = @from_sourcefile ? ::File.read(@content) : @content
@from_template ? ERB.new(content).result : content
diff --git a/lib/dslkeywords/only_when.rb b/lib/dslkeywords/only_when.rb
index 2f493b2..82dbc1f 100644
--- a/lib/dslkeywords/only_when.rb
+++ b/lib/dslkeywords/only_when.rb
@@ -3,21 +3,10 @@ module RCM
class OnlyWhen
require 'socket'
- def initialize
- @conds = {}
- end
-
- def is(arg)
- arg
- end
-
- def method_missing(method_name, *args, &block)
- @conds[method_name] = args.first
- end
-
- def respond_to_missing?
- true
- end
+ def initialize = @conds = {}
+ def is(arg) = arg
+ def method_missing(method_name, *args, &block) = @conds[method_name] = args.first
+ def respond_to_missing? = true
def met?
return false if @conds.key?(:hostname) && Socket.gethostname != @conds[:hostname].to_s
diff --git a/lib/log.rb b/lib/log.rb
index 67ff321..2e4e4ea 100644
--- a/lib/log.rb
+++ b/lib/log.rb
@@ -4,21 +4,9 @@ module RCM
module Log
@@logger = Logger.new(STDOUT)
- def info(message)
- @@logger.info("#{id} => #{message}")
- end
-
- def warn(message)
- @@logger.warn("#{id} => #{message}")
- end
-
- def fatal_exit(message)
- @@logger.fatal("#{id} => #{message}")
- exit 2
- end
-
- def debug(message)
- @@logger.debug("#{id} => #{message}")
- end
+ def info(message) = @@logger.info("#{id} => #{message}")
+ def warn(message) = @@logger.warn("#{id} => #{message}")
+ def fatal_exit(message) = @@logger.fatal("#{id} => #{message}")
+ def debug(message) = @@logger.debug("#{id} => #{message}")
end
end
diff --git a/lib/options.rb b/lib/options.rb
index c3950ca..79e3c51 100644
--- a/lib/options.rb
+++ b/lib/options.rb
@@ -3,9 +3,7 @@ require 'optparse'
module RCM
# Command line options
module Options
- @@options = {
- debug: false
- }
+ @@options = { debug: false }
after_double_dash = ARGV.slice_before('--').to_a.last.drop(1)