Module: Fluentd::Setting::Common
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Model
- Included in:
- InForward, InHttp, InMonitorAgent, InSyslog, OutElasticsearch, OutForward, OutForward::Secondary, OutForward::Server, OutMongo, OutS3, OutStdout, OutTd
- Defined in:
- app/models/fluentd/setting/common.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #boolenan(key) ⇒ Object
- #child_class(key) ⇒ Object
- #children_of(key) ⇒ Object
- #column_type(key) ⇒ Object
- #conf(key) ⇒ Object
- #empty_value? ⇒ Boolean
- #flag(key) ⇒ Object
- #input_plugin? ⇒ Boolean
- #output_plugin? ⇒ Boolean
- #plugin_type_name ⇒ Object
- #print_if_present(key) ⇒ Object
- #to_config(elm_name = nil) ⇒ Object
- #values_of(key) ⇒ Object
Instance Method Details
#boolenan(key) ⇒ Object
130 131 132 |
# File 'app/models/fluentd/setting/common.rb', line 130 def boolenan(key) send(key).presence == "true" ? "#{key} true" : "#{key} false" end |
#child_class(key) ⇒ Object
72 73 74 |
# File 'app/models/fluentd/setting/common.rb', line 72 def child_class(key) self.class.children[key][:class] end |
#children_of(key) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/fluentd/setting/common.rb', line 60 def children_of(key) = self.class.children[key] return unless klass = [:class] data = send(key) || {"0" => {}} children = [] data.each_pair do |index, attrs| children << klass.new(attrs) end children end |
#column_type(key) ⇒ Object
80 81 82 |
# File 'app/models/fluentd/setting/common.rb', line 80 def column_type(key) self.class.types.try(:[], key) || "string" end |
#conf(key) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/fluentd/setting/common.rb', line 84 def conf(key) case column_type(key) when :boolean boolenan(key) when :flag flag(key) when :nested return "" unless send(key) klass = child_class(key) send(key).map do |(_, child)| # send("servers") # # "servers" => { # "0" => { # "name" => "foo", # "host" => "bar", # .. # }, # "1" => { # .. # } # } child_instance = klass.new(child) unless child_instance.empty_value? "\n" + child_instance.to_config(key).gsub(/^/m, " ") end end.join else # including :hidden print_if_present(key) end end |
#empty_value? ⇒ Boolean
138 139 140 141 142 143 144 |
# File 'app/models/fluentd/setting/common.rb', line 138 def empty_value? config = "" self.class.const_get(:KEYS).each do |key| config << conf(key) end config.empty? end |
#flag(key) ⇒ Object
134 135 136 |
# File 'app/models/fluentd/setting/common.rb', line 134 def flag(key) send(key).presence == "true" ? key.to_s : "" end |
#input_plugin? ⇒ Boolean
146 147 148 |
# File 'app/models/fluentd/setting/common.rb', line 146 def input_plugin? self.class.to_s.match(/::In|^In/) end |
#output_plugin? ⇒ Boolean
150 151 152 |
# File 'app/models/fluentd/setting/common.rb', line 150 def output_plugin? not input_plugin? end |
#plugin_type_name ⇒ Object
116 117 118 119 120 |
# File 'app/models/fluentd/setting/common.rb', line 116 def plugin_type_name # Fluentd::Setting::OutS3 -> s3 # Override this method if not above style try(:plugin_name) || self.class.to_s.split("::").last.sub(/(In|Out)/, "").downcase end |
#print_if_present(key) ⇒ Object
122 123 124 125 126 127 128 |
# File 'app/models/fluentd/setting/common.rb', line 122 def print_if_present(key) # e.g.: # path /var/log/td/aaa # user nobody # retry_limit 3 send(key).present? ? "#{key} #{send(key)}" : "" end |
#to_config(elm_name = nil) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'app/models/fluentd/setting/common.rb', line 154 def to_config(elm_name = nil) indent = " " if elm_name config = "<#{elm_name}>\n" else if input_plugin? config = "<source>\n" else config = "<match #{match}>\n" end config << "#{indent}type #{plugin_type_name}\n" end self.class.const_get(:KEYS).each do |key| next if key == :match config << indent config << conf(key) config << "\n" end if elm_name config << "</#{elm_name}>\n" else if input_plugin? config << "</source>\n" else config << "</match>\n" end end config.gsub(/^[ ]*\n/m, "") end |
#values_of(key) ⇒ Object
76 77 78 |
# File 'app/models/fluentd/setting/common.rb', line 76 def values_of(key) self.class.values.try(:[], key) || [] end |