Skip to content

Commit

Permalink
Fix make script (#43)
Browse files Browse the repository at this point in the history
* fixes make_tag script to include swift-source

* Adds GleanPlumbHelpers.swift
  • Loading branch information
Tarik Eshaq authored Feb 16, 2022
1 parent a276a45 commit 29772c8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion make_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ else
fi

"$THIS_DIR/generate.sh" $AS_PATH || exit 1
git add "$THIS_DIR/generated"
git add "$THIS_DIR/swift-source"

if [ "false" = $IS_LOCAL ]; then
echo "Removing application services repository after generating bindings"
Expand Down
2 changes: 1 addition & 1 deletion swift-source/Generated/Metrics/Metrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension GleanMetrics {
// Intentionally left private, no external user can instantiate a new global object.
}

public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 2, day: 12, hour: 15, minute: 6, second: 39))
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 2, day: 16, hour: 17, minute: 5, second: 28))
}

enum NimbusEvents {
Expand Down
72 changes: 72 additions & 0 deletions swift-source/Nimbus/GleanPlumbHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* This Source Code Form is subject to the terms of the Mozilla
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation

/**
* Instances of this class are useful for implementing a messaging service based upon
* Nimbus.
*
* The message helper is designed to help string interpolation and JEXL evalutaiuon against the context
* of the attrtibutes Nimbus already knows about.
*
* App-specific, additional context can be given at creation time.
*
* The helpers are designed to evaluate multiple messages at a time, however: since the context may change
* over time, the message helper should not be stored for long periods.
*/
public protocol GleanPlumbProtocol {
func createMessageHelper() throws -> GleanPlumbMessageHelper
func createMessageHelper(additionalContext: [String: Any]) throws -> GleanPlumbMessageHelper
func createMessageHelper<T: Encodable>(additionalContext: T) throws -> GleanPlumbMessageHelper
}

/**
* A helper object to make working with Strings uniform across multiple implementations of the messaging
* system.
*
* This object provides access to a JEXL evaluator which runs against the same context as provided by
* Nimbus targeting.
*
* It should also provide a similar function for String substitution, though this scheduled for EXP-2159.
*/
public class GleanPlumbMessageHelper {
private let targetingHelper: NimbusTargetingHelperProtocol
private let stringHelper: NimbusStringHelperProtocol

init(targetingHelper: NimbusTargetingHelperProtocol, stringHelper: NimbusStringHelperProtocol) {
self.targetingHelper = targetingHelper
self.stringHelper = stringHelper
}

public func evalJexl(expression: String) throws -> Bool {
try targetingHelper.evalJexl(expression: expression)
}

public func getUuid(template: String) -> String? {
stringHelper.getUuid(template: template)
}

public func stringFormat(template: String, uuid: String?) -> String {
stringHelper.stringFormat(template: template, uuid: uuid)
}
}

// MARK: Dummy implementations

internal class AlwaysFalseTargetingHelper: NimbusTargetingHelperProtocol {
public func evalJexl(expression _: String) throws -> Bool {
false
}
}

internal class NonStringHelper: NimbusStringHelperProtocol {
public func getUuid(template _: String) -> String? {
nil
}

public func stringFormat(template: String, uuid _: String?) -> String {
template
}
}

0 comments on commit 29772c8

Please sign in to comment.