Module: Fluentd::V1::Checker

Defined in:
lib/fluentd/v1/checker.rb,
lib/fluentd/v1/checker/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.execute(path, v1conf_path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluentd/v1/checker.rb', line 25

def self.execute(path, v1conf_path)
  v0 = parse_classic(path).to_s.rstrip + "\n"
  v1 = parse_v1(v1conf_path || path).to_s.rstrip + "\n"
  diff = Diffy::Diff.new(v0, v1, :include_diff_info => true ).to_s(:color)
  if diff.strip.empty? && v1conf_path
    # ok
  elsif diff.strip.empty?
    # ok
  else
    diff = diff.sub(/--- .*$/){ "--- CLASSIC PARSE" }.sub(/\+\+\+ .*$/){ "+++ V1 PARSE" }
    puts diff
    exit 1
  end
end

.parse_classic(path) ⇒ Object



11
12
13
14
15
16
# File 'lib/fluentd/v1/checker.rb', line 11

def self.parse_classic(path)
  str = File.read(path)
  fname = File.basename(path)
  dirname = File.dirname(path)
  Fluent::Config::Parser.parse(str, fname, dirname)
end

.parse_v1(path) ⇒ Object



18
19
20
21
22
23
# File 'lib/fluentd/v1/checker.rb', line 18

def self.parse_v1(path)
  str = File.read(path)
  fname = File.basename(path)
  dirname = File.dirname(path)
  Fluent::Config::V1Parser.parse(str, fname, dirname, Kernel.binding)
end