Module: Fluent::DataEntryPreferenceConfigurable
- Defined in:
- lib/flydata/fluent-plugins/preference.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- @@supported_custom_confs =
Hash.new{|h,k| h[k] = {}}
Class Method Summary collapse
- .included(base) ⇒ Object
- .replace_value_with_option(param_name, param_value, option_name, option_value, opts = {}) ⇒ Object
Instance Method Summary collapse
- #apply_custom_conf(conf, key, type, option) ⇒ Object
- #apply_custom_option(key, option) ⇒ Object
- #load_custom_conf(file_path = @custom_conf_path) ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/flydata/fluent-plugins/preference.rb', line 8 def self.included(base) base.extend ClassMethods base.class_eval do config_param :custom_conf_path, :string, default: nil config_param :key, :string, default: nil end end |
.replace_value_with_option(param_name, param_value, option_name, option_value, opts = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/flydata/fluent-plugins/preference.rb', line 57 def self.replace_value_with_option(param_name, param_value, option_name, option_value, opts = {}) ret = param_value case option_name when :encrypted if option_value ret = Flydata::Util::Encryptor.decrypt( param_value, opts[:key], param_name) end end ret end |
Instance Method Details
#apply_custom_conf(conf, key, type, option) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/flydata/fluent-plugins/preference.rb', line 30 def apply_custom_conf(conf, key, type, option) if conf[type.to_s] and value = conf[type.to_s][key.to_s] var_name = option[:var_name] || key instance_variable_set(:"@#{var_name}", value) end end |
#apply_custom_option(key, option) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flydata/fluent-plugins/preference.rb', line 37 def apply_custom_option(key, option) var_name = option[:var_name] || key original_value = instance_variable_get(:"@#{var_name}") value = original_value option.each do |option_name, option_value| value = Fluent::DataEntryPreferenceConfigurable.replace_value_with_option( key, value, option_name, option_value, key: @key) end if original_value != value instance_variable_set(:"@#{var_name}", value) end end |
#load_custom_conf(file_path = @custom_conf_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/flydata/fluent-plugins/preference.rb', line 16 def load_custom_conf(file_path = @custom_conf_path) custom_conf = if file_path and File.exists?(file_path) YAML.load_file(file_path) else nil end @@supported_custom_confs.each do |type, settings| settings.each do |key, option| apply_custom_conf(custom_conf, key, type, option) if custom_conf apply_custom_option(key, option) end end end |