Class: Oxidized::Output::File
- Inherits:
-
Oxidized::Output
- Object
- Oxidized::Output
- Oxidized::Output::File
- 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
-
#commitref ⇒ Object
readonly
Returns the value of attribute commitref.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(node, group) ⇒ Object
- #get_version(_node, _group, _oid) ⇒ Object
-
#initialize ⇒ File
constructor
A new instance of File.
- #setup ⇒ Object
-
#store(node, outputs, opt = {}) ⇒ Object
node: node name (String) outputs: Oxidized::Models::Outputs opts: dict of optional parameters: - group: node group - significant_changes: nil / not set / true -> store as usual false -> do not store.
- #version(_node, _group) ⇒ Object
Constructor Details
Instance Attribute Details
#commitref ⇒ Object (readonly)
Returns the value of attribute commitref.
7 8 9 |
# File 'lib/oxidized/output/file.rb', line 7 def commitref @commitref end |
Class Method Details
.clean_obsolete_nodes(active_nodes) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/oxidized/output/file.rb', line 76 def self.clean_obsolete_nodes(active_nodes) cfg_dir = ::File. Oxidized.config.output.file.directory dir_base = ::File.dirname(cfg_dir) default_dir = ::File.basename(cfg_dir) keep_files = active_nodes.map { |n| node_path(n.name, n.group) } active_groups = active_nodes.map(&:group).compact.uniq [default_dir, *active_groups].each do |group| Dir.glob(::File.join(dir_base, group, "*")).each do |file| ::File.delete(file) if ::File.file?(file) && !keep_files.include?(file) end end end |
.node_path(node_name, group_name = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/oxidized/output/file.rb', line 66 def self.node_path(node_name, group_name = nil) cfg_dir = ::File. Oxidized.config.output.file.directory if group_name ::File.join ::File.dirname(cfg_dir), group_name, node_name else ::File.join cfg_dir, node_name end end |
Instance Method Details
#fetch(node, group) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/oxidized/output/file.rb', line 40 def fetch(node, group) cfg_dir = ::File. @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
62 63 64 |
# File 'lib/oxidized/output/file.rb', line 62 def get_version(_node, _group, _oid) 'not supported' end |
#setup ⇒ Object
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
node: node name (String) outputs: Oxidized::Models::Outputs opts: dict of optional parameters:
- group: node group
- significant_changes:
nil / not set / true -> store as usual
false -> do not store
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/oxidized/output/file.rb', line 29 def store(node, outputs, opt = {}) return false if opt[:significant_changes] == false file = ::File. @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
57 58 59 60 |
# File 'lib/oxidized/output/file.rb', line 57 def version(_node, _group) # not supported [] end |