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
# File 'lib/oxidized/output/file.rb', line 7

def initialize
  @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



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

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

#get_version(node, group, oid) ⇒ Object



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

def get_version node, group, oid
  'not supported'
end

#setupObject



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

def setup
  if @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
end

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



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

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 }
  @commitref = file
end

#version(node, group) ⇒ Object



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

def version node, group
  # not supported
  []
end