-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce New Plugin Classes #866
Changes from all commits
19caf7b
f601453
5c237ac
e2cb738
36e13f6
6912c05
4087110
e54b5bb
0fffaf3
2612e9f
013ea4d
44e2bdc
e82c40d
1f53273
1ef535f
9ae1fc6
682b574
80c014d
58f508c
3e62883
2c825e8
a169cf7
0a6cd4f
db19c73
3a98938
f458123
fe56d93
dbb3492
d773e01
11db673
db901fa
a3f3a7f
ff4212b
14d19d0
af735c1
e96dcdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ | |
module Fluent | ||
module Config | ||
class ConfigureProxy | ||
attr_accessor :name, :final, :param_name, :init, :required, :multi, :alias, :argument, :params, :defaults, :descriptions, :sections | ||
attr_accessor :name, :final, :param_name, :init, :required, :multi, :alias, :configured_in_section | ||
attr_accessor :argument, :params, :defaults, :descriptions, :sections | ||
# config_param :desc, :string, :default => '....' | ||
# config_set_default :buffer_type, :memory | ||
# | ||
|
@@ -50,6 +51,11 @@ def initialize(name, opts = {}) | |
|
||
raise "init and required are exclusive" if @init && @required | ||
|
||
# specify section name for viewpoint of owner(parent) plugin | ||
# for buffer plugins: all params are in <buffer> section of owner | ||
# others: <storage>, <format> (formatter/parser), ... | ||
@configured_in_section = nil | ||
|
||
@argument = nil # nil: ignore argument | ||
@params = {} | ||
@defaults = {} | ||
|
@@ -89,6 +95,9 @@ def merge(other) # self is base class, other is subclass | |
if overwrite?(other, :alias) | ||
raise ConfigError, "BUG: subclass cannot overwrite base class's config_section: alias" | ||
end | ||
if overwrite?(other, :configured_in_section) | ||
raise ConfigError, "BUG: subclass cannot overwrite base class's config_section: configured_in" | ||
end | ||
|
||
options = {} | ||
# param_name is used not to ovewrite plugin's instance | ||
|
@@ -103,6 +112,9 @@ def merge(other) # self is base class, other is subclass | |
|
||
merged = self.class.new(other.name, options) | ||
|
||
# configured_in MUST be kept | ||
merged.configured_in_section = self.configured_in_section | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This space is needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it is not for plugin itself, but for internal handling about overwriting default values. It should be separated from argument/params/defaults/sections. |
||
merged.argument = other.argument || self.argument | ||
merged.params = other.params.merge(self.params) | ||
merged.defaults = self.defaults.merge(other.defaults) | ||
|
@@ -144,6 +156,9 @@ def merge_for_finalized(other) | |
if overwrite?(other, :alias) | ||
raise ConfigError, "BUG: subclass cannot overwrite base class's config_section: alias" | ||
end | ||
if overwrite?(other, :configured_in_section) | ||
raise ConfigError, "BUG: subclass cannot overwrite base class's config_section: configured_in" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
end | ||
|
||
options = {} | ||
options[:param_name] = other.param_name | ||
|
@@ -155,6 +170,8 @@ def merge_for_finalized(other) | |
|
||
merged = self.class.new(other.name, options) | ||
|
||
merged.configured_in_section = self.configured_in_section | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
merged.argument = self.argument || other.argument | ||
merged.params = other.params.merge(self.params) | ||
merged.defaults = other.defaults.merge(self.defaults) | ||
|
@@ -175,6 +192,15 @@ def merge_for_finalized(other) | |
merged | ||
end | ||
|
||
def overwrite_defaults(other) # other is owner plugin's corresponding proxy | ||
self.defaults = self.defaults.merge(other.defaults) | ||
self.sections.keys.each do |section_key| | ||
if other.sections.has_key?(section_key) | ||
self.sections[section_key].overwrite_defaults(other.sections[section_key]) | ||
end | ||
end | ||
end | ||
|
||
def parameter_configuration(name, *args, &block) | ||
name = name.to_sym | ||
|
||
|
@@ -213,6 +239,13 @@ def parameter_configuration(name, *args, &block) | |
[name, block, opts] | ||
end | ||
|
||
def configured_in(section_name) | ||
if @configured_in_section | ||
raise ArgumentError, "#{self.name}: configured_in called twice" | ||
end | ||
@configured_in_section = section_name.to_sym | ||
end | ||
|
||
def config_argument(name, *args, &block) | ||
if @argument | ||
raise ArgumentError, "#{self.name}: config_argument called twice" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configured_in_section
instead ofconfigured_in
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This message is for authors of plugins, and plugins use
configured_in
method to specify this value.