Sha256: 60fa9cec450660842d3326e87217a5589d94afc58389aaef6778771e23b3cf7d

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

module Oxidized
class OxidizedFile < Output
  require 'fileutils'

  attr_reader :commitref

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

  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

  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

  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

  def version node, group
    # not supported
    []
  end

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

end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
oxidized-0.16.3 lib/oxidized/output/file.rb
oxidized-0.16.2 lib/oxidized/output/file.rb
oxidized-0.16.1 lib/oxidized/output/file.rb
oxidized-0.16.0 lib/oxidized/output/file.rb
oxidized-0.15.0 lib/oxidized/output/file.rb
oxidized-0.14.3 lib/oxidized/output/file.rb
oxidized-0.14.2 lib/oxidized/output/file.rb
oxidized-0.14.1 lib/oxidized/output/file.rb
oxidized-0.14.0 lib/oxidized/output/file.rb
oxidized-0.13.1 lib/oxidized/output/file.rb
oxidized-0.13.0 lib/oxidized/output/file.rb
oxidized-0.12.2 lib/oxidized/output/file.rb
oxidized-0.12.1 lib/oxidized/output/file.rb
oxidized-0.12.0 lib/oxidized/output/file.rb
oxidized-0.11.0 lib/oxidized/output/file.rb
oxidized-0.10.0 lib/oxidized/output/file.rb