Class: LogStash::PluginMixins::ECSCompatibilitySupport::Selector Private
- Inherits:
-
Module
- Object
- Module
- LogStash::PluginMixins::ECSCompatibilitySupport::Selector
- Defined in:
- lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A ‘ECSCompatibilitySupport::Selector` is a `Module` that can be included into any `LogStash::Plugin` to constrain instances to a specific set of supported `ecs_compatibility` modes.
It also provides an ‘ecs_select` that allows plugin developers to specify ECS alternatives in-line with their existing code.
Defined Under Namespace
Classes: State
Instance Method Summary collapse
- #included(base) ⇒ void
-
#initialize(*ecs_modes_and_optional_alias_map) ⇒ Selector
constructor
private
A new instance of Selector.
- #name ⇒ String private
Constructor Details
#initialize(*ecs_modes_and_optional_alias_map) ⇒ Selector
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Selector.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb', line 36 def initialize(*ecs_modes_and_optional_alias_map) selector_module = self alias_mapping = ecs_modes_and_optional_alias_map.last.kind_of?(Hash) ? ecs_modes_and_optional_alias_map.pop.dup.freeze : EMPTY_HASH ecs_modes_supported = ecs_modes_and_optional_alias_map.dup fail(ArgumentError, "one or more ecs_modes_supported required") if ecs_modes_supported.empty? fail(ArgumentError, "ecs_modes_supported must only contain symbols") unless ecs_modes_supported.all? { |s| s.kind_of?(Symbol) } fail(ArgumentError, "alias names must be symbols") unless alias_mapping.keys.all? { |v| v.kind_of?(Symbol) } fail(ArgumentError, "alias targets must be symbols") unless alias_mapping.values.all? { |v| v.kind_of?(Symbol) } fail(ArgumentError, "alias must not redefine") if alias_mapping.keys.any? {|v| ecs_modes_supported.include?(v) } fail(ArgumentError, "alias map must not have circular references") if circular_references_present?(alias_mapping) ecs_modes_supported |= alias_mapping.keys fail(ArgumentError, "alias target doesn't exist") if alias_mapping.values.any? { |v| !ecs_modes_supported.include?(v) } ecs_modes_supported.freeze ## # Hooks initialization to throw a configuration error if plugin is initialized with # an unsupported `ecs_compatibility` mode. # @method initialize define_method(:initialize) do |*args| super(*args) # Plugin#initialize effective_ecs_mode = ecs_compatibility if !ecs_modes_supported.include?(effective_ecs_mode) = "#{config_name} #{@plugin_type} plugin does not support `ecs_compatibility => #{effective_ecs_mode}`. "+ "Supported modes are: #{ecs_modes_supported}" fail(LogStash::ConfigurationError, ) end @_ecs_select = selector_module.state_for(effective_ecs_mode) end ## # @method ecs_select # @return [State] define_method(:ecs_select) { @_ecs_select } define_singleton_method(:ecs_modes_supported) { ecs_modes_supported } define_singleton_method(:state_for) do |selected_value| unless ecs_modes_supported.include?(selected_value) fail(NotImplementedError, "Unsupported state `#{selected_value}` (expected one of #{ecs_modes_supported})") end State.new(ecs_modes_supported, selected_value, alias_mapping) end end |
Instance Method Details
#included(base) ⇒ void
This method returns an undefined value.
24 25 26 27 |
# File 'lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb', line 24 def included(base) fail(ArgumentError, "`#{base}` must inherit LogStash::Plugin") unless base < LogStash::Plugin base.include(ECSCompatibilitySupport) end |
#name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb', line 89 def name "#{Selector}(#{ecs_modes_supported.join(',')})" end |