summaryrefslogtreecommitdiff
path: root/lib/dslkeywords
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-08 13:09:34 +0200
committerPaul Buetow <paul@buetow.org>2024-12-08 13:09:34 +0200
commit5897262698ac68a85ad68b69f4f6aeb3171d399a (patch)
treec142930276a262176f160d21abcb35ef698f9cad /lib/dslkeywords
parented5f36ed3dffbac12247e5130e61d8ebd8ad82f5 (diff)
use of endless methods
Diffstat (limited to 'lib/dslkeywords')
-rw-r--r--lib/dslkeywords/file.rb33
-rw-r--r--lib/dslkeywords/only_when.rb19
2 files changed, 17 insertions, 35 deletions
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