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
158 159 160 161 162 |
# File 'lib/fluent/configurable.rb', line 158 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
172 173 174 175 176 177 178 179 |
# File 'lib/fluent/configurable.rb', line 172 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
164 165 166 |
# File 'lib/fluent/configurable.rb', line 164 def config_set_default(name, defval) configure_proxy(self.name).config_set_default(name, defval) end |
#config_set_desc(name, desc) ⇒ Object
168 169 170 |
# File 'lib/fluent/configurable.rb', line 168 def config_set_desc(name, desc) configure_proxy(self.name).config_set_desc(name, desc) end |
#configure_proxy(mod_name) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/fluent/configurable.rb', line 144 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
138 139 140 141 142 |
# File 'lib/fluent/configurable.rb', line 138 def configure_proxy_map map = {} self.define_singleton_method(:configure_proxy_map){ map } map end |
#configured_in(section_name) ⇒ Object
154 155 156 |
# File 'lib/fluent/configurable.rb', line 154 def configured_in(section_name) configure_proxy(self.name).configured_in(section_name) end |
#desc(description) ⇒ Object
181 182 183 |
# File 'lib/fluent/configurable.rb', line 181 def desc(description) configure_proxy(self.name).desc(description) end |
#dump_config_definition ⇒ Object
197 198 199 |
# File 'lib/fluent/configurable.rb', line 197 def dump_config_definition configure_proxy_map[self.to_s].dump_config_definition end |
#merged_configure_proxy ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/fluent/configurable.rb', line 185 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 |