Class: Flipper::Notifications::FeatureEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/notifications/feature_event.rb

Constant Summary collapse

NOTEWORTHY_OPERATIONS =
%w[
  add
  enable
  disable
  clear
  remove
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#featureObject (readonly)

Returns the value of attribute feature.



27
28
29
# File 'lib/flipper/notifications/feature_event.rb', line 27

def feature
  @feature
end

#operationObject (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_markdownObject



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

Returns:

  • (Boolean)


58
59
60
# File 'lib/flipper/notifications/feature_event.rb', line 58

def noteworthy?
  NOTEWORTHY_OPERATIONS.include?(operation)
end

#summary_markdownObject



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