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 | |
| parent | 7c23b27007ca62ff545411aa3d1200fce4eec8c9 (diff) | |
sugar
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dslkeywords/file.rb | 21 | ||||
| -rw-r--r-- | lib/rcm.rb | 13 |
2 files changed, 17 insertions, 17 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 @@ -10,17 +10,18 @@ module RCM class RCM attr_reader :id - @@rcm_counter = 0 + @@rcm_counter = -1 + @@objs = {} include Config include Options include Log def initialize + @@rcm_counter += 1 @id = "#{self.class}(#{@@rcm_counter})" - @objs = {} @conds_met = true - @@rcm_counter += 1 + @scheduled = [] end def to_s @@ -28,12 +29,12 @@ module RCM end def do! - @objs.each_value(&:do!) + @scheduled.each(&:do!) end def <<(obj) - fatal_exit "Object #{obj.id} already declared!" if @objs.key?(obj.id) - @objs[obj.id] = obj + fatal_exit "Object #{obj.id} already declared!" if @@objs.key?(obj.id) + @scheduled << @@objs[obj.id] = obj end end end |
