diff options
| author | Paul Buetow <paul@buetow.org> | 2024-12-07 00:21:42 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-12-07 00:21:42 +0200 |
| commit | bf5baf8891f0622f4e46571fa0ad990d7140b9d7 (patch) | |
| tree | 506363c4fd648905683ff525a46892ca12f67501 /lib/dslkeywords | |
| parent | 7c23b27007ca62ff545411aa3d1200fce4eec8c9 (diff) | |
sugar
Diffstat (limited to 'lib/dslkeywords')
| -rw-r--r-- | lib/dslkeywords/file.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index a22e52f..8411d53 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -22,26 +22,25 @@ module RCM end def content(content = nil) - content.nil? ? @content : @content = content + return @content if content.nil? + + @content = content.instance_of?(Array) ? content.join("\n") : content end def create_parent_directory @create_parent = true - self end - def from_file(...) - @from_file = true - self + def from_sourcefile + @from_sourcefile = true end - def from_template(...) + def from_template @from_template = true - self end def do! - content = file_content + content = real_content dirname = ::File.dirname(@path) if !::File.directory?(dirname) && @create_parent @@ -59,8 +58,8 @@ module RCM private - def file_content - content = @from_file ? ::File.read(@content) : @content + def real_content + content = @from_sourcefile ? ::File.read(@content) : @content @from_template ? ERB.new(content).result : content end end @@ -71,7 +70,7 @@ module RCM return unless @conds_met f = File.new(path) - f.instance_eval(&block) + f.content(f.instance_eval(&block)) self << f end end |
