-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keep a cache around and use it if available when linting
speeds up lint operation by avoiding having to re-parse all files
- Loading branch information
Showing
10 changed files
with
172 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Sources/stringray/Strings Table/Cache/CachedStringsTable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// CachedStringsTable.swift | ||
// stringray | ||
// | ||
// Created by Geoffrey Foster on 2018-12-12. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CachedStringsTable: Codable { | ||
let stringsTable: StringsTable | ||
let cacheKeys: [String: Date] | ||
|
||
enum LocalizationType { | ||
case strings | ||
case stringsdict | ||
} | ||
|
||
init(stringsTable: StringsTable, cacheKeys: [String: Date]) { | ||
self.stringsTable = stringsTable | ||
self.cacheKeys = cacheKeys | ||
} | ||
|
||
func strings(for locale: Locale) -> OrderedSet<StringsTable.Entry>? { | ||
return stringsTable.entries[locale] | ||
} | ||
|
||
func stringsDict(for locale: Locale) -> [String: StringsTable.DictEntry]? { | ||
return stringsTable.dictEntries[locale] | ||
} | ||
|
||
func isCacheValid(for locale: Locale, type: LocalizationType, base: URL) -> Bool { | ||
do { | ||
let fileURL: URL | ||
switch type { | ||
case .strings: | ||
fileURL = try base.stringsURL(tableName: stringsTable.name, locale: locale) | ||
case .stringsdict: | ||
fileURL = try base.stringsDictURL(tableName: stringsTable.name, locale: locale) | ||
} | ||
let attributes = try FileManager.default.attributesOfItem(atPath: fileURL.path) | ||
guard let modificationDate = attributes[.modificationDate] as? Date else { return false } | ||
return modificationDate == cacheKeys[CachedStringsTable.cacheKey(for: locale, type: type)] | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
static func cacheKey(for locale: Locale, type: LocalizationType) -> String { | ||
switch type { | ||
case .strings: | ||
return "\(locale.identifier).strings" | ||
case .stringsdict: | ||
return "\(locale.identifier).stringsdict" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters