Skip to content

Commit 12b7938

Browse files
committed
Moved hook-related types to Hook.swift
1 parent f7956cc commit 12b7938

2 files changed

Lines changed: 47 additions & 46 deletions

File tree

Sources/InterposeKit/Hooks/Hook+.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

Sources/InterposeKit/Hooks/Hook.swift

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Foundation
1+
import ObjectiveC
22

33
/// A runtime hook that interposes a single instance method on a class or object.
44
public final class Hook {
@@ -39,7 +39,7 @@ public final class Hook {
3939
func makeStrategy(_ hook: Hook) throws -> HookStrategy {
4040
let hookProxy = HookProxy(
4141
selector: selector,
42-
originalProvider: {
42+
getOriginal: {
4343
unsafeBitCast(
4444
self.originalIMP,
4545
to: MethodSignature.self
@@ -169,6 +169,51 @@ extension Hook {
169169
}
170170
}
171171

172+
public typealias HookBuilder<MethodSignature, HookSignature> = (HookProxy<MethodSignature>) -> HookSignature
173+
174+
public final class HookProxy<MethodSignature> {
175+
176+
internal init(
177+
selector: Selector,
178+
getOriginal: @escaping () -> MethodSignature
179+
) {
180+
self.selector = selector
181+
self._getOriginal = getOriginal
182+
}
183+
184+
public let selector: Selector
185+
186+
private let _getOriginal: () -> MethodSignature
187+
188+
public var original: MethodSignature {
189+
self._getOriginal()
190+
}
191+
192+
}
193+
194+
public enum HookScope {
195+
196+
/// The scope that targets all instances of the class.
197+
case `class`
198+
199+
/// The scope that targets a specific instance of the class.
200+
case object(AnyObject)
201+
202+
}
203+
204+
public enum HookState: Equatable {
205+
206+
/// The hook is ready to be applied.
207+
case pending
208+
209+
/// The hook has been successfully applied.
210+
case active
211+
212+
/// The hook failed to apply.
213+
case failed
214+
215+
}
216+
172217
fileprivate enum HookTarget {
173218
case `class`(AnyClass)
174219
case object(AnyObject)

0 commit comments

Comments
 (0)