Class: Fluentd::Setting::Config
- Inherits:
-
Object
- Object
- Fluentd::Setting::Config
- Defined in:
- app/models/fluentd/setting/config.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#fl_config ⇒ Object
readonly
Returns the value of attribute fl_config.
Instance Method Summary collapse
- #delete_element(name, arg, element) ⇒ Object
- #empty? ⇒ Boolean
- #filters ⇒ Object
- #formatted ⇒ Object
- #group_by_label ⇒ Object
-
#initialize(config_file) ⇒ Config
constructor
A new instance of Config.
- #labels ⇒ Object
- #matches ⇒ Object
- #sources ⇒ Object
- #write_to_file ⇒ Object
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'app/models/fluentd/setting/config.rb', line 6 def file @file end |
#fl_config ⇒ Object (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
#delete_element(name, arg, element) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/fluentd/setting/config.rb', line 66 def delete_element(name, arg, element) if name == "label" label_section = fl_config.elements(name: name, arg: arg).first original_size = label_section.elements.size remaining_elements = label_section.elements.reject do |e| element == e end if remaining_elements.empty? remaining_elements = fl_config.elements.reject do |e| label_section == e end fl_config.elements = remaining_elements return element else label_section.elements = remaining_elements if original_size == label_section.elements.size return nil else return element end end else original_size = fl_config.elements.size remaining_elements = fl_config.elements.reject do |e| element == e end fl_config.elements = remaining_elements if original_size == fl_config.elements.size return nil else return element end end end |
#empty? ⇒ Boolean
14 15 16 |
# File 'app/models/fluentd/setting/config.rb', line 14 def empty? elements.length.zero? end |
#filters ⇒ Object
24 25 26 27 28 |
# File 'app/models/fluentd/setting/config.rb', line 24 def filters elements.find_all do |elm| elm.name == "filter" end end |
#formatted ⇒ Object
106 107 108 |
# File 'app/models/fluentd/setting/config.rb', line 106 def formatted fl_config.to_s.gsub(/<\/?ROOT>/, "").strip_heredoc.gsub(%r|^</.*?>$|, "\\0\n") end |
#group_by_label ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/fluentd/setting/config.rb', line 42 def group_by_label hash = Hash.new{|h, k| h[k] = {} } sources.each do |source| label = source["@label"] || source["label"] if label hash[label][:sources] = [source] else hash["ROOT"][:sources] = [source] end end hash["ROOT"][:filters] = filters unless filters.empty? hash["ROOT"][:matches] = matches unless matches.empty? labels.each do |label| hash[label.arg][:filters] = label.elements.find_all do |e| e.name == "filter" end hash[label.arg][:matches] = label.elements.find_all do |e| e.name == "match" end end hash end |
#labels ⇒ Object
36 37 38 39 40 |
# File 'app/models/fluentd/setting/config.rb', line 36 def labels elements.find_all do |elm| elm.name == "label" end end |
#matches ⇒ Object
30 31 32 33 34 |
# File 'app/models/fluentd/setting/config.rb', line 30 def matches elements.find_all do |elm| elm.name == "match" end end |
#sources ⇒ Object
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 |