Module: Fluent::Configurable::ClassMethods
- Defined in:
- lib/fluent/configurable.rb
Instance Method Summary collapse
- #config_param(name, type = nil, **kwargs, &block) ⇒ Object
- #config_section(name, **kwargs, &block) ⇒ Object
- #config_set_default(name, defval) ⇒ Object
- #config_set_desc(name, desc) ⇒ Object
- #configure_proxy(mod_name) ⇒ Object
- #configure_proxy_map ⇒ Object
- #configured_in(section_name) ⇒ Object
- #desc(description) ⇒ Object
- #dump_config_definition ⇒ Object
- #merged_configure_proxy ⇒ Object
Instance Method Details
#config_param(name, type = nil, **kwargs, &block) ⇒ Object
157 158 159 160 161 |
# File 'lib/fluent/configurable.rb', line 157 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
171 172 173 174 175 176 177 178 |
# File 'lib/fluent/configurable.rb', line 171 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
163 164 165 |
# File 'lib/fluent/configurable.rb', line 163 def config_set_default(name, defval) configure_proxy(self.name).config_set_default(name, defval) end |
#config_set_desc(name, desc) ⇒ Object
167 168 169 |
# File 'lib/fluent/configurable.rb', line 167 def config_set_desc(name, desc) configure_proxy(self.name).config_set_desc(name, desc) end |
#configure_proxy(mod_name) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/fluent/configurable.rb', line 143 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_map ⇒ Object
137 138 139 140 141 |
# File 'lib/fluent/configurable.rb', line 137 def configure_proxy_map map = {} self.define_singleton_method(:configure_proxy_map){ map } map end |
#configured_in(section_name) ⇒ Object
153 154 155 |
# File 'lib/fluent/configurable.rb', line 153 def configured_in(section_name) configure_proxy(self.name).configured_in(section_name) end |
#desc(description) ⇒ Object
180 181 182 |
# File 'lib/fluent/configurable.rb', line 180 def desc(description) configure_proxy(self.name).desc(description) end |
#dump_config_definition ⇒ Object
196 197 198 |
# File 'lib/fluent/configurable.rb', line 196 def dump_config_definition configure_proxy_map[self.to_s].dump_config_definition end |
#merged_configure_proxy ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/fluent/configurable.rb', line 184 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 |