Class: Oxidized::OxidizedFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Output

#cfg_to_str

Constructor Details

#initializeOxidizedFile

Returns a new instance of OxidizedFile.



7
8
9
10
# File 'lib/oxidized/output/file.rb', line 7

def initialize
  super
  @cfg = Oxidized.config.output.file
end

Instance Attribute Details

#commitrefObject (readonly)

Returns the value of attribute commitref.



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

def commitref
  @commitref
end

Instance Method Details

#fetch(node, group) ⇒ Object



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

def fetch(node, group)
  cfg_dir   = File.expand_path @cfg.directory
  node_name = node.name

  if group # group is explicitly defined by user
    cfg_dir = File.join File.dirname(cfg_dir), group
    File.read File.join(cfg_dir, node_name)
  elsif File.exist? File.join(cfg_dir, node_name) # node configuration file is stored on base directory
    File.read File.join(cfg_dir, node_name)
  else
    path = Dir.glob(File.join(File.dirname(cfg_dir), '**', node_name)).first # fetch node in all groups
    File.read path
  end
rescue Errno::ENOENT
  nil
end

#get_version(_node, _group, _oid) ⇒ Object



51
52
53
# File 'lib/oxidized/output/file.rb', line 51

def get_version(_node, _group, _oid)
  'not supported'
end

#setupObject

Raises:



12
13
14
15
16
17
18
# File 'lib/oxidized/output/file.rb', line 12

def setup
  return unless @cfg.empty?

  Oxidized.asetus.user.output.file.directory = File.join(Config::ROOT, 'configs')
  Oxidized.asetus.save :user
  raise NoConfig, 'no output file config, edit ~/.config/oxidized/config'
end

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



20
21
22
23
24
25
26
27
# File 'lib/oxidized/output/file.rb', line 20

def store(node, outputs, opt = {})
  file = File.expand_path @cfg.directory
  file = File.join File.dirname(file), opt[:group] if opt[:group]
  FileUtils.mkdir_p file
  file = File.join file, node
  File.write(file, outputs.to_cfg)
  @commitref = file
end

#version(_node, _group) ⇒ Object



46
47
48
49
# File 'lib/oxidized/output/file.rb', line 46

def version(_node, _group)
  # not supported
  []
end