require_relative '../base' module Analytics module Serializer class ObjC < Base # It's named AnalyticsFile instead of Analytics, # because it failed to have a class which used the same name as the parent module. class Enums def initialize(src) @src = src end def save(path) @class_name = 'AnalyticsEnums' @file_name = @class_name + '.h' output_path = File.join(path, @file_name) File.write(output_path, render_h) end private def render_h ERB.new(template_h, nil, '-').result(binding) end def template_h <<~TEMPLATE <%= ERB.new(Analytics::Templates.tmpl_at('header.erb')).result(binding) %> #import NS_ASSUME_NONNULL_BEGIN #pragma mark - Analytics Event Enums (AE) <% Interactor::Event.all_enum_properties(@src['events']).each do |property| -%> <% @enum_name = 'AE' + property['name'].pascal_case -%> __swift_unavailable("This enum is only available in ObjC.") typedef NS_CLOSED_ENUM(NSInteger, <%= @enum_name %>) { <% property['values'].each do |value| -%> <%= @enum_name + value.pascal_case %>, <% end -%> }; <% end -%> #pragma mark - Analytics User Property Enums (AUP) <% Interactor::UserProperty.all_enum_user_properties(@src['userProperties']).each do |property| -%> <% @enum_name = 'AUP' + property['name'].pascal_case -%> __swift_unavailable("This enum is only available in ObjC.") typedef NS_CLOSED_ENUM(NSInteger, <%= @enum_name %>) { <% property['values'].each do |value| -%> <%= @enum_name + value.pascal_case %>, <% end -%> <%= @enum_name + 'Nil' %> }; <% end -%> NS_ASSUME_NONNULL_END TEMPLATE end end end end end