Skip to content

Commit ef101e5

Browse files
committed
Move LocalFileStore to WordPressShared
We need it there because it's used by `SharedDataIssueSolver` which we'll soon need to move to WordPressData.
1 parent 899e136 commit ef101e5

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Foundation
2+
3+
extension FileManager: LocalFileStore {
4+
public func containerURL(forAppGroup appGroup: String) -> URL? {
5+
return containerURL(forSecurityApplicationGroupIdentifier: appGroup)
6+
}
7+
8+
public func fileExists(at url: URL) -> Bool {
9+
return fileExists(atPath: url.path)
10+
}
11+
12+
@discardableResult
13+
public func save(contents: Data, at url: URL) -> Bool {
14+
return createFile(atPath: url.path, contents: contents)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
3+
public protocol LocalFileStore {
4+
func data(from url: URL) throws -> Data
5+
6+
func fileExists(at url: URL) -> Bool
7+
8+
@discardableResult
9+
func save(contents: Data, at url: URL) -> Bool
10+
11+
func containerURL(forAppGroup appGroup: String) -> URL?
12+
13+
func removeItem(at url: URL) throws
14+
15+
func copyItem(at srcURL: URL, to dstURL: URL) throws
16+
}
17+
18+
public extension LocalFileStore {
19+
func data(from url: URL) throws -> Data {
20+
return try Data(contentsOf: url)
21+
}
22+
}

WordPress/Classes/Utility/Blogging Prompts/PromptRemindersScheduler.swift

+1-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import UserNotifications
3+
import WordPressShared
34

45
/// Encapsulates the local notification scheduling logic for Blogging Prompts.
56
///
@@ -459,43 +460,3 @@ struct DefaultCurrentDateProvider: CurrentDateProvider {
459460
}
460461
}
461462

462-
// MARK: - Local Store
463-
464-
/// A wrapper protocol intended for `FileManager`.
465-
/// Created to simplify unit testing.
466-
///
467-
protocol LocalFileStore {
468-
func data(from url: URL) throws -> Data
469-
470-
func fileExists(at url: URL) -> Bool
471-
472-
@discardableResult
473-
func save(contents: Data, at url: URL) -> Bool
474-
475-
func containerURL(forAppGroup appGroup: String) -> URL?
476-
477-
func removeItem(at url: URL) throws
478-
479-
func copyItem(at srcURL: URL, to dstURL: URL) throws
480-
}
481-
482-
extension LocalFileStore {
483-
func data(from url: URL) throws -> Data {
484-
return try Data(contentsOf: url)
485-
}
486-
}
487-
488-
extension FileManager: LocalFileStore {
489-
func containerURL(forAppGroup appGroup: String) -> URL? {
490-
return containerURL(forSecurityApplicationGroupIdentifier: appGroup)
491-
}
492-
493-
func fileExists(at url: URL) -> Bool {
494-
return fileExists(atPath: url.path)
495-
}
496-
497-
@discardableResult
498-
func save(contents: Data, at url: URL) -> Bool {
499-
return createFile(atPath: url.path, contents: contents)
500-
}
501-
}

WordPress/WordPressTest/PromptRemindersSchedulerTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import XCTest
22
import OHHTTPStubs
33
import OHHTTPStubsSwift
44
import CoreData
5+
import WordPressShared
56

67
@testable import WordPress
78

0 commit comments

Comments
 (0)