class LaunchDarkly::EventOutputFormatter
@private
Public Class Methods
new(config)
click to toggle source
# File lib/ldclient-rb/events.rb, line 407 def initialize(config) @inline_users = config.inline_users_in_events @user_filter = UserFilter.new(config) end
Public Instance Methods
make_output_events(events, summary)
click to toggle source
Transforms events into the format used for event sending.
# File lib/ldclient-rb/events.rb, line 413 def make_output_events(events, summary) events_out = events.map { |e| make_output_event(e) } if !summary.counters.empty? events_out.push(make_summary_event(summary)) end events_out end
Private Instance Methods
make_output_event(event)
click to toggle source
# File lib/ldclient-rb/events.rb, line 428 def make_output_event(event) case event[:kind] when "feature" is_debug = event[:debug] out = { kind: is_debug ? "debug" : "feature", creationDate: event[:creationDate], key: event[:key], value: event[:value] } out[:default] = event[:default] if event.has_key?(:default) out[:variation] = event[:variation] if event.has_key?(:variation) out[:version] = event[:version] if event.has_key?(:version) out[:prereqOf] = event[:prereqOf] if event.has_key?(:prereqOf) out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind) if @inline_users || is_debug out[:user] = process_user(event) else out[:userKey] = event[:user][:key] end out[:reason] = event[:reason] if !event[:reason].nil? out when "identify" { kind: "identify", creationDate: event[:creationDate], key: event[:user][:key].to_s, user: process_user(event) } when "custom" out = { kind: "custom", creationDate: event[:creationDate], key: event[:key] } out[:data] = event[:data] if event.has_key?(:data) if @inline_users out[:user] = process_user(event) else out[:userKey] = event[:user][:key] end out[:metricValue] = event[:metricValue] if event.has_key?(:metricValue) out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind) out when "index" { kind: "index", creationDate: event[:creationDate], user: process_user(event) } else event end end
make_summary_event(summary)
click to toggle source
Transforms the summary data into the format used for event sending.
# File lib/ldclient-rb/events.rb, line 484 def make_summary_event(summary) flags = {} summary[:counters].each { |ckey, cval| flag = flags[ckey[:key]] if flag.nil? flag = { default: cval[:default], counters: [] } flags[ckey[:key]] = flag end c = { value: cval[:value], count: cval[:count] } if !ckey[:variation].nil? c[:variation] = ckey[:variation] end if ckey[:version].nil? c[:unknown] = true else c[:version] = ckey[:version] end flag[:counters].push(c) } { kind: "summary", startDate: summary[:start_date], endDate: summary[:end_date], features: flags } end
process_user(event)
click to toggle source
# File lib/ldclient-rb/events.rb, line 423 def process_user(event) filtered = @user_filter.transform_user_props(event[:user]) Util.stringify_attrs(filtered, USER_ATTRS_TO_STRINGIFY_FOR_EVENTS) end