Skip to content

Commit

Permalink
Merge pull request #5 from kayak/features/additional_attributions
Browse files Browse the repository at this point in the history
Allow adding additional attributions
  • Loading branch information
VitalyYurchenko authored Jun 14, 2019
2 parents 9a77769 + 346b006 commit e4891aa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Attributions/Attributions/Attribution.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

class Attribution {
public class Attribution {

let name: String
let displayedForMainBundleIDs: [String]
let license: License
public let name: String
public let displayedForMainBundleIDs: [String]
public let license: License

convenience init?(json: [AnyHashable: Any]) {
guard
Expand All @@ -19,7 +19,7 @@ class Attribution {
self.init(name: name, displayedForMainBundleIDs: displayedForMainBundleIDs, license: license)
}

init(name: String, displayedForMainBundleIDs: [String], license: License) {
public init(name: String, displayedForMainBundleIDs: [String], license: License) {
self.name = name
self.displayedForMainBundleIDs = displayedForMainBundleIDs
self.license = license
Expand Down
3 changes: 2 additions & 1 deletion Attributions/Attributions/AttributionReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class AttributionReader {
func compileAttributions(sections: [AttributionSection], mainBundle: Bundle, licenseFiles: [String]) throws -> [[Attribution]] {
var attributionsPerSection = [[Attribution]]()
for section in sections {
let attributions = try jsonToAttribution(file: section.file, mainBundle: mainBundle)
var attributions = try jsonToAttribution(file: section.file, mainBundle: mainBundle)
try attributions.forEach {
let licenseReader = LicenseReader(attribution: $0, licenseFiles: licenseFiles)
try licenseReader.verifyLicenseExists()
}
attributions.append(contentsOf: section.additionalAttributions)
attributionsPerSection.append(attributions)
}
return attributionsPerSection
Expand Down
4 changes: 3 additions & 1 deletion Attributions/Attributions/AttributionSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public struct AttributionSection {

public let file: URL
public let description: String
public let additionalAttributions: [Attribution]

public init(file: URL, description: String) {
public init(file: URL, description: String, additionalAttributions: [Attribution] = []) {
self.file = file
self.description = description
self.additionalAttributions = additionalAttributions
}

}
2 changes: 1 addition & 1 deletion Attributions/Attributions/License.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

enum License {
public enum License {

case id(String)
case text(String)
Expand Down
4 changes: 3 additions & 1 deletion Attributions/AttributionsTests/AttributionReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class AttributionReaderTests: XCTestCase {
XCTFail()
return
}
sections.append(AttributionSection(file: path, description: "GoodJSON"))
let additionalAttribution = Attribution(name: "Additional Framework", displayedForMainBundleIDs: [], license: .text("It's free!!!"))
sections.append(AttributionSection(file: path, description: "GoodJSON", additionalAttributions: [additionalAttribution]))

verifyReadingSections(framework: "Apache", hasBundleIDs: [])
verifyReadingSections(framework: "Eclipse", hasBundleIDs: [])
verifyReadingSections(framework: "Another Framework", hasBundleIDs: ["com.kayak.AttributionsTests"])
verifyReadingSections(framework: "Additional Framework", hasBundleIDs: [])
}

func testThrowsErrorForBadLicenseKey() {
Expand Down

0 comments on commit e4891aa

Please sign in to comment.