-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Returned instances are injected the component factory (also for block…
…s!). This commit completes the previous one, making factories based on blocks also inject the factory when appropriate. The idea is using the already working implementation from the initializer closures: the block turns into the implementation of a hidden method, the real method gets intercepted by forwardInvocation, which gets redirected to the hidden method, and the return value gets injected with the component factory if needed. Tests added or updated for the new feature. See #144
- Loading branch information
1 parent
20d8032
commit 074fcd1
Showing
18 changed files
with
358 additions
and
77 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
32 changes: 32 additions & 0 deletions
32
Source/Factory/Provider/TyphoonAssistedFactoryMethodBlockClosure.h
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,32 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2014, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "TyphoonAssistedFactoryMethodClosure.h" | ||
|
||
/** | ||
* A closure of a factory method. Internally this object stores a description of | ||
* both the factory method and the init method selector. Each time you invoke the | ||
* factory method (through forwardInvocation) a simple 1-to-1 mapping of the | ||
* arguments will be performed, and the call will be forwarded. | ||
* | ||
* Users should not use this class directly. | ||
*/ | ||
@interface TyphoonAssistedFactoryMethodBlockClosure : NSObject <TyphoonAssistedFactoryMethodClosure> | ||
|
||
/** | ||
* Creates a new closure pointing to the given selector, for the factory method | ||
* described by methodSignature. | ||
*/ | ||
- (instancetype)initWithSelector:(SEL)selector methodSignature:(NSMethodSignature *)methodSignature; | ||
|
||
@end |
53 changes: 53 additions & 0 deletions
53
Source/Factory/Provider/TyphoonAssistedFactoryMethodBlockClosure.m
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,53 @@ | ||
// | ||
// TyphoonAssistedFactoryMethodBlockClosure.m | ||
// A-Typhoon | ||
// | ||
// Created by Daniel Rodríguez Troitiño on 01/02/14. | ||
// Copyright (c) 2014 Jasper Blues. All rights reserved. | ||
// | ||
|
||
#import "TyphoonAssistedFactoryMethodBlockClosure.h" | ||
|
||
@implementation TyphoonAssistedFactoryMethodBlockClosure | ||
{ | ||
SEL _selector; | ||
} | ||
|
||
@synthesize methodSignature = _methodSignature; | ||
|
||
- (instancetype)initWithSelector:(SEL)selector methodSignature:(NSMethodSignature *)methodSignature | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
NSParameterAssert(selector); | ||
NSParameterAssert(methodSignature); | ||
|
||
_selector = selector; | ||
_methodSignature = methodSignature; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (NSInvocation *)invocationWithFactory:(id)factory forwardedInvocation:(NSInvocation *)anInvocation | ||
{ | ||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:_methodSignature]; | ||
invocation.target = factory; | ||
invocation.selector = _selector; | ||
|
||
NSUInteger numberOfArguments = [_methodSignature numberOfArguments]; | ||
for (NSUInteger idx = 2; idx < numberOfArguments; idx++) { | ||
NSUInteger argumentSize = 0; | ||
NSGetSizeAndAlignment([_methodSignature getArgumentTypeAtIndex:idx], &argumentSize, NULL); | ||
|
||
void *argument = malloc(argumentSize); | ||
[anInvocation getArgument:argument atIndex:idx]; | ||
[invocation setArgument:argument atIndex:idx]; | ||
free(argument); | ||
} | ||
|
||
return invocation; | ||
} | ||
|
||
@end |
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
35 changes: 35 additions & 0 deletions
35
Source/Factory/Provider/TyphoonAssistedFactoryMethodInitializerClosure.h
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,35 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#include "TyphoonAssistedFactoryMethodClosure.h" | ||
|
||
|
||
@class TyphoonAssistedFactoryMethodInitializer; | ||
|
||
/** | ||
* A closure of a factory method. Internally this object stores a description of | ||
* both the factory method and the init method. Each time you invoke the | ||
* factory method (through forwardInvocation) the mapping described in the method | ||
* initializer will be performed, and the call will be forwarded. | ||
* | ||
* Users should not use this class directly. | ||
*/ | ||
@interface TyphoonAssistedFactoryMethodInitializerClosure : NSObject <TyphoonAssistedFactoryMethodClosure> | ||
|
||
/** | ||
* Creates a new closure from the description of the initializer, for the | ||
* factory method described by methodSignature. | ||
*/ | ||
- (instancetype)initWithInitializer:(TyphoonAssistedFactoryMethodInitializer *)initializer methodSignature:(NSMethodSignature *)methodSignature; | ||
|
||
@end |
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 |
---|---|---|
|
@@ -20,4 +20,6 @@ | |
|
||
- (id)paymentFactory; | ||
|
||
- (id)pizzaFactory; | ||
|
||
@end |
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
Oops, something went wrong.