-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added capablility to supply manual license information in the config …
…yaml file.
- Loading branch information
Alexander Widerberg
committed
Oct 4, 2017
1 parent
efe6660
commit 9c05449
Showing
9 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Foundation | ||
import APIKit | ||
import LoggerAPI | ||
import Yaml | ||
|
||
public class Manual: Library { | ||
public let name: String | ||
public var body: String? // Used as a container between YAML and ManualLicence | ||
public var source: String? | ||
public var nameSpecified: String? | ||
public var version: String? | ||
|
||
init(name n: String, source: String?, nameSpecified: String?, version: String?) { | ||
self.name = n | ||
self.source = source | ||
self.nameSpecified = nameSpecified | ||
self.version = version | ||
} | ||
} | ||
|
||
extension Manual { | ||
public static func==(lhs: Manual, rhs: Manual) -> Bool { | ||
return lhs.name == rhs.name && | ||
lhs.nameSpecified == rhs.nameSpecified && | ||
lhs.version == rhs.version | ||
} | ||
} | ||
|
||
extension Manual: CustomStringConvertible { | ||
public var description: String { | ||
return "name: \(name), source: \(source ?? ""), nameSpecified: \(nameSpecified ?? ""), version: \(version ?? "")" | ||
} | ||
} | ||
|
||
extension Manual { | ||
public static func load(_ raw: [Yaml], | ||
renames: [String: String]) -> [Manual] { | ||
return raw.map { (manualEntry) -> Manual in | ||
var name = "" | ||
var body = "" | ||
var source = "" | ||
var rename = "" | ||
var version = "" | ||
for valuePair in manualEntry.dictionary ?? [:] { | ||
switch valuePair.key.string ?? "" { | ||
case "source": | ||
source = valuePair.value.string ?? "" | ||
break | ||
case "name": | ||
name = valuePair.value.string ?? "" | ||
break | ||
case "version": | ||
version = valuePair.value.string ?? "" | ||
break | ||
case "body": | ||
body = valuePair.value.string ?? "" | ||
break | ||
default: | ||
Log.warning("Tried to parse an unknown YAML key") | ||
} | ||
} | ||
rename = renames[name] ?? "" | ||
let manual = Manual(name: name, source: source, nameSpecified: rename, version: version) | ||
manual.body = body // This is so that we do not have to store a body at all ( for testing purposes mostly ) | ||
return manual | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
import LoggerAPI | ||
|
||
public struct ManualLicense: License, Equatable { | ||
public let library: Manual | ||
public let body: String | ||
|
||
public static func==(lhs: ManualLicense, rhs: ManualLicense) -> Bool { | ||
return lhs.library == rhs.library | ||
} | ||
} | ||
|
||
extension ManualLicense: CustomStringConvertible { | ||
public var description: String { | ||
return "name: \(library.name), nameSpecified: \(library.nameSpecified ?? ""), version: \(library.version ?? "")\nbody: \(String(body.characters.prefix(20)))…" | ||
} | ||
} | ||
|
||
extension ManualLicense { | ||
public static func load(_ manuals: [Manual]) -> [ManualLicense] { | ||
return manuals.map { | ||
return ManualLicense(library: $0, body: $0.body ?? "") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters