From 5897262698ac68a85ad68b69f4f6aeb3171d399a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 8 Dec 2024 13:09:34 +0200 Subject: use of endless methods --- lib/dslkeywords/file.rb | 33 +++++++++++++-------------------- lib/dslkeywords/only_when.rb | 19 ++++--------------- 2 files changed, 17 insertions(+), 35 deletions(-) (limited to 'lib/dslkeywords') 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 -- cgit v1.2.3