diff options
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | lib/config.rb | 4 | ||||
| -rw-r--r-- | lib/dsl.rb | 5 | ||||
| -rw-r--r-- | lib/dslkeywords/file.rb | 33 | ||||
| -rw-r--r-- | lib/dslkeywords/only_when.rb | 19 | ||||
| -rw-r--r-- | lib/log.rb | 20 | ||||
| -rw-r--r-- | lib/options.rb | 4 |
7 files changed, 31 insertions, 62 deletions
@@ -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 @@ -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 @@ -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) |
