Class: Oxidized::Output::File

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

Overview

ruby’s File class must be accessed with ::File to avoid name conflicts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFile

Returns a new instance of File.



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

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

Instance Attribute Details

#commitrefObject (readonly)

Returns the value of attribute commitref.



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

def commitref
  @commitref
end

Instance Method Details

#fetch(node, group) ⇒ Object



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

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



53
54
55
# File 'lib/oxidized/output/file.rb', line 53

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

#setupObject

Raises:



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

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 #{Oxidized::Config.configfile}"
end

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



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

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



48
49
50
51
# File 'lib/oxidized/output/file.rb', line 48

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