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



156
157
158
159
160
# File 'lib/fluent/configurable.rb', line 156

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



170
171
172
173
174
175
176
177
# File 'lib/fluent/configurable.rb', line 170

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



162
163
164
# File 'lib/fluent/configurable.rb', line 162

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

#config_set_desc(name, desc) ⇒ Object



166
167
168
# File 'lib/fluent/configurable.rb', line 166

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

#configure_proxy(mod_name) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/fluent/configurable.rb', line 142

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



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

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

#configured_in(section_name) ⇒ Object



152
153
154
# File 'lib/fluent/configurable.rb', line 152

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

#desc(description) ⇒ Object



179
180
181
# File 'lib/fluent/configurable.rb', line 179

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

#dump_config_definitionObject



195
196
197
# File 'lib/fluent/configurable.rb', line 195

def dump_config_definition
  configure_proxy_map[self.to_s].dump_config_definition
end

#merged_configure_proxyObject



183
184
185
186
187
188
189
190
191
192
193
# File 'lib/fluent/configurable.rb', line 183

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