Module: Fluent::Configurable::ClassMethods

Defined in:
lib/fluent/configurable.rb

Instance Method Summary collapse

Instance Method Details

#config_param(name, type = nil, **kwargs, &block) ⇒ Object



132
133
134
135
136
# File 'lib/fluent/configurable.rb', line 132

def config_param(name, type = nil, **kwargs, &block)
  configure_proxy(self.name).config_param(name, type, **kwargs, &block)
  # reserved names '@foo' are invalid as attr_accessor name
  attr_accessor(name) unless kwargs[:skip_accessor] || Fluent::Config::Element::RESERVED_PARAMETERS.include?(name.to_s)
end

#config_section(name, **kwargs, &block) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/fluent/configurable.rb', line 146

def config_section(name, **kwargs, &block)
  section_already_exists = !!merged_configure_proxy.sections[name]
  configure_proxy(self.name).config_section(name, **kwargs, &block)
  variable_name = configure_proxy(self.name).sections[name].variable_name
  if !section_already_exists && !self.respond_to?(variable_name)
    attr_accessor variable_name
  end
end

#config_set_default(name, defval) ⇒ Object



138
139
140
# File 'lib/fluent/configurable.rb', line 138

def config_set_default(name, defval)
  configure_proxy(self.name).config_set_default(name, defval)
end

#config_set_desc(name, desc) ⇒ Object



142
143
144
# File 'lib/fluent/configurable.rb', line 142

def config_set_desc(name, desc)
  configure_proxy(self.name).config_set_desc(name, desc)
end

#configure_proxy(mod_name) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/fluent/configurable.rb', line 118

def configure_proxy(mod_name)
  map = configure_proxy_map
  unless map[mod_name]
    type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
    proxy = Fluent::Config::ConfigureProxy.new(mod_name, root: true, required: true, multi: false, type_lookup: type_lookup)
    map[mod_name] = proxy
  end
  map[mod_name]
end

#configure_proxy_mapObject



112
113
114
115
116
# File 'lib/fluent/configurable.rb', line 112

def configure_proxy_map
  map = {}
  self.define_singleton_method(:configure_proxy_map){ map }
  map
end

#configured_in(section_name) ⇒ Object



128
129
130
# File 'lib/fluent/configurable.rb', line 128

def configured_in(section_name)
  configure_proxy(self.name).configured_in(section_name)
end

#desc(description) ⇒ Object



155
156
157
# File 'lib/fluent/configurable.rb', line 155

def desc(description)
  configure_proxy(self.name).desc(description)
end

#dump(level = 0) ⇒ Object



171
172
173
# File 'lib/fluent/configurable.rb', line 171

def dump(level = 0)
  configure_proxy_map[self.to_s].dump(level)
end

#merged_configure_proxyObject



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/fluent/configurable.rb', line 159

def merged_configure_proxy
  configurables = ancestors.reverse.select{ |a| a.respond_to?(:configure_proxy) }

  # 'a.object_id.to_s' is to support anonymous class
  #   which created in tests to overwrite original behavior temporally
  #
  # p Module.new.name   #=> nil
  # p Class.new.name    #=> nil
  # p AnyGreatClass.dup.name #=> nil
  configurables.map{ |a| a.configure_proxy(a.name || a.object_id.to_s) }.reduce(:merge)
end