Class: Beaker::DSL::InstallUtils::FeatureFlags
- Inherits:
-
Object
- Object
- Beaker::DSL::InstallUtils::FeatureFlags
- Defined in:
- lib/beaker-pe/install/feature_flags.rb
Overview
This helper class encapsulates querying feature flag settings from options which can be used to drive Beaker’s install behavior around new or experimental features, typically in the PE Modules.
Also handles initializing feature flag settings from environment variables for CI. In this way, flags can be pulled in without needing to munge Beaker’s config file which is often handled inside of a script in Jenkins.
Flags are expected to be found in a feature_flags
hash in the options under the key :feature_flags. Beaker::OptionHash should ensure that all keys end up as symbols. If you are programatically constructing the answers, you must take care to use merge() to add elements.
All flag keys are expected to be downcased with underscores.
Environment variables may be uppercased.
Constant Summary collapse
- FLAGS =
%w{ pe_modules_next }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#flag?(flag) ⇒ Boolean?
Returns the boolean state of the flag as found in options, or if not found in the answers, then it checks for an environment variable.
-
#initialize(options) ⇒ FeatureFlags
constructor
A new instance of FeatureFlags.
-
#register_flags! ⇒ Object
Updates options[:feature_flags] with any environment variables found based on FLAGS, but if and only if they are not already present.
Constructor Details
#initialize(options) ⇒ FeatureFlags
Returns a new instance of FeatureFlags.
33 34 35 |
# File 'lib/beaker-pe/install/feature_flags.rb', line 33 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/beaker-pe/install/feature_flags.rb', line 31 def @options end |
Instance Method Details
#flag?(flag) ⇒ Boolean?
Returns the boolean state of the flag as found in options, or if not found in the answers, then it checks for an environment variable.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/beaker-pe/install/feature_flags.rb', line 42 def flag?(flag) key = canonical_key(flag) state = flags[key] if flags? state = environment_flag?(key) if state.nil? case state when nil then nil else state.to_s == 'true' end end |
#register_flags! ⇒ Object
Updates options[:feature_flags] with any environment variables found based on FLAGS, but if and only if they are not already present.
(existing :answers take precedence)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/beaker-pe/install/feature_flags.rb', line 57 def register_flags! answers_with_registered_flags = answers answers_with_registered_flags[:feature_flags] ||= StringifyHash.new new_flags = answers_with_registered_flags[:feature_flags] FLAGS.each do |flag| key = canonical_key(flag) value = flag?(key) if !new_flags.include?(key) && !value.nil? new_flags[key] = value end end .merge!( :answers => answers_with_registered_flags ) if !new_flags.empty? end |