Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IgorMuzyka/f4248dab875cb67d5842267c34390c31 to your computer and use it in GitHub Desktop.
Save IgorMuzyka/f4248dab875cb67d5842267c34390c31 to your computer and use it in GitHub Desktop.
extension Restorable {
public static func restore(from path: Path) throws -> Self {
return try Self.read(from: path)
}
}
extension Persistable {
@discardableResult
public func persist(to directory: Path, override shouldOverride: Bool = true) throws -> File<Self> {
let path = directory + (fileName + Self.fileExtension)
let file = File<Self>(path: path)
if file.exists && shouldOverride { try file.delete() }
try file.create()
try write(to: file.path)
return file
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment