Class: RubyEventStore::Flipper::NotificationHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(event_store, stream_pattern, custom_events) ⇒ NotificationHandler

Returns a new instance of NotificationHandler.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_event_store/flipper.rb', line 16

def initialize(event_store, stream_pattern, custom_events)
  @event_store = event_store
  @stream_pattern = stream_pattern
  @custom_events = {
    "ToggleAdded" => Events::ToggleAdded,
    "ToggleRemoved" => Events::ToggleRemoved,
    "ToggleGloballyEnabled" => Events::ToggleGloballyEnabled,
    "ToggleEnabledForActor" => Events::ToggleEnabledForActor,
    "ToggleEnabledForGroup" => Events::ToggleEnabledForGroup,
    "ToggleEnabledForPercentageOfActors" => Events::ToggleEnabledForPercentageOfActors,
    "ToggleEnabledForPercentageOfTime" => Events::ToggleEnabledForPercentageOfTime,
    "ToggleGloballyDisabled" => Events::ToggleGloballyDisabled,
    "ToggleDisabledForActor" => Events::ToggleDisabledForActor,
    "ToggleDisabledForGroup" => Events::ToggleDisabledForGroup,
    "ToggleDisabledForPercentageOfActors" => Events::ToggleDisabledForPercentageOfActors,
    "ToggleDisabledForPercentageOfTime" => Events::ToggleDisabledForPercentageOfTime,
  }.merge(custom_events || {})
end

Instance Method Details

#call(_name, _start, _finish, _id, payload) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/ruby_event_store/flipper.rb', line 35

def call(_name, _start, _finish, _id, payload)
  feature_name = payload.fetch(:feature_name).to_s
  operation = payload.fetch(:operation)
  common_payload = { feature_name: feature_name }
  if (domain_event = build_domain_event(common_payload, operation, payload))
    event_store.publish(domain_event, stream_name: stream_pattern.(feature_name))
  end
end