Skip to content

Commit

Permalink
Create WorkspaceSettings model
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Piñera committed Jan 6, 2019
1 parent f363129 commit 8d1e856
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Fixtures/WorkspaceSettings.xcsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Original</string>
</dict>
</plist>
Empty file removed Fixtures/newfile.swift
Empty file.
34 changes: 34 additions & 0 deletions Sources/xcodeproj/Project/WorkspaceSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Foundation
import PathKit

public enum WorkspaceSettingsError: Error {
/// thrown when the settings file was not found.
case notFound(path: Path)
}

/// It represents the WorkspaceSettings.xcsettings file under a workspace data directory.
public class WorkspaceSettings: Decodable {
/// Workspace build system.
public let buildSystem: String?

/// Decodable coding keys.
///
/// - buildSystem: Build system.
enum CodingKeys: String, CodingKey {
case buildSystem = "BuildSystemType"
}

/// Initializes the settings reading the values from the WorkspaceSettings.xcsettings file.
///
/// - Parameter path: Path to the WorkspaceSettings.xcsettings
/// - Returns: The initialized workspace settings.
/// - Throws: An error if the file doesn't exist or has an invalid format.
public static func at(path: Path) throws -> WorkspaceSettings {
if !path.exists {
throw WorkspaceSettingsError.notFound(path: path)
}
let data = try Data(contentsOf: path.url)
let plistDecoder = PropertyListDecoder()
return try plistDecoder.decode(WorkspaceSettings.self, from: data)
}
}
13 changes: 13 additions & 0 deletions Tests/xcodeprojTests/Project/WorkspaceSettingsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation
import PathKit
import XCTest

@testable import xcodeproj

final class WorkspaceSettingsTests: XCTestCase {
func test_init() throws {
let path = fixturesPath() + "WorkspaceSettings.xcsettings"
let got = try WorkspaceSettings.at(path: path)
XCTAssertEqual(got.buildSystem, "Original")
}
}

0 comments on commit 8d1e856

Please sign in to comment.