Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PATH
specs:
evva (0.9.0)
colorize (~> 1.0)
csv (>= 3.0)
csv (~> 3.0)
safe_yaml (~> 1.0)

GEM
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Support optional people properties in Kotlin: `innerValue` is now `Any?` and optional special properties use `value?.key`

## [0.9.0] - 2026-09-04

- Add `Platform` column support in the events sheet and `filter_by_platforms` configuration to filter generated events by platform
Expand Down
12 changes: 11 additions & 1 deletion lib/evva/kotlin_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,21 @@ def people_properties(people_bundle, file_name, enums_file_name, destinations_fi

properties = people_bundle.map do |property|
type = native_type(property.type)
value_fetcher = "value"

if special_property?(type)
if type.end_with?("?")
# optional value, we need ? to access a parameter
value_fetcher += "?"
end
value_fetcher += ".key"
Comment thread
mrstif marked this conversation as resolved.
end

{
class_name: camelize(property.property_name),
property_name: constantize(property.property_name),
type: type,
is_special_property: special_property?(property.type),
value_fetcher: value_fetcher,
destinations: property.destinations.map { |p| constantize(p) },
}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/evva/templates/kotlin/people_properties.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sealed class <%= class_name %>(
property: <%= enums_class_name %>,
val innerValue: Any,
val innerValue: Any?,
val destinations: Array<<%= destinations_class_name %>> = emptyArray(),
) {
val name = property.key
Expand All @@ -10,7 +10,7 @@ sealed class <%= class_name %>(
val value: <%= property[:type] %>,
) : <%= class_name %>(
property = <%= enums_class_name %>.<%= property[:property_name] %>,
innerValue = value<% if property[:is_special_property] %>.key<% end %>,
innerValue = <%= property[:value_fetcher] %>,
<%- if property[:destinations].count > 0 -%>
destinations = arrayOf(
<%- property[:destinations].each_with_index do |d, index| -%>
Expand Down
20 changes: 14 additions & 6 deletions spec/lib/evva/kotlin_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@
describe "#people_properties" do
subject { generator.people_properties(people_bundle, "AnalyticsProperty", "AnalyticsProperties", "AnalyticsDestinations") }
let(:people_bundle) { [
Evva::AnalyticsProperty.new("rounds_with_wear", "String", []),
Evva::AnalyticsProperty.new("rounds_with_wear", "String?", []),
Evva::AnalyticsProperty.new("last_active_at", "Date", []),
Evva::AnalyticsProperty.new("wear_platform", "WearableAppPlatform", ["firebase", "custom destination"]),
Evva::AnalyticsProperty.new("upgrade_source", "PremiumFrom", []),
Evva::AnalyticsProperty.new("wear_platform", "WearableAppPlatform?", ["firebase", "custom destination"]),
] }
let(:expected) {
<<-Kotlin
Expand All @@ -170,13 +171,13 @@

sealed class AnalyticsProperty(
property: AnalyticsProperties,
val innerValue: Any,
val innerValue: Any?,
val destinations: Array<AnalyticsDestinations> = emptyArray(),
) {
val name = property.key

data class RoundsWithWear(
val value: String,
val value: String?,
) : AnalyticsProperty(
property = AnalyticsProperties.ROUNDS_WITH_WEAR,
innerValue = value,
Expand All @@ -189,11 +190,18 @@
innerValue = value,
)

data class UpgradeSource(
val value: PremiumFrom,
) : AnalyticsProperty(
property = AnalyticsProperties.UPGRADE_SOURCE,
innerValue = value.key,
)

data class WearPlatform(
val value: WearableAppPlatform,
val value: WearableAppPlatform?,
) : AnalyticsProperty(
property = AnalyticsProperties.WEAR_PLATFORM,
innerValue = value.key,
innerValue = value?.key,
destinations = arrayOf(
AnalyticsDestinations.FIREBASE,
AnalyticsDestinations.CUSTOM_DESTINATION,
Expand Down
Loading