diff options
Diffstat (limited to 'lib/oxidized/output')
-rw-r--r-- | lib/oxidized/output/file.rb | 4 | ||||
-rw-r--r-- | lib/oxidized/output/git.rb | 49 | ||||
-rw-r--r-- | lib/oxidized/output/output.rb | 5 |
3 files changed, 42 insertions, 16 deletions
diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 2d08106..03c878a 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -14,14 +14,14 @@ class OxidizedFile < Output end end - def store node, data, opt={} + def store node, outputs, opt={} file = @cfg.directory if opt[:group] file = File.join File.dirname(file), opt[:group] end FileUtils.mkdir_p file file = File.join file, node - open(file, 'w') { |fh| fh.write data } + open(file, 'w') { |fh| fh.write outputs.to_cfg } end def fetch node, group diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb index a3f32af..0c73638 100644 --- a/lib/oxidized/output/git.rb +++ b/lib/oxidized/output/git.rb @@ -21,23 +21,32 @@ class Git < Output end end - def store file, data, opt={} - msg = opt[:msg] - user = (opt[:user] or @cfg.user) - email = (opt[:email] or @cfg.email) - repo = @cfg.repo - if opt[:group] - repo = File.join File.dirname(repo), opt[:group] + '.git' - end - begin - repo = Rugged::Repository.new repo - update_repo repo, file, data, msg, user, email - rescue Rugged::OSError, Rugged::RepositoryError - Rugged::Repository.init_at repo, :bare - retry + def store file, outputs, opt={} + @msg = opt[:msg] + @user = (opt[:user] or @cfg.user) + @email = (opt[:email] or @cfg.email) + @opt = opt + repo = @cfg.repo + + outputs.types.each do |type| + type_cfg = '' + type_repo = File.join File.dirname(repo), type + '.git' + outputs.type(type).each do |output| + (type_cfg << output; next) if not output.name + type_file = file + '--' + output.name + if @cfg.type_as_directory? + type_file = type + '/' + type_file + type_repo = repo + end + update type_repo, type_file, output + end + update type_repo, file, type_cfg end + + update repo, file, outputs.to_cfg end + def fetch node, group begin repo = @cfg.repo @@ -55,6 +64,18 @@ class Git < Output private + def update repo, file, data + return if data.empty? + if @opt[:group] + repo = File.join File.dirname(repo), @opt[:group] + '.git' + end + repo = Rugged::Repository.new repo + update_repo repo, file, data, @msg, @user, @email + rescue Rugged::OSError, Rugged::RepositoryError + Rugged::Repository.init_at repo, :bare + retry + end + def update_repo repo, file, data, msg, user, email oid = repo.write data, :blob index = repo.index diff --git a/lib/oxidized/output/output.rb b/lib/oxidized/output/output.rb index eaf149a..1355d03 100644 --- a/lib/oxidized/output/output.rb +++ b/lib/oxidized/output/output.rb @@ -1,5 +1,10 @@ module Oxidized class Output class NoConfig < OxidizedError; end + + def cfg_to_str cfg + cfg.select{ |h| h[:type]=='cfg' }.map{ |h| h[:data] }.join + end + end end |