Class: LaunchDarkly::Impl::EventFactory
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::EventFactory
- 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().
Instance Method Summary collapse
-
#initialize(with_reasons) ⇒ EventFactory
constructor
A new instance of EventFactory.
- #new_alias_event(current_context, previous_context) ⇒ Object
- #new_custom_event(event_name, user, data, metric_value) ⇒ Object
- #new_default_event(flag, user, default_value, reason) ⇒ Object
- #new_eval_event(flag, user, detail, default_value, prereq_of_flag = nil) ⇒ Object
- #new_identify_event(user) ⇒ Object
- #new_unknown_flag_event(key, user, default_value, reason) ⇒ Object
Constructor Details
#initialize(with_reasons) ⇒ EventFactory
Returns a new instance of EventFactory.
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_alias_event(current_context, previous_context) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/ldclient-rb/impl/event_factory.rb', line 72 def new_alias_event(current_context, previous_context) { kind: 'alias', key: current_context[:key], contextKind: context_to_context_kind(current_context), previousKey: previous_context[:key], previousContextKind: context_to_context_kind(previous_context) } end |
#new_custom_event(event_name, user, data, metric_value) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ldclient-rb/impl/event_factory.rb', line 82 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[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous] e end |
#new_default_event(flag, user, default_value, reason) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ldclient-rb/impl/event_factory.rb', line 35 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[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous] e end |
#new_eval_event(flag, user, detail, default_value, prereq_of_flag = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous] e end |
#new_identify_event(user) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ldclient-rb/impl/event_factory.rb', line 64 def new_identify_event(user) { kind: 'identify', key: user[:key], user: user } end |
#new_unknown_flag_event(key, user, default_value, reason) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ldclient-rb/impl/event_factory.rb', line 51 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[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous] e end |