Class: Oxidized::OxidizedFile

Inherits:
Output
  • Object
show all
Defined in:
lib/oxidized/output/file.rb

Instance Method Summary collapse

Methods inherited from Output

#cfg_to_str

Constructor Details

#initializeOxidizedFile

Returns a new instance of OxidizedFile.



5
6
7
# File 'lib/oxidized/output/file.rb', line 5

def initialize
  @cfg = CFG.output.file
end

Instance Method Details

#fetch(node, group) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/oxidized/output/file.rb', line 27

def fetch node, group
  cfg_dir = @cfg.directory
  if group # group is explicitly defined by user
    IO.readlines File.join(cfg_dir, group, node)
  else
    if File.exists? File.join(cfg_dir, node) # node configuration file is stored on base directory
      IO.readlines File.join(cfg_dir, node)
    else
      path = Dir.glob File.join(cfg_dir, '**', node) # fetch node in all groups
      return nil if path[0].nil?
      open(path[0], 'r').readlines
    end
  end
end

#setupObject



9
10
11
12
13
14
15
# File 'lib/oxidized/output/file.rb', line 9

def setup
  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

#store(node, outputs, opt = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/oxidized/output/file.rb', line 17

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 outputs.to_cfg }
end