-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af19240
commit 4b214c2
Showing
14 changed files
with
315 additions
and
9 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
Sources/Equatable/MomUniquenessConstraints+Equatable.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,34 @@ | ||
// | ||
// MomUniquenessConstraints+Equatable.swift | ||
// | ||
// | ||
// Created by Eric Marchand on 01/07/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
extension MomUniquenessConstraints: Equatable { | ||
|
||
public static func == (lhs: MomUniquenessConstraints, rhs: MomUniquenessConstraints) -> Bool { | ||
if lhs.constraints.count != rhs.constraints.count { | ||
return false | ||
} | ||
return lhs.constraints == rhs.constraints | ||
} | ||
} | ||
|
||
extension MomUniquenessConstraint: Equatable { | ||
|
||
public static func == (lhs: MomUniquenessConstraint, rhs: MomUniquenessConstraint) -> Bool { | ||
if lhs.constraints.count != rhs.constraints.count { | ||
return false | ||
} | ||
return lhs.constraints == rhs.constraints | ||
} | ||
} | ||
|
||
extension MomConstraint: Equatable { | ||
public static func == (lhs: MomConstraint, rhs: MomConstraint) -> Bool { | ||
return lhs.value == rhs.value | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// MomUniquenessConstraints+XML.swift | ||
// | ||
// | ||
// Created by Eric Marchand on 01/07/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
extension MomUniquenessConstraints: XMLObject { | ||
|
||
public init?(xml: XML) { | ||
guard let element = xml.element, element.name == "uniquenessConstraints" else { | ||
return nil | ||
} | ||
|
||
for child in xml.children { | ||
if let entry = MomUniquenessConstraint(xml: child) { | ||
self.constraints.append(entry) | ||
} else { | ||
MomXML.orphanCallback?(xml, MomUniquenessConstraint.self) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
extension MomUniquenessConstraint: XMLObject { | ||
|
||
public init?(xml: XML) { | ||
guard let element = xml.element, element.name == "uniquenessConstraint" else { | ||
return nil | ||
} | ||
for child in xml.children { | ||
if let entry = MomConstraint(xml: child) { | ||
self.constraints.append(entry) | ||
} else { | ||
MomXML.orphanCallback?(xml, MomConstraint.self) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
extension MomConstraint: XMLObject { | ||
|
||
public init?(xml: XML) { | ||
guard let element = xml.element, element.name == "constraint" else { | ||
return nil | ||
} | ||
guard let value = element.attribute(by: "value")?.text else { | ||
return nil | ||
} | ||
self.init(value: value) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// MomUniquenessConstraints.swift | ||
// MomXML | ||
// | ||
// Created by Eric Marchand on 01/07/2020. | ||
// Copyright © 2020 phimage. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct MomUniquenessConstraints { | ||
|
||
public var constraints: [MomUniquenessConstraint] = [] | ||
|
||
public mutating func add(constraint: MomUniquenessConstraint) { | ||
self.constraints.append(constraint) | ||
} | ||
|
||
public var isEmpty: Bool { | ||
return constraints.isEmpty | ||
} | ||
|
||
public init(uniquenessConstraints: [[Any]] = []) { | ||
self.constraints = uniquenessConstraints.compactMap { MomUniquenessConstraint(constraints: $0) } | ||
} | ||
|
||
} | ||
|
||
public struct MomUniquenessConstraint { | ||
|
||
public var constraints: [MomConstraint] = [] | ||
public init() {} | ||
|
||
public init?(constraints: [Any]) { | ||
self.constraints = constraints.compactMap { MomConstraint(any: $0) } | ||
if self.constraints.isEmpty { | ||
return nil | ||
} | ||
} | ||
|
||
} | ||
|
||
public struct MomConstraint { | ||
public var value: String | ||
public init(value: String) { | ||
self.value = value | ||
} | ||
public init?(any: Any) { | ||
guard let value = any as? String else { | ||
return nil | ||
} | ||
self.value = value | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
Sources/ToCoreData/MomUniquenessConstraints+CoreData.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,34 @@ | ||
// | ||
// MomUniquenessConstraints.swift | ||
// | ||
// | ||
// Created by Eric Marchand on 01/07/2020. | ||
// | ||
|
||
import Foundation | ||
|
||
import CoreData | ||
|
||
extension MomUniquenessConstraints { | ||
|
||
public var coreData: [[String]] { | ||
return self.constraints.map { $0.coreData } | ||
} | ||
|
||
} | ||
|
||
extension MomUniquenessConstraint { | ||
|
||
public var coreData: [String] { | ||
return self.constraints.map { $0.coreData } | ||
} | ||
|
||
} | ||
|
||
extension MomConstraint { | ||
|
||
public var coreData: String { | ||
return self.value | ||
} | ||
|
||
} |
Oops, something went wrong.