Class: LaunchDarkly::Impl::EventFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/impl/event_factory.rb

Overview

Event constructors are centralized here to avoid mistakes and repetitive logic. The LDClient owns two instances of EventFactory: one that always embeds evaluation reasons in the events (for when variation_detail is called) and one that doesn’t.

Note that these methods do not set the “creationDate” property, because in the Ruby client, that is done by EventProcessor.add_event().

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(with_reasons) ⇒ EventFactory

Returns a new instance of EventFactory.

Since:

  • 5.5.0



11
12
13
# File 'lib/ldclient-rb/impl/event_factory.rb', line 11

def initialize(with_reasons)
  @with_reasons = with_reasons
end

Instance Method Details

#new_custom_event(event_name, user, data, metric_value) ⇒ Object

Since:

  • 5.5.0



69
70
71
72
73
74
75
76
77
78
# File 'lib/ldclient-rb/impl/event_factory.rb', line 69

def new_custom_event(event_name, user, data, metric_value)
  e = {
    kind: 'custom',
    key: event_name,
    user: user
  }
  e[:data] = data if !data.nil?
  e[:metricValue] = metric_value if !metric_value.nil?
  e
end

#new_default_event(flag, user, default_value, reason) ⇒ Object

Since:

  • 5.5.0



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ldclient-rb/impl/event_factory.rb', line 34

def new_default_event(flag, user, default_value, reason)
  e = {
    kind: 'feature',
    key: flag[:key],
    user: user,
    value: default_value,
    default: default_value,
    version: flag[:version]
  }
  e[:trackEvents] = true if flag[:trackEvents]
  e[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
  e[:reason] = reason if @with_reasons
  e
end

#new_eval_event(flag, user, detail, default_value, prereq_of_flag = nil) ⇒ Object

Since:

  • 5.5.0



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ldclient-rb/impl/event_factory.rb', line 15

def new_eval_event(flag, user, detail, default_value, prereq_of_flag = nil)
  add_experiment_data = is_experiment(flag, detail.reason)
  e = {
    kind: 'feature',
    key: flag[:key],
    user: user,
    variation: detail.variation_index,
    value: detail.value,
    default: default_value,
    version: flag[:version]
  }
  # the following properties are handled separately so we don't waste bandwidth on unused keys
  e[:trackEvents] = true if add_experiment_data || flag[:trackEvents]
  e[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
  e[:prereqOf] = prereq_of_flag[:key] if !prereq_of_flag.nil?
  e[:reason] = detail.reason if add_experiment_data || @with_reasons
  e
end

#new_identify_event(user) ⇒ Object

Since:

  • 5.5.0



61
62
63
64
65
66
67
# File 'lib/ldclient-rb/impl/event_factory.rb', line 61

def new_identify_event(user)
  {
    kind: 'identify',
    key: user[:key],
    user: user
  }
end

#new_unknown_flag_event(key, user, default_value, reason) ⇒ Object

Since:

  • 5.5.0



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ldclient-rb/impl/event_factory.rb', line 49

def new_unknown_flag_event(key, user, default_value, reason)
  e = {
    kind: 'feature',
    key: key,
    user: user,
    value: default_value,
    default: default_value
  }
  e[:reason] = reason if @with_reasons
  e
end