Skip to content

Commit

Permalink
Merge pull request #19 from IvanUshakov/raw_values
Browse files Browse the repository at this point in the history
inject manually created objects in blocks assembly
  • Loading branch information
jasperblues committed May 23, 2013
2 parents 610b238 + 16b7f60 commit 16c9b08
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Source/Component/Initializer/TyphoonInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ typedef enum

- (void)injectParameterAtIndex:(NSUInteger)index1 withDefinition:(TyphoonDefinition*)definition;

- (void)injectParameterAtIndex:(NSUInteger)index withValue:(id)value;

- (void)injectParameterNamed:(NSString*)name withValue:(id)value;

- (void)injectParameterWithValue:(id)value;
@end
19 changes: 19 additions & 0 deletions Source/Component/Initializer/TyphoonInitializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "TyphoonParameterInjectedByReference.h"
#import "NSObject+TyphoonIntrospectionUtils.h"
#import "TyphoonParameterInjectedByValue.h"
#import "TyphoonParameterInjectedByRawValue.h"
#import "TyphoonDefinition.h"


Expand Down Expand Up @@ -100,6 +101,24 @@ - (void)injectWithText:(NSString*)text requiredTypeOrNil:(id)requiredTypeOrNil
[self injectParameterAtIndex:[_injectedParameters count] withValueAsText:text requiredTypeOrNil:requiredTypeOrNil];
}

- (void)injectParameterAtIndex:(NSUInteger)index withValue:(id)value
{
if (index != NSUIntegerMax && index < [_parameterNames count])
{
[_injectedParameters addObject:[[TyphoonParameterInjectedByRawValue alloc] initWithParameterIndex:index value:value]];
}
}

- (void)injectParameterNamed:(NSString*)name withValue:(id)value
{
[self injectParameterAtIndex:[self indexOfParameter:name] withValue:value];
}

- (void)injectParameterWithValue:(id)value
{
[self injectParameterAtIndex:[_injectedParameters count] withValue:value];
}

/* ====================================================================================================================================== */
#pragma mark - Block assembly

Expand Down
3 changes: 2 additions & 1 deletion Source/Component/Initializer/TyphoonInjectedParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
typedef enum
{
TyphoonParameterInjectedByReferenceType,
TyphoonParameterInjectedByValueType
TyphoonParameterInjectedByValueType,
TyphoonParameterInjectedByRawValueType
} TyphoonParameterInjectionType;

@protocol TyphoonInjectedParameter <NSObject>
Expand Down
21 changes: 21 additions & 0 deletions Source/Component/Initializer/TyphoonParameterInjectedByRawValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// TyphoonParameterInjectedByRowValue.h
// Typhoon
//
// Created by Иван Ушаков on 23.05.13.
// Copyright (c) 2013 Jasper Blues. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TyphoonInjectedParameter.h"

@interface TyphoonParameterInjectedByRawValue : NSObject <TyphoonInjectedParameter>

@property(nonatomic, readonly) NSUInteger index;
@property(nonatomic, readonly) TyphoonParameterInjectionType type;
@property(nonatomic, strong, readonly) id value;

- (id)initWithParameterIndex:(NSUInteger)index value:(id)value;


@end
33 changes: 33 additions & 0 deletions Source/Component/Initializer/TyphoonParameterInjectedByRawValue.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// TyphoonParameterInjectedByRowValue.m
// Typhoon
//
// Created by Иван Ушаков on 23.05.13.
// Copyright (c) 2013 Jasper Blues. All rights reserved.
//

#import "TyphoonParameterInjectedByRawValue.h"

@implementation TyphoonParameterInjectedByRawValue

- (id)initWithParameterIndex:(NSUInteger)index value:(id)value
{
self = [super init];
if (self) {
_index = index;
_value = value;
}
return self;
}

- (TyphoonParameterInjectionType)type
{
return TyphoonParameterInjectedByRawValueType;
}

- (void)setInitializer:(TyphoonInitializer*)initializer
{
//Do nothing.
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "TyphoonCollectionValue.h"
#import "TyphoonByReferenceCollectionValue.h"
#import "TyphoonTypeConvertedCollectionValue.h"
#import "TyphoonParameterInjectedByRawValue.h"


@implementation TyphoonComponentFactory (InstanceBuilder)
Expand Down Expand Up @@ -102,6 +103,12 @@ - (id)invokeInitializerOn:(id)instanceOrClass withDefinition:(TyphoonDefinition*
[self setArgumentFor:invocation index:byValue.index + 2 textValue:byValue.textValue
requiredType:[byValue resolveTypeWith:instanceOrClass]];
}
else if (parameter.type == TyphoonParameterInjectedByRawValueType)
{
TyphoonParameterInjectedByRawValue* byValue = (TyphoonParameterInjectedByRawValue*) parameter;
id value = byValue.value;
[invocation setArgument:&value atIndex:parameter.index + 2];
}
}
[invocation invoke];
__autoreleasing id <NSObject> returnValue = nil;
Expand Down
11 changes: 11 additions & 0 deletions Tests/Factory/Block/MiddleAgesAssemblyOverride.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "MiddleAgesAssemblyOverride.h"
#import "TyphoonDefinition.h"
#import "TyphoonInitializer.h"
#import "Knight.h"


Expand All @@ -23,4 +24,14 @@ - (id)knight
}];
}

- (id)testString
{
return [TyphoonDefinition withClass:[NSDictionary class] initialization:^(TyphoonInitializer* initializer)
{
initializer.selector = @selector(initWithDictionary:);
[initializer injectParameterWithValue:@{@"test": @123}];
}];

}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ - (void)test_injects_properties_by_reference_and_by_value
assertThatUnsignedLongLong(knight.damselsRescued, equalToUnsignedLongLong(50));
}

- (void)test_injects_properties_by_raw_value
{
NSDictionary* string = [_componentFactory componentForType:[NSDictionary class]];
// assertThat(string, notNilValue());
// assertThat(string, equalTo(@"test string"));
}

@end
8 changes: 8 additions & 0 deletions Typhoon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
6B7CE44516C74919002E0107 /* OCMockito.framework in Install Hamcrest and Mockito */ = {isa = PBXBuildFile; fileRef = 6B7CE44416C74919002E0107 /* OCMockito.framework */; };
6BD2B6DE16AC02DD0066C5DB /* OCHamcrest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6BD2B6DD16AC02DD0066C5DB /* OCHamcrest.framework */; };
6BD2B6E216AC031B0066C5DB /* OCHamcrest.framework in Install Hamcrest and Mockito */ = {isa = PBXBuildFile; fileRef = 6BD2B6E116AC031B0066C5DB /* OCHamcrest.framework */; };
B594F87F174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m in Sources */ = {isa = PBXBuildFile; fileRef = B594F87E174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m */; };
B594F880174DF32E00BF5DC5 /* TyphoonParameterInjectedByRawValue.m in Sources */ = {isa = PBXBuildFile; fileRef = B594F87E174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m */; };
BA79800736608E888611A7B3 /* TyphoonParameterInjectedByReference.h in Headers */ = {isa = PBXBuildFile; fileRef = BA798E2173A9C04887B7291B /* TyphoonParameterInjectedByReference.h */; };
BA79800B110019810E388455 /* TyphoonXmlComponentFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BA798CE9339A8FBFF40E4B13 /* TyphoonXmlComponentFactoryTests.m */; };
BA79800FBAC7DD90540E5AD0 /* AutoWiringKnight.m in Sources */ = {isa = PBXBuildFile; fileRef = BA798705F411B8128A8D3DE5 /* AutoWiringKnight.m */; };
Expand Down Expand Up @@ -216,6 +218,8 @@
6B7CE44416C74919002E0107 /* OCMockito.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMockito.framework; path = External/OCMockito.framework; sourceTree = "<group>"; };
6BD2B6DD16AC02DD0066C5DB /* OCHamcrest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrest.framework; path = External/OCHamcrest.framework; sourceTree = "<group>"; };
6BD2B6E116AC031B0066C5DB /* OCHamcrest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrest.framework; path = External/OCHamcrest.framework; sourceTree = "<group>"; };
B594F87D174DF32700BF5DC5 /* TyphoonParameterInjectedByRawValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonParameterInjectedByRawValue.h; sourceTree = "<group>"; };
B594F87E174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonParameterInjectedByRawValue.m; sourceTree = "<group>"; };
BA798012692BC6CFD0CCB60F /* TyphoonInitializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonInitializer.h; sourceTree = "<group>"; };
BA79801A7ED2DD0708D6AF5F /* TyphoonTypeDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonTypeDescriptor.m; sourceTree = "<group>"; };
BA79801AE4DCFB941CCC29CF /* TyphoonDefinitionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonDefinitionTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -791,6 +795,8 @@
BA79832904B8D31EAB17C3CE /* TyphoonParameterInjectedByReference.m */,
BA79866B01F50CC47F6507CE /* TyphoonParameterInjectedByValue.h */,
BA7987099DAD3FC6A242E863 /* TyphoonParameterInjectedByValue.m */,
B594F87D174DF32700BF5DC5 /* TyphoonParameterInjectedByRawValue.h */,
B594F87E174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m */,
);
path = Initializer;
sourceTree = "<group>";
Expand Down Expand Up @@ -1047,6 +1053,7 @@
BA7982E1BDA4C7924D7285BB /* TyphoonPropertyInjectedAsCollectionTests.m in Sources */,
1D7493181746216900EAB208 /* MiddleAgesAssemblyOverride.m in Sources */,
1D74931C17462B8300EAB208 /* TyphoonBlockComponentFactoryOverrideTests.m in Sources */,
B594F87F174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1087,6 +1094,7 @@
BA798917A7860D9B8DC321BE /* TyphoonPropertyInjectedAsCollection.m in Sources */,
BA798A4C71CEC4CDB76D64B1 /* TyphoonByReferenceCollectionValue.m in Sources */,
BA798FC40F89DECD91733E69 /* TyphoonTypeConvertedCollectionValue.m in Sources */,
B594F880174DF32E00BF5DC5 /* TyphoonParameterInjectedByRawValue.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 16c9b08

Please sign in to comment.