Module: Fluent::DataEntryPreferenceConfigurable

Defined in:
lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb', line 9

def self.included(base)
  base.instance_eval do
    extend ClassMethods
    @supported_custom_confs = Hash.new{|h,k| h[k] = {}}
    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



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb', line 70

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



32
33
34
35
36
37
38
# File 'lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb', line 32

def apply_custom_conf(conf, key, type, option)
  if conf[type.to_s] and conf[type.to_s].has_key?(key.to_s)
    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, type) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb', line 40

def apply_custom_option(key, option, type)
  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
  @data_entry_preferences ||= Hash.new{|h,k| h[k] = {}}
  @data_entry_preferences[type.to_s][var_name.to_s] = value
end

#load_custom_conf(file_path = @custom_conf_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flydata/fluent-plugins/flydata_plugin_ext/preference.rb', line 18

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
  self.class.instance_variable_get(:@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, type)
    end
  end
end