diff options
Diffstat (limited to 'lib/oxidized/output')
-rw-r--r-- | lib/oxidized/output/file.rb | 15 | ||||
-rw-r--r-- | lib/oxidized/output/git.rb | 23 | ||||
-rw-r--r-- | lib/oxidized/output/output.rb | 1 |
3 files changed, 19 insertions, 20 deletions
diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index ee8a9a6..f3443b4 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -3,20 +3,19 @@ class OxFile < Output require 'fileutils' def initialize - @cfg = CFG.output[:file] + @cfg = CFG.output.file end def setup - if not @cfg - CFG.output[:file] = { - :directory => File.join(Config::Root, 'configs') - } - CFG.save + if @cfg.empty? + CFGS.user.output.file.directory = File.join(Config::Root, 'configs') + CFGS.save :user + raise NoConfig, 'no output file config, edit ~/.config/oxidized/config' end end def store node, data, opt={} - file = @cfg[:directory] + file = @cfg.directory if opt[:group] file = File.join File.dirname(file), opt[:group] end @@ -26,7 +25,7 @@ class OxFile < Output end def fetch node, group - cfg_dir = @cfg[:directory] + cfg_dir = @cfg.directory if group # group is explicitly defined by user IO.readlines File.join(cfg_dir, group, node) else diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb index b4fa4a8..ff9237b 100644 --- a/lib/oxidized/output/git.rb +++ b/lib/oxidized/output/git.rb @@ -5,25 +5,24 @@ class Git < Output include Grit def initialize - @cfg = CFG.output[:git] + @cfg = CFG.output.git end def setup - if not @cfg - CFG.output[:git] = { - :user => 'Oxidized', - :email => 'o@example.com', - :repo => File.join(Config::Root, 'oxidized.git') - } - CFG.save + if @cfg.empty? + CFGS.user.output.git.user = 'Oxidized' + CFGS.user.output.git.email = 'o@example.com' + CFGS.user.output.git.repo = File.join(Config::Root, 'oxidized.git') + CFGS.save :user + raise NoConfig, 'no output git config, edit ~/.config/oxidized/config' 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] + 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 @@ -41,7 +40,7 @@ class Git < Output def fetch node, group begin - repo = Repo.new(@cfg[:repo]) + repo = Repo.new(@cfg.repo) (repo.tree / node).data rescue 'node not found' diff --git a/lib/oxidized/output/output.rb b/lib/oxidized/output/output.rb index 61cb2b5..54d616c 100644 --- a/lib/oxidized/output/output.rb +++ b/lib/oxidized/output/output.rb @@ -1,5 +1,6 @@ module Oxidized class Output + class NoConfig < OxidizedError; end class << self def inherited klass Oxidized.mgr.loader = { :class => klass } |