Skip to content

Commit

Permalink
refactor: Move model into ReporterCore (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Feb 13, 2025
1 parent b28650a commit fb01a48
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import Foundation

struct Changes: CustomStringConvertible {
public struct Changes: CustomStringConvertible {

let additions: [String]
let deletions: [String]
public let additions: [String]
public let deletions: [String]

let isEmpty: Bool
public let isEmpty: Bool

var description: String {
public var description: String {
return (
"\(additions.count) additions\n" +
additions
Expand All @@ -42,7 +42,7 @@ struct Changes: CustomStringConvertible {
)
}

init(additions: [String], deletions: [String]) {
public init(additions: [String], deletions: [String]) {
self.additions = additions
self.deletions = deletions
self.isEmpty = additions.isEmpty && deletions.isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import Foundation

struct KeyedChanges {
public struct KeyedChanges {

let url: URL
let changes: Changes
let name: String
let path: String
public let url: URL
public let changes: Changes
public let name: String
public let path: String

init(url: URL, changes: Changes) {
public init(url: URL, changes: Changes) {
self.url = url
self.changes = changes
self.name = url.lastPathComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@

import Foundation

struct Report {
public struct Report {

var isEmpty: Bool {
public var isEmpty: Bool {
return folders.reduce(true) { partialResult, folder in
return partialResult && folder.changes.isEmpty
}
}

var folders: [KeyedChanges]
public var folders: [KeyedChanges]

public init(folders: [KeyedChanges]) {
self.folders = folders
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

import Foundation

enum ReporterError: Error {
public enum ReporterError: Error {
case failed
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@

import Foundation

struct State: Codable {
public struct State: Codable {

struct Item: Codable, Hashable {
let path: String
let checksum: Data?
public struct Item: Codable, Hashable, Sendable {
public let path: String
public let checksum: Data?

public init(path: String, checksum: Data?) {
self.path = path
self.checksum = checksum
}
}

struct Snapshot: Codable {
public struct Snapshot: Codable {

var description: String {
public var description: String {
return "\(items.count) files"
}

let items: Set<Item>
public let items: Set<Item>

init(items: [Item] = []) {
public init(items: [Item] = []) {
self.items = Set(items)
}

func changes(from initialState: Snapshot) -> Changes {
public func changes(from initialState: Snapshot) -> Changes {
let additions = items.subtracting(initialState.items)
let deletions = initialState.items.subtracting(items)
return Changes(
Expand All @@ -50,9 +55,9 @@ struct State: Codable {

}

var snapshots: [URL: Snapshot]
public var snapshots: [URL: Snapshot]

init() {
public init() {
self.snapshots = [:]
}

Expand Down

0 comments on commit fb01a48

Please sign in to comment.