Skip to content

Commit 2ab4963

Browse files
refactor: Update context filter class to match preferred coding style (#364)
Co-authored-by: Casey Waldren <[email protected]>
1 parent 0702503 commit 2ab4963

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

libs/internal/include/launchdarkly/context_filter.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ContextFilter {
3232
* @param context The context to redact.
3333
* @return JSON suitable for an analytics event.
3434
*/
35-
JsonValue filter(Context const& context);
35+
JsonValue Filter(Context const& context);
3636

3737
private:
3838
/**
@@ -54,7 +54,7 @@ class ContextFilter {
5454
* @param item The stack item denoting placement information.
5555
* @param addition The item to add.
5656
*/
57-
static void emplace(StackItem& item, JsonValue&& addition);
57+
static void Emplace(StackItem& item, JsonValue&& addition);
5858

5959
/**
6060
* If the path needs to be redacted, then redact it and add it to the
@@ -65,7 +65,7 @@ class ContextFilter {
6565
* attributes.
6666
* @return True if the item was redacted.
6767
*/
68-
bool redact(std::vector<std::string>& redactions,
68+
bool Redact(std::vector<std::string>& redactions,
6969
std::vector<std::string_view> path,
7070
Attributes const& attributes);
7171

@@ -75,19 +75,19 @@ class ContextFilter {
7575
* @param value The container to append.
7676
* @return The appended container.
7777
*/
78-
static JsonValue* append_container(StackItem& item, JsonValue&& value);
78+
static JsonValue* AppendContainer(StackItem& item, JsonValue&& value);
7979

8080
/**
8181
* Put a simple value into the parent specified by its stack item.
8282
* @param item The stack item with value information and the parent.
8383
*/
84-
static void append_simple_type(StackItem& item);
84+
static void AppendSimpleType(StackItem& item);
8585

86-
JsonValue filter_single_context(std::string_view kind,
87-
bool include_kind,
88-
Attributes const& attributes);
86+
JsonValue FilterSingleContext(std::string_view kind,
87+
bool include_kind,
88+
Attributes const& attributes);
8989

90-
JsonValue filter_multi_context(Context const& context);
90+
JsonValue FilterMultiContext(Context const& context);
9191

9292
bool all_attributes_private_;
9393
AttributeReference::SetType const global_private_attributes_;

libs/internal/src/context_filter.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ ContextFilter::ContextFilter(
1111
: all_attributes_private_(all_attributes_private),
1212
global_private_attributes_(std::move(global_private_attributes)) {}
1313

14-
ContextFilter::JsonValue ContextFilter::filter(Context const& context) {
14+
ContextFilter::JsonValue ContextFilter::Filter(Context const& context) {
1515
// Context should be validated before calling this method.
1616
assert(context.Valid());
1717
if (context.Kinds().size() == 1) {
18-
auto kind = context.Kinds()[0];
19-
return filter_single_context(kind, INCLUDE_KIND,
20-
context.Attributes(kind.data()));
18+
std::string const& kind = context.Kinds()[0];
19+
return FilterSingleContext(kind, INCLUDE_KIND,
20+
context.Attributes(kind));
2121
}
22-
return filter_multi_context(context);
22+
return FilterMultiContext(context);
2323
}
2424

25-
void ContextFilter::emplace(ContextFilter::StackItem& item,
25+
void ContextFilter::Emplace(ContextFilter::StackItem& item,
2626
ContextFilter::JsonValue&& addition) {
2727
if (item.parent.is_object()) {
2828
item.parent.as_object().emplace(item.path.back(), std::move(addition));
@@ -31,7 +31,7 @@ void ContextFilter::emplace(ContextFilter::StackItem& item,
3131
}
3232
}
3333

34-
bool ContextFilter::redact(std::vector<std::string>& redactions,
34+
bool ContextFilter::Redact(std::vector<std::string>& redactions,
3535
std::vector<std::string_view> path,
3636
Attributes const& attributes) {
3737
if (all_attributes_private_) {
@@ -58,7 +58,7 @@ bool ContextFilter::redact(std::vector<std::string>& redactions,
5858
return false;
5959
}
6060

61-
ContextFilter::JsonValue ContextFilter::filter_single_context(
61+
ContextFilter::JsonValue ContextFilter::FilterSingleContext(
6262
std::string_view kind,
6363
bool include_kind,
6464
Attributes const& attributes) {
@@ -75,7 +75,7 @@ ContextFilter::JsonValue ContextFilter::filter_single_context(
7575
}
7676

7777
if (!attributes.Name().empty() &&
78-
!redact(redactions, std::vector<std::string_view>{"name"},
78+
!Redact(redactions, std::vector<std::string_view>{"name"},
7979
attributes)) {
8080
filtered.as_object().insert_or_assign("name", attributes.Name());
8181
}
@@ -90,20 +90,20 @@ ContextFilter::JsonValue ContextFilter::filter_single_context(
9090
stack.pop_back();
9191

9292
// Check if the attribute needs to be redacted.
93-
if (!item.path.empty() && redact(redactions, item.path, attributes)) {
93+
if (!item.path.empty() && Redact(redactions, item.path, attributes)) {
9494
continue;
9595
}
9696

9797
if (item.value.IsObject()) {
98-
JsonValue* nested = append_container(item, JsonObject());
98+
JsonValue* nested = AppendContainer(item, JsonObject());
9999

100100
for (auto const& pair : item.value.AsObject()) {
101101
auto new_path = std::vector<std::string_view>(item.path);
102102
new_path.push_back(pair.first);
103103
stack.push_back(StackItem{pair.second, new_path, *nested});
104104
}
105105
} else if (item.value.IsArray()) {
106-
JsonValue* nested = append_container(item, JsonArray());
106+
JsonValue* nested = AppendContainer(item, JsonArray());
107107

108108
// Array contents are added in reverse, this is a recursive
109109
// algorithm so they will get reversed again when the stack
@@ -120,7 +120,7 @@ ContextFilter::JsonValue ContextFilter::filter_single_context(
120120
rev_from++;
121121
}
122122
} else {
123-
append_simple_type(item);
123+
AppendSimpleType(item);
124124
}
125125
}
126126

@@ -137,19 +137,19 @@ ContextFilter::JsonValue ContextFilter::filter_single_context(
137137
return filtered;
138138
}
139139

140-
void ContextFilter::append_simple_type(ContextFilter::StackItem& item) {
140+
void ContextFilter::AppendSimpleType(ContextFilter::StackItem& item) {
141141
switch (item.value.Type()) {
142142
case Value::Type::kNull:
143-
emplace(item, JsonValue());
143+
Emplace(item, JsonValue());
144144
break;
145145
case Value::Type::kBool:
146-
emplace(item, item.value.AsBool());
146+
Emplace(item, item.value.AsBool());
147147
break;
148148
case Value::Type::kNumber:
149-
emplace(item, item.value.AsDouble());
149+
Emplace(item, item.value.AsDouble());
150150
break;
151151
case Value::Type::kString:
152-
emplace(item, item.value.AsString().c_str());
152+
Emplace(item, item.value.AsString().c_str());
153153
break;
154154
case Value::Type::kObject:
155155
case Value::Type::kArray:
@@ -158,7 +158,7 @@ void ContextFilter::append_simple_type(ContextFilter::StackItem& item) {
158158
}
159159
}
160160

161-
ContextFilter::JsonValue* ContextFilter::append_container(
161+
ContextFilter::JsonValue* ContextFilter::AppendContainer(
162162
ContextFilter::StackItem& item,
163163
JsonValue&& value) {
164164
if (item.parent.is_object()) {
@@ -169,15 +169,15 @@ ContextFilter::JsonValue* ContextFilter::append_container(
169169
return &item.parent.as_array().back();
170170
}
171171

172-
ContextFilter::JsonValue ContextFilter::filter_multi_context(
172+
ContextFilter::JsonValue ContextFilter::FilterMultiContext(
173173
Context const& context) {
174174
JsonValue filtered = JsonObject();
175175
filtered.as_object().emplace("kind", "multi");
176176

177-
for (auto const& kind : context.Kinds()) {
177+
for (std::string const& kind : context.Kinds()) {
178178
filtered.as_object().emplace(
179-
kind, filter_single_context(kind, EXCLUDE_KIND,
180-
context.Attributes(kind.data())));
179+
kind,
180+
FilterSingleContext(kind, EXCLUDE_KIND, context.Attributes(kind)));
181181
}
182182

183183
return filtered;

libs/internal/src/events/asio_event_processor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ std::vector<OutputEvent> AsioEventProcessor<SDK>::Process(
227227
event.context.CanonicalKey())) {
228228
out.emplace_back(server_side::IndexEvent{
229229
event.creation_date,
230-
filter_.filter(event.context)});
230+
filter_.Filter(event.context)});
231231
}
232232
}
233233

@@ -250,7 +250,7 @@ std::vector<OutputEvent> AsioEventProcessor<SDK>::Process(
250250

251251
if (emit_debug_event) {
252252
out.emplace_back(
253-
DebugEvent{base, filter_.filter(event.context)});
253+
DebugEvent{base, filter_.Filter(event.context)});
254254
}
255255

256256
if (event.require_full_event) {
@@ -269,7 +269,7 @@ std::vector<OutputEvent> AsioEventProcessor<SDK>::Process(
269269
}
270270

271271
out.emplace_back(IdentifyEvent{event.creation_date,
272-
filter_.filter(event.context)});
272+
filter_.Filter(event.context)});
273273
},
274274
[&](ClientTrackEventParams&& event) {
275275
out.emplace_back(std::move(event));
@@ -281,7 +281,7 @@ std::vector<OutputEvent> AsioEventProcessor<SDK>::Process(
281281
event.context.CanonicalKey())) {
282282
out.emplace_back(server_side::IndexEvent{
283283
event.base.creation_date,
284-
filter_.filter(event.context)});
284+
filter_.Filter(event.context)});
285285
}
286286
}
287287

libs/internal/tests/context_filter_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TEST(ContextFilterTests, CanRedactName) {
1717
auto global_private_attributes = AttributeReference::SetType{"name"};
1818
ContextFilter filter(false, global_private_attributes);
1919

20-
auto filtered = filter.filter(ContextBuilder()
20+
auto filtered = filter.Filter(ContextBuilder()
2121
.Kind("user", "user-key")
2222
.Name("Bob")
2323
.Set("isCat", false)
@@ -38,7 +38,7 @@ TEST(ContextFilterTests, CannotRedactKeyKindMeta) {
3838
AttributeReference::SetType{"key", "kind", "_meta", "name"};
3939
ContextFilter filter(false, global_private_attributes);
4040

41-
auto filtered = filter.filter(ContextBuilder()
41+
auto filtered = filter.Filter(ContextBuilder()
4242
.Kind("user", "user-key")
4343
.Name("Bob")
4444
.Set("isCat", false)
@@ -58,7 +58,7 @@ TEST(ContextFilterTests, BasicContext) {
5858
auto global_private_attributes = AttributeReference::SetType{"email"};
5959
ContextFilter filter(false, global_private_attributes);
6060

61-
auto filtered = filter.filter(
61+
auto filtered = filter.Filter(
6262
ContextBuilder()
6363
.Kind("user", "user-key")
6464
.Set("email", "email.email@email")
@@ -91,7 +91,7 @@ TEST(ContextFilterTests, MultiContext) {
9191
auto global_private_attributes = AttributeReference::SetType{"email"};
9292
ContextFilter filter(false, global_private_attributes);
9393

94-
auto filtered = filter.filter(
94+
auto filtered = filter.Filter(
9595
ContextBuilder()
9696
.Kind("user", "user-key")
9797
.Set("email", "email.email@email")
@@ -127,7 +127,7 @@ TEST(ContextFilterTests, AllAttributesPrivateSingleContext) {
127127
auto global_private_attributes = AttributeReference::SetType{};
128128
ContextFilter filter(true, global_private_attributes);
129129

130-
auto filtered = filter.filter(ContextBuilder()
130+
auto filtered = filter.Filter(ContextBuilder()
131131
.Kind("user", "user-key")
132132
.Name("Bob")
133133
.Set("isCat", false)
@@ -146,7 +146,7 @@ TEST(ContextFilterTests, AllAttributesPrivateMultiContext) {
146146
auto global_private_attributes = AttributeReference::SetType{};
147147
ContextFilter filter(true, global_private_attributes);
148148

149-
auto filtered = filter.filter(
149+
auto filtered = filter.Filter(
150150
ContextBuilder()
151151
.Kind("user", "user-key")
152152
.Name("Bob")

libs/internal/tests/event_serialization_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ TEST(EventSerialization, DebugEvent) {
5555
std::nullopt,
5656

5757
})),
58-
filter.filter(context)};
58+
filter.Filter(context)};
5959

6060
auto event_json = boost::json::value_from(event);
6161

@@ -71,7 +71,7 @@ TEST(EventSerialization, IdentifyEvent) {
7171
ContextFilter filter(false, attrs);
7272
auto event = events::IdentifyEvent{
7373
creation_date,
74-
filter.filter(ContextBuilder().Kind("foo", "bar").Build())};
74+
filter.Filter(ContextBuilder().Kind("foo", "bar").Build())};
7575

7676
auto event_json = boost::json::value_from(event);
7777

@@ -86,7 +86,7 @@ TEST(EventSerialization, IndexEvent) {
8686
ContextFilter filter(false, attrs);
8787
auto event = events::server_side::IndexEvent{
8888
creation_date,
89-
filter.filter(ContextBuilder().Kind("foo", "bar").Build())};
89+
filter.Filter(ContextBuilder().Kind("foo", "bar").Build())};
9090

9191
auto event_json = boost::json::value_from(event);
9292

0 commit comments

Comments
 (0)