Class: Fluentd::Setting::Config

Inherits:
Object
  • Object
show all
Defined in:
app/models/fluentd/setting/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Config

Returns a new instance of Config.



9
10
11
12
# File 'app/models/fluentd/setting/config.rb', line 9

def initialize(config_file)
  @fl_config = Fluent::Config.parse(IO.read(config_file), config_file, nil, true)
  @file = config_file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'app/models/fluentd/setting/config.rb', line 6

def file
  @file
end

#fl_configObject (readonly)

Returns the value of attribute fl_config.



6
7
8
# File 'app/models/fluentd/setting/config.rb', line 6

def fl_config
  @fl_config
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/fluentd/setting/config.rb', line 14

def empty?
  elements.length.zero?
end

#formattedObject



35
36
37
# File 'app/models/fluentd/setting/config.rb', line 35

def formatted
  fl_config.to_s.gsub(/<\/?ROOT>/, "").strip_heredoc.gsub(%r|^</.*?>$|, "\\0\n")
end

#matchesObject



24
25
26
27
28
# File 'app/models/fluentd/setting/config.rb', line 24

def matches
  elements.find_all do |elm|
    elm.name == "match"
  end
end

#sourcesObject



18
19
20
21
22
# File 'app/models/fluentd/setting/config.rb', line 18

def sources
  elements.find_all do |elm|
    elm.name == "source"
  end
end

#write_to_fileObject



30
31
32
33
# File 'app/models/fluentd/setting/config.rb', line 30

def write_to_file
  return unless Fluentd.instance
  Fluentd.instance.agent.config_write formatted
end