Skip to content

Commit 9435273

Browse files
committed
Merge branch 'release/1.1.0'
2 parents ebc9475 + eda383c commit 9435273

19 files changed

+206
-45
lines changed

.swiftlint.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
line_length: 200
2+
identifier_name:
3+
min_length: 2
4+
excluded:
5+
- .build
6+
disabled_rules:
7+
- nesting
8+
- redundant_optional_initialization

Package.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
// swift-tools-version:4.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

4-
54
import PackageDescription
65

76
let package = Package(
87
name: "PolymorphCore",
98
products: [
10-
// Products define the executables and libraries produced by a package, and make them visible to other packages.
119
.library(
1210
name: "PolymorphCore",
13-
targets: ["PolymorphCore"]),
11+
targets: ["PolymorphCore"])
1412
],
1513
dependencies: [
16-
.package(url: "https://github.com/Digipolitan/string-case-swift.git", .branch("master")),
14+
.package(url: "https://github.com/Digipolitan/string-case-swift.git", from: "1.0.0")
1715
],
1816
targets: [
19-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
20-
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2117
.target(
2218
name: "PolymorphCore",
2319
dependencies: ["StringCase"]),
2420
.testTarget(
2521
name: "PolymorphCoreTests",
26-
dependencies: ["PolymorphCore"]),
22+
dependencies: ["PolymorphCore"])
2723
]
2824
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
targets: ["XXX"]),
2222
],
2323
dependencies: [
24-
.package(url: "https://github.com/Digipolitan/polymorph-core.git", .branch("master"))
24+
.package(url: "https://github.com/Digipolitan/polymorph-core.git", from: "1.1.0")
2525
],
2626
targets: [
2727
.target(

Sources/PolymorphCore/Class.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ extension Class: Hashable {
131131
return self.id.hashValue
132132
}
133133

134-
public static func ==(lhs: Class, rhs: Class) -> Bool {
134+
public static func == (lhs: Class, rhs: Class) -> Bool {
135135
return lhs.name == rhs.name
136136
}
137137
}

Sources/PolymorphCore/Endpoint.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ public class Endpoint: Member, Documentable, Codable {
1717
case options
1818
case trace
1919
case connect
20+
21+
public static func all() -> [Method] {
22+
return [
23+
.get,
24+
.post,
25+
.put,
26+
.delete,
27+
.options,
28+
.trace,
29+
.connect
30+
]
31+
}
2032
}
2133

2234
// MARK: Codable
@@ -25,6 +37,8 @@ public class Endpoint: Member, Documentable, Codable {
2537
case name
2638
case path
2739
case method
40+
case serializer
41+
case parser
2842
case inputType
2943
case inputGenericTypes
3044
case outputType
@@ -40,6 +54,10 @@ public class Endpoint: Member, Documentable, Codable {
4054

4155
public var method: Method
4256

57+
public var serializer: Service.Transformer?
58+
59+
public var parser: Service.Transformer?
60+
4361
public var inputType: UUID
4462

4563
public var inputGenericTypes: [UUID]?

Sources/PolymorphCore/Enum.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public class Enum: Object, Documentable, Packageable {
2323
public enum RawType: String, Codable {
2424
case int
2525
case string
26+
27+
public static func all() -> [RawType] {
28+
return [
29+
.int,
30+
.string
31+
]
32+
}
2633
}
2734

2835
public struct Value: Documentable, Codable {
@@ -88,7 +95,7 @@ extension Enum: Hashable {
8895
return self.id.hashValue
8996
}
9097

91-
public static func ==(lhs: Enum, rhs: Enum) -> Bool {
98+
public static func == (lhs: Enum, rhs: Enum) -> Bool {
9299
return lhs.name == rhs.name
93100
}
94101
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// External.swift
3+
// PolymorphCore
4+
//
5+
// Created by Benoit BRIATTE on 13/11/2017.
6+
//
7+
8+
import Foundation
9+
10+
public class External: Object, Documentable, Packageable {
11+
12+
public enum ExternalType: String, Codable {
13+
case `class`
14+
case interface
15+
case `enum`
16+
17+
public static func all() -> [ExternalType] {
18+
return [
19+
.class,
20+
.interface,
21+
.enum
22+
]
23+
}
24+
}
25+
26+
// MARK: Codable
27+
28+
enum CodingKeys: String, CodingKey {
29+
case id
30+
case name
31+
case package
32+
case documentation
33+
case type
34+
}
35+
36+
// MARK: Properties
37+
38+
public var id: UUID
39+
40+
public var name: String
41+
42+
public var package: Package
43+
44+
public var documentation: String?
45+
46+
public var type: ExternalType
47+
48+
public var canonicalName: String? {
49+
guard
50+
let project = self.project,
51+
let package = try? self.merge(parent: project) else {
52+
return nil
53+
}
54+
return "\(package.value).\(self.name)"
55+
}
56+
57+
public internal(set) weak var project: Project? = nil
58+
59+
// MARK: Initializers
60+
61+
public init(name: String, package: Package, type: ExternalType = .class) {
62+
self.id = UUID()
63+
self.name = name
64+
self.package = package
65+
self.type = type
66+
}
67+
}
68+
69+
extension External: Hashable {
70+
71+
public var hashValue: Int {
72+
return self.id.hashValue
73+
}
74+
75+
public static func == (lhs: External, rhs: External) -> Bool {
76+
return lhs.name == rhs.name
77+
}
78+
}

Sources/PolymorphCore/Models.swift

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Models: Documentable, Codable {
1515
case documentation
1616
case classes
1717
case enums
18+
case externals
1819
}
1920

2021
// MARK: Properties
@@ -23,11 +24,13 @@ public class Models: Documentable, Codable {
2324

2425
public private(set) var classes: [UUID: Class]
2526
public private(set) var enums: [UUID: Enum]
27+
public private(set) var externals: [UUID: External]
2628

2729
public internal(set) weak var project: Project? = nil {
2830
didSet {
2931
self.classes.values.forEach { $0.project = self.project }
3032
self.enums.values.forEach { $0.project = self.project }
33+
self.externals.values.forEach { $0.project = self.project }
3134
}
3235
}
3336

@@ -36,6 +39,7 @@ public class Models: Documentable, Codable {
3639
public init() {
3740
self.classes = [:]
3841
self.enums = [:]
42+
self.externals = [:]
3943
}
4044

4145
// MARK: Objects
@@ -47,20 +51,24 @@ public class Models: Documentable, Codable {
4751
if let en = self.enums[uuid] {
4852
return en
4953
}
50-
return nil
54+
return self.externals[uuid]
5155
}
5256

5357
public func findObject(name: String) -> Object? {
5458
if let c = self.findClass(name: name) {
5559
return c
5660
}
57-
return self.findEnum(name: name)
61+
if let e = self.findEnum(name: name) {
62+
return e
63+
}
64+
return self.findExternal(name: name)
5865
}
5966

6067
public func searchObjects(matching: String) -> [Object] {
6168
var objects: [Object] = []
6269
objects += self.searchClasses(matching: matching) as [Object]
6370
objects += self.searchEnums(matching: matching) as [Object]
71+
objects += self.searchExternals(matching: matching) as [Object]
6472
return objects
6573
}
6674

@@ -123,4 +131,32 @@ public class Models: Documentable, Codable {
123131
public func searchEnums(matching: String) -> [Enum] {
124132
return self.enums.values.filter { $0.name.range(of: matching, options: .caseInsensitive) != nil }
125133
}
134+
135+
// MARK: External
136+
137+
@discardableResult
138+
public func addExternal(_ newExternal: External) -> Bool {
139+
guard self.externals[newExternal.id] == nil else {
140+
return false
141+
}
142+
self.externals[newExternal.id] = newExternal
143+
return true
144+
}
145+
146+
@discardableResult
147+
public func removeExternal(uuid: UUID) -> Bool {
148+
guard self.externals[uuid] != nil else {
149+
return false
150+
}
151+
self.externals[uuid] = nil
152+
return true
153+
}
154+
155+
public func findExternal(name: String) -> External? {
156+
return self.externals.first { $0.value.name == name }?.value
157+
}
158+
159+
public func searchExternals(matching: String) -> [External] {
160+
return self.externals.values.filter { $0.name.range(of: matching, options: .caseInsensitive) != nil }
161+
}
126162
}

Sources/PolymorphCore/Native.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ public class Native: Member {
1919
case data = "Data"
2020
case array = "Array"
2121
case map = "Map"
22+
case url = "URL"
23+
case multilingual = "Multilingual"
24+
25+
public static func all() -> [DataType] {
26+
return [
27+
.int,
28+
.bool,
29+
.double,
30+
.float,
31+
.date,
32+
.string,
33+
.data,
34+
.array,
35+
.map,
36+
.url,
37+
.multilingual
38+
]
39+
}
2240

2341
public static func from(string: String) -> DataType? {
2442
return Native.mapping[string.lowercased()]
@@ -39,14 +57,16 @@ public class Native: Member {
3957
"array": .array,
4058
"map": .map,
4159
"dict": .map,
42-
"dictionary": .map
60+
"dictionary": .map,
61+
"url": .url,
62+
"multilingual": .multilingual
4363
]
4464

4565
// MARK: Properties
4666

4767
public var name: String
4868

49-
public internal(set) weak var project: Project? = nil
69+
public internal(set) weak var project: Project?
5070

5171
// MARK: Initializers
5272

@@ -61,7 +81,7 @@ extension Native: Hashable {
6181
return self.name.hashValue
6282
}
6383

64-
public static func ==(lhs: Native, rhs: Native) -> Bool {
84+
public static func == (lhs: Native, rhs: Native) -> Bool {
6585
return lhs.name == rhs.name
6686
}
6787
}

Sources/PolymorphCore/NativeFactory.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,10 @@ import Foundation
99

1010
internal class NativeFactory {
1111

12-
internal static let dataTypes: [Native.DataType] = [
13-
.int,
14-
.bool,
15-
.double,
16-
.float,
17-
.date,
18-
.string,
19-
.data,
20-
.array,
21-
.map
22-
]
23-
2412
internal static func create(project: Project) -> [UUID: Native] {
2513
var idx = 1
2614
var natives = [UUID: Native]()
27-
NativeFactory.dataTypes.forEach {
15+
Native.DataType.all().forEach {
2816
guard let uuid = UUID(uuidString: "00000001-0000-0000-0000-\(String(format: "%012d", idx))") else {
2917
return
3018
}

0 commit comments

Comments
 (0)