Skip to content

Commit

Permalink
Merge pull request #33 from IBM-Swift/ro-swifty
Browse files Browse the repository at this point in the history
Ro swifty
  • Loading branch information
rolivieri authored Dec 11, 2016
2 parents febacc0 + 1e56fe9 commit 02e61fe
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 132 deletions.
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ let package = Package(
],
dependencies: [
//.Package(url: "https://github.com/behrang/YamlSwift.git", majorVersion: 1),
.Package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", majorVersion: 15)
]
//testDependencies: []
)
85 changes: 84 additions & 1 deletion Sources/CloudFoundryEnv/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,89 @@
*/
public struct App {

public class Builder {
var id: String?
var name: String?
var uris: [String]?
var version: String?
var instanceId: String?
var instanceIndex: Int?
var limits: Limits?
var port: Int?
var spaceId: String?
var startedAt: Date?

init() {}

func setId(id: String?) -> Builder {
self.id = id
return self
}

func setName(name: String?) -> Builder {
self.name = name
return self
}

func setUris(uris: [String]) -> Builder {
self.uris = uris
return self
}

func setVersion(version: String?) -> Builder {
self.version = version
return self
}

func setInstanceId(instanceId: String?) -> Builder {
self.instanceId = instanceId
return self
}

func setInstanceIndex(instanceIndex: Int?) -> Builder {
self.instanceIndex = instanceIndex
return self
}

func setLimits(limits: Limits) -> Builder {
self.limits = limits
return self
}

func setPort(port: Int?) -> Builder {
self.port = port
return self
}

func setSpaceId(spaceId: String?) -> Builder {
self.spaceId = spaceId
return self
}

func setStartedAt(startedAt: Date?) -> Builder {
self.startedAt = startedAt
return self
}

func build() -> App? {
guard let id = id, let name = name,
let uris = uris, let version = version,
let instanceId = instanceId,
let instanceIndex = instanceIndex,
let limits = limits,
let port = port,
let spaceId = spaceId,
let startedAt = startedAt else {
return nil
}

let startedAtTs = startedAt.timeIntervalSince1970
return App(id: id, name: name, uris: uris, version: version, instanceId: instanceId,
instanceIndex: instanceIndex, limits: limits, port: port, spaceId: spaceId,
startedAtTs: startedAtTs, startedAt: startedAt)
}
}

public struct Limits {
let memory: Int
let disk: Int
Expand Down Expand Up @@ -49,7 +132,7 @@ public struct App {
* Constructor.
*/
// swiftlint:disable function_parameter_count
public init(id: String, name: String, uris: [String], version: String,
private init(id: String, name: String, uris: [String], version: String,
instanceId: String, instanceIndex: Int, limits: Limits, port: Int,
spaceId: String, startedAtTs: TimeInterval, startedAt: Date) {
// swiftlint:enable function_parameter_count
Expand Down
Loading

0 comments on commit 02e61fe

Please sign in to comment.