Class: LogStash::PluginMixins::ECSCompatibilitySupport::Selector::State Private
- Inherits:
-
Object
- Object
- LogStash::PluginMixins::ECSCompatibilitySupport::Selector::State
- 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 ‘State` contains the active mode and a list of all supported modes.
It allows a developer to safely define mappings of alternative values, exactly one of which will be selected based on the effective mode.
It is NOT designed for performance, but may be helpful during instantiation.
Instance Attribute Summary collapse
- #active_mode ⇒ Object readonly private
- #supported_modes ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(supported_modes, active_mode) ⇒ State
constructor
private
A new instance of State.
-
#value_from(defined_choices) ⇒ Object
(also: #[])
private
With the active mode, select one of the provided options.
Constructor Details
#initialize(supported_modes, active_mode) ⇒ State
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 State.
83 84 85 86 |
# File 'lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb', line 83 def initialize(supported_modes, active_mode) @supported_modes = supported_modes @active_mode = active_mode end |
Instance Attribute Details
#active_mode ⇒ Object (readonly)
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.
88 89 90 |
# File 'lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb', line 88 def active_mode @active_mode end |
#supported_modes ⇒ Object (readonly)
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 supported_modes @supported_modes end |
Instance Method Details
#value_from(defined_choices) ⇒ Object Also known as: []
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.
With the active mode, select one of the provided options.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/logstash/plugin_mixins/ecs_compatibility_support/selector.rb', line 98 def value_from(defined_choices) fail(ArgumentError, "defined_choices must be a Hash") unless defined_choices.kind_of?(Hash) fail(ArgumentError, "defined_choices cannot be empty") if defined_choices.empty? fail(ArgumentError, "defined_choices must have Symbol keys") unless defined_choices.keys.all? { |k| k.kind_of?(Symbol) } fail(ArgumentError, "at least one choice must be defined") if defined_choices.empty? missing = @supported_modes - defined_choices.keys fail(ArgumentError, "missing one or more required choice definition #{missing}") if missing.any? unknown = defined_choices.keys - @supported_modes fail(ArgumentError, "unknown choices #{unknown}; valid choices are #{@supported_modes}") if unknown.any? defined_choices.fetch(@active_mode) end |