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
3 changes: 3 additions & 0 deletions lib/evva/swift_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SwiftGenerator
TAB_SIZE = " " # \t -> 4 spaces

NATIVE_TYPES = %w[Int String Double Float Bool Date].freeze
SWIFT_KEYWORDS = %w[default].freeze

def initialize(swift_public: false)
@swift_public_modifier = swift_public ? "public " : ""
Expand Down Expand Up @@ -64,6 +65,7 @@ def people_properties(people_bundle, _file_name, _enums_file_name, _destinations
property_name: p.property_name,
type: type,
is_special_property: special_property?(type),
is_optional: type.end_with?("?"),
destinations: p.destinations.map { |p| camelize(p) },
}
end
Expand Down Expand Up @@ -136,6 +138,7 @@ def camelize(term)
string = string.sub(/^(?:#{@acronym_regex}(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
string.gsub!("/".freeze, "::".freeze)
string = "`#{string}`" if SWIFT_KEYWORDS.include?(string)
string
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/evva/templates/swift/destinations.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= @swift_public_modifier %>enum Destination {
enum Destination {
<%- destinations.each do |d| -%>
case <%= d %>
<%- end -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/evva/templates/swift/people_properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum Property {
<%- properties.each_with_index do |p, index| -%>
case let .<%= p[:case_name] %>(value):
return PropertyData(type: .<%= p[:case_name] %>,
value: value<% if p[:is_special_property] %>.rawValue<% end %>)
value: value<% if p[:is_special_property] %><%= "?" if p[:is_optional] %>.rawValue<% end %>)
<%- unless index == properties.count - 1 -%>

<%- end -%>
Expand Down
16 changes: 15 additions & 1 deletion spec/lib/evva/swift_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
let(:enums) { [
Evva::AnalyticsEnum.new("CourseProfileSource", ["course_discovery", "synced_courses"]),
Evva::AnalyticsEnum.new("PremiumFrom", ["Course Profile", "Round Setup"]),
Evva::AnalyticsEnum.new("PreAuthenticationScreenType", ["default", "self_improvement"]),
] }

let(:expected) {
Expand All @@ -131,6 +132,11 @@
case courseProfile = "Course Profile"
case roundSetup = "Round Setup"
}

enum PreAuthenticationScreenType: String {
case `default` = "default"
case selfImprovement = "self_improvement"
}
}
Swift
}
Expand All @@ -144,6 +150,7 @@
let(:people_bundle) { [
Evva::AnalyticsProperty.new("rounds_with_wear", "String", ["firebase"]),
Evva::AnalyticsProperty.new("wear_platform", "WearableAppPlatform", ["firebase", "custom destination"]),
Evva::AnalyticsProperty.new("reverse_trial_type", "ReverseTrialType?", ["firebase"]),
Evva::AnalyticsProperty.new("number_of_times_it_happened", "Long", []),
] }

Expand Down Expand Up @@ -173,6 +180,7 @@
enum PropertyType: String {
case roundsWithWear = "rounds_with_wear"
case wearPlatform = "wear_platform"
case reverseTrialType = "reverse_trial_type"
case numberOfTimesItHappened = "number_of_times_it_happened"

var name: String { return rawValue }
Expand All @@ -181,6 +189,7 @@
switch self {
case .roundsWithWear: return [.firebase]
case .wearPlatform: return [.firebase, .customDestination]
case .reverseTrialType: return [.firebase]
case .numberOfTimesItHappened: return []
}
}
Expand All @@ -189,6 +198,7 @@
enum Property {
case roundsWithWear(String)
case wearPlatform(WearableAppPlatform)
case reverseTrialType(ReverseTrialType?)
case numberOfTimesItHappened(Int)

var data: PropertyData {
Expand All @@ -201,6 +211,10 @@
return PropertyData(type: .wearPlatform,
value: value.rawValue)

case let .reverseTrialType(value):
return PropertyData(type: .reverseTrialType,
value: value?.rawValue)

case let .numberOfTimesItHappened(value):
return PropertyData(type: .numberOfTimesItHappened,
value: value)
Expand Down Expand Up @@ -249,7 +263,7 @@
import Foundation

public extension Analytics {
public enum Destination {
enum Destination {
case firebase
case whateverYouWantReally
}
Expand Down
Loading