diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-14 21:35:40 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-14 21:35:40 +0200 |
| commit | a2edd9ec657dca835ce1a73807a86a9c44fdfec8 (patch) | |
| tree | 678076fbd778b10264ed0b23857c8e5accdcc693 /lib | |
| parent | 07e5f8d4402346ccb336cc0680cad98d0d5ba920 (diff) | |
initial tests
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dslkeywords/file.rb | 18 | ||||
| -rw-r--r-- | lib/options.rb | 12 |
2 files changed, 16 insertions, 14 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index 403f01e..58d7a47 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -19,10 +19,10 @@ module RCM def to_s = id - def content(content = nil) - return @content if content.nil? + def content(text = nil) + return @content if text.nil? - @content = content.instance_of?(Array) ? content.join("\n") : content + @content = text.instance_of?(Array) ? text.join("\n") : text end def create_parent_directory = @create_parent = true @@ -49,12 +49,12 @@ module RCM end end - def write_content!(content) + def write_content!(text) create_parent_directory! - debug content if option :debug + debug text if option :debug info "Creating file #{@path}" tmp_path = "#{@path}.tmp" - ::File.write(tmp_path, content) + ::File.write(tmp_path, text) ::File.rename(tmp_path, @path) end @@ -67,8 +67,8 @@ module RCM end def real_content - content = @from_sourcefile ? ::File.read(@content) : @content - @from_template ? ERB.new(content).result : content + text = @from_sourcefile ? ::File.read(@content) : @content + @from_template ? ERB.new(text).result : text end end @@ -77,6 +77,8 @@ module RCM def file(path, &block) return unless @conds_met + p :FOO, path + f = File.new(path) f.content(f.instance_eval(&block)) self << f diff --git a/lib/options.rb b/lib/options.rb index 79e3c51..ee30295 100644 --- a/lib/options.rb +++ b/lib/options.rb @@ -5,12 +5,12 @@ module RCM module Options @@options = { debug: false } - after_double_dash = ARGV.slice_before('--').to_a.last.drop(1) - - OptionParser.new do |opts| - opts.banner = 'Usage: rake [task] -- [options]' - opts.on('-v', '--[no-]debug', 'debug output') { |v| @@options[:debug] = v } - end.parse!(after_double_dash) + if (after_double_dash = ARGV.slice_before('--').to_a.last&.drop(1)) + OptionParser.new do |opts| + opts.banner = 'Usage: rake [task] -- [options]' + opts.on('-v', '--[no-]debug', 'debug output') { |v| @@options[:debug] = v } + end.parse!(after_double_dash) + end def option(key) raise "No such option: #{key}" unless @@options.key?(key) |
