Sha256: 1a4e77870118558c67427fca34447bb243b00c9c1f3ef8a15863ae9a928da349

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

module Analytics
  module Serializer
    class Swift < 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 AnalyticsFile
        def initialize(src)
          @src = src
        end

        def save(path)
          @file_name = 'Analytics.swift'
          output_path = File.join(path, @file_name)
          File.write(output_path, render)
        end

        private

        def render
          ERB.new(template, nil, '-').result(binding)
        end

        def template
          <<~TEMPLATE
            <%= ERB.new(Analytics::Templates.tmpl_at('header.erb')).result(binding) %>

            import Foundation

            final class Analytics {

                private let loggers: [AnalyticsLogger]

                init(loggers: [AnalyticsLogger]) {
                    self.loggers = loggers
                }
            }

            // MARK: - AnalyticsLogger

            extension Analytics: AnalyticsLogger {

                func set(enabled: Bool) {
                    loggers.forEach { $0.set(enabled: enabled) }
                }

                func log(event: Analytics.Event) {
                    loggers.forEach { $0.log(event: event) }
                }

                func track(screen: Analytics.Screen) {
                    loggers.forEach { $0.track(screen: screen) }
                }

                func set(userProperty: Analytics.UserProperty) {
                    loggers.forEach { $0.set(userProperty: userProperty) }
                }
            }
          TEMPLATE
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ios_analytics_cli-1.1.0 lib/ios_analytics_cli/serializers/swift/analytics.rb
ios_analytics_cli-1.0.0 lib/ios_analytics_cli/serializers/swift/analytics.rb