11import Foundation
22import JSONUtilities
33import PathKit
4+ import Yams
45
56public struct SpecFile {
67 public let basePath : Path
@@ -13,17 +14,20 @@ public struct SpecFile {
1314 fileprivate struct Include {
1415 let path : Path
1516 let relativePaths : Bool
17+ let enable : Bool
1618
1719 static let defaultRelativePaths = true
20+ static let defaultEnable = true
1821
1922 init ? ( any: Any ) {
2023 if let string = any as? String {
2124 path = Path ( string)
2225 relativePaths = Include . defaultRelativePaths
23- } else if let dictionary = any as? JSONDictionary ,
24- let path = dictionary [ " path " ] as? String {
26+ enable = Include . defaultEnable
27+ } else if let dictionary = any as? JSONDictionary , let path = dictionary [ " path " ] as? String {
2528 self . path = Path ( path)
26- relativePaths = dictionary [ " relativePaths " ] as? Bool ?? Include . defaultRelativePaths
29+ relativePaths = Self . resolveBoolean ( dictionary, key: " relativePaths " ) ?? Include . defaultRelativePaths
30+ enable = Self . resolveBoolean ( dictionary, key: " enable " ) ?? Include . defaultEnable
2731 } else {
2832 return nil
2933 }
@@ -38,10 +42,14 @@ public struct SpecFile {
3842 return [ ]
3943 }
4044 }
45+
46+ private static func resolveBoolean( _ dictionary: [ String : Any ] , key: String ) -> Bool ? {
47+ dictionary [ key] as? Bool ?? ( dictionary [ key] as? NSString ) ? . boolValue
48+ }
4149 }
4250
43- public init ( path: Path ) throws {
44- try self . init ( filePath: path, basePath: path. parent ( ) )
51+ public init ( path: Path , variables : [ String : String ] = [ : ] ) throws {
52+ try self . init ( filePath: path, basePath: path. parent ( ) , variables : variables )
4553 }
4654
4755 public init ( filePath: Path , jsonDictionary: JSONDictionary , basePath: Path = " " , relativePath: Path = " " , subSpecs: [ SpecFile ] = [ ] ) {
@@ -52,21 +60,23 @@ public struct SpecFile {
5260 self . filePath = filePath
5361 }
5462
55- private init ( include: Include , basePath: Path , relativePath: Path ) throws {
63+ private init ( include: Include , basePath: Path , relativePath: Path , variables : [ String : String ] ) throws {
5664 let basePath = include. relativePaths ? ( basePath + relativePath) : ( basePath + relativePath + include. path. parent ( ) )
5765 let relativePath = include. relativePaths ? include. path. parent ( ) : Path ( )
5866
59- try self . init ( filePath: include. path, basePath: basePath, relativePath: relativePath)
67+ try self . init ( filePath: include. path, basePath: basePath, variables : variables , relativePath: relativePath)
6068 }
6169
62- private init ( filePath: Path , basePath: Path , relativePath: Path = " " ) throws {
70+ private init ( filePath: Path , basePath: Path , variables : [ String : String ] , relativePath: Path = " " ) throws {
6371 let path = basePath + relativePath + filePath. lastComponent
64- let jsonDictionary = try SpecFile . loadDictionary ( path: path)
72+ let jsonDictionary = try SpecFile . loadDictionary ( path: path) . expand ( variables : variables )
6573
6674 let includes = Include . parse ( json: jsonDictionary [ " include " ] )
67- let subSpecs : [ SpecFile ] = try includes. map { include in
68- try SpecFile ( include: include, basePath: basePath, relativePath: relativePath)
69- }
75+ let subSpecs : [ SpecFile ] = try includes
76+ . filter ( \. enable)
77+ . map { include in
78+ try SpecFile ( include: include, basePath: basePath, relativePath: relativePath, variables: variables)
79+ }
7080
7181 self . init ( filePath: filePath, jsonDictionary: jsonDictionary, basePath: basePath, relativePath: relativePath, subSpecs: subSpecs)
7282 }
@@ -85,8 +95,8 @@ public struct SpecFile {
8595 }
8696 }
8797
88- public func resolvedDictionary( variables : [ String : String ] = [ : ] ) -> JSONDictionary {
89- resolvedDictionaryWithUniqueTargets ( ) . expand ( variables : variables )
98+ public func resolvedDictionary( ) -> JSONDictionary {
99+ resolvedDictionaryWithUniqueTargets ( )
90100 }
91101
92102 private func resolvedDictionaryWithUniqueTargets( ) -> JSONDictionary {
0 commit comments