Class: Flipper::Notifications::FeatureEvent
- Inherits:
-
Object
- Object
- Flipper::Notifications::FeatureEvent
- Defined in:
- lib/flipper/notifications/feature_event.rb
Constant Summary collapse
- NOTEWORTHY_OPERATIONS =
%w[ add enable disable clear remove ].freeze
Instance Attribute Summary collapse
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #feature_enabled_settings_markdown ⇒ Object
-
#initialize(feature_name:, operation:) ⇒ FeatureEvent
constructor
A new instance of FeatureEvent.
- #noteworthy? ⇒ Boolean
- #summary_markdown ⇒ Object
Constructor Details
#initialize(feature_name:, operation:) ⇒ FeatureEvent
Returns a new instance of FeatureEvent.
22 23 24 25 |
# File 'lib/flipper/notifications/feature_event.rb', line 22 def initialize(feature_name:, operation:) @feature = Flipper.feature(feature_name) @operation = operation.to_s end |
Instance Attribute Details
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
27 28 29 |
# File 'lib/flipper/notifications/feature_event.rb', line 27 def feature @feature end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
27 28 29 |
# File 'lib/flipper/notifications/feature_event.rb', line 27 def operation @operation end |
Class Method Details
.from_active_support(event:) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/flipper/notifications/feature_event.rb', line 15 def self.from_active_support(event:) new( feature_name: event.payload[:feature_name], operation: event.payload[:operation] ) end |
Instance Method Details
#==(other) ⇒ Object
62 63 64 |
# File 'lib/flipper/notifications/feature_event.rb', line 62 def ==(other) other.is_a?(self.class) && feature == other.feature && operation == other.operation end |
#feature_enabled_settings_markdown ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/flipper/notifications/feature_event.rb', line 40 def feature_enabled_settings_markdown return "" unless feature.conditional? [].tap do |settings| settings << "The feature is now enabled for:" if feature.conditional? settings << "- Groups: #{to_sentence(feature.enabled_groups.map(&:name).sort)}" if feature.enabled_groups.any? settings << "- Actors: #{to_sentence(feature.actors_value.sort)}" if feature.actors_value.any? if feature.percentage_of_actors_value.positive? settings << "- #{feature.percentage_of_actors_value}% of actors" end settings << "- #{feature.percentage_of_time_value}% of the time" if feature.percentage_of_time_value.positive? end.join("\n") end |
#noteworthy? ⇒ Boolean
58 59 60 |
# File 'lib/flipper/notifications/feature_event.rb', line 58 def noteworthy? NOTEWORTHY_OPERATIONS.include?(operation) end |
#summary_markdown ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flipper/notifications/feature_event.rb', line 29 def summary_markdown msg = String.new("Feature *#{feature.name}* was #{action_taken}.") if include_state? msg << " The feature is now *fully enabled.*" if feature.on? msg << " The feature is now *fully disabled.*" if feature.off? end msg end |