module Fluent::Configurable

Constants

CONFIG_TYPE_REGISTRY

Public Class Methods

included(mod) click to toggle source
# File lib/fluent/configurable.rb, line 24
def self.included(mod)
  mod.extend(ClassMethods)
end
lookup_type(type) click to toggle source
# File lib/fluent/configurable.rb, line 79
def self.lookup_type(type)
  CONFIG_TYPE_REGISTRY.lookup(type)
end
new() click to toggle source
# File lib/fluent/configurable.rb, line 28
def initialize
  # to simulate implicit 'attr_accessor' by config_param / config_section and its value by config_set_default
  proxy = self.class.merged_configure_proxy
  proxy.params.keys.each do |name|
    if proxy.defaults.has_key?(name)
      instance_variable_set("@#{name}".to_sym, proxy.defaults[name])
    end
  end
  proxy.sections.keys.each do |name|
    subproxy = proxy.sections[name]
    if subproxy.multi?
      instance_variable_set("@#{subproxy.param_name}".to_sym, [])
    else
      instance_variable_set("@#{subproxy.param_name}".to_sym, nil)
    end
  end
end
register_type(type, callable = nil, &block) click to toggle source
# File lib/fluent/configurable.rb, line 74
def self.register_type(type, callable = nil, &block)
  callable ||= block
  CONFIG_TYPE_REGISTRY.register(type, callable)
end

Public Instance Methods

config() click to toggle source
# File lib/fluent/configurable.rb, line 68
def config
  @masked_config ||= @config.to_masked_element
end
configure(conf) click to toggle source
# File lib/fluent/configurable.rb, line 46
def configure(conf)
  @config = conf

  logger = self.respond_to?(:log) ? log : $log
  proxy = self.class.merged_configure_proxy
  conf.corresponding_proxies << proxy

  # In the nested section, can't get plugin class through proxies so get plugin class here
  plugin_class = Plugin.lookup_name_from_class(proxy.name.to_s)
  root = Fluent::Config::SectionGenerator.generate(proxy, conf, logger, plugin_class)
  @config_root_section = root

  root.instance_eval{ @params.keys }.each do |param_name|
    varname = "@#{param_name}".to_sym
    if (! root[param_name].nil?) || instance_variable_get(varname).nil?
      instance_variable_set(varname, root[param_name])
    end
  end

  self
end