diff --git a/Source/Component/Initializer/TyphoonInitializer.h b/Source/Component/Initializer/TyphoonInitializer.h index 01f89bd9f..017fd433b 100644 --- a/Source/Component/Initializer/TyphoonInitializer.h +++ b/Source/Component/Initializer/TyphoonInitializer.h @@ -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 \ No newline at end of file diff --git a/Source/Component/Initializer/TyphoonInitializer.m b/Source/Component/Initializer/TyphoonInitializer.m index 229f8d795..d95e7b9f6 100644 --- a/Source/Component/Initializer/TyphoonInitializer.m +++ b/Source/Component/Initializer/TyphoonInitializer.m @@ -15,6 +15,7 @@ #import "TyphoonParameterInjectedByReference.h" #import "NSObject+TyphoonIntrospectionUtils.h" #import "TyphoonParameterInjectedByValue.h" +#import "TyphoonParameterInjectedByRawValue.h" #import "TyphoonDefinition.h" @@ -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 diff --git a/Source/Component/Initializer/TyphoonInjectedParameter.h b/Source/Component/Initializer/TyphoonInjectedParameter.h index b12020b6f..5853b817f 100644 --- a/Source/Component/Initializer/TyphoonInjectedParameter.h +++ b/Source/Component/Initializer/TyphoonInjectedParameter.h @@ -17,7 +17,8 @@ typedef enum { TyphoonParameterInjectedByReferenceType, - TyphoonParameterInjectedByValueType + TyphoonParameterInjectedByValueType, + TyphoonParameterInjectedByRawValueType } TyphoonParameterInjectionType; @protocol TyphoonInjectedParameter diff --git a/Source/Component/Initializer/TyphoonParameterInjectedByRawValue.h b/Source/Component/Initializer/TyphoonParameterInjectedByRawValue.h new file mode 100644 index 000000000..c539dee32 --- /dev/null +++ b/Source/Component/Initializer/TyphoonParameterInjectedByRawValue.h @@ -0,0 +1,21 @@ +// +// TyphoonParameterInjectedByRowValue.h +// Typhoon +// +// Created by Иван Ушаков on 23.05.13. +// Copyright (c) 2013 Jasper Blues. All rights reserved. +// + +#import +#import "TyphoonInjectedParameter.h" + +@interface TyphoonParameterInjectedByRawValue : NSObject + +@property(nonatomic, readonly) NSUInteger index; +@property(nonatomic, readonly) TyphoonParameterInjectionType type; +@property(nonatomic, strong, readonly) id value; + +- (id)initWithParameterIndex:(NSUInteger)index value:(id)value; + + +@end diff --git a/Source/Component/Initializer/TyphoonParameterInjectedByRawValue.m b/Source/Component/Initializer/TyphoonParameterInjectedByRawValue.m new file mode 100644 index 000000000..368d71447 --- /dev/null +++ b/Source/Component/Initializer/TyphoonParameterInjectedByRawValue.m @@ -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 diff --git a/Source/Factory/InstanceBuilder/TyphoonComponentFactory+InstanceBuilder.m b/Source/Factory/InstanceBuilder/TyphoonComponentFactory+InstanceBuilder.m index 3b8fd5464..4f7c815d8 100644 --- a/Source/Factory/InstanceBuilder/TyphoonComponentFactory+InstanceBuilder.m +++ b/Source/Factory/InstanceBuilder/TyphoonComponentFactory+InstanceBuilder.m @@ -28,6 +28,7 @@ #import "TyphoonCollectionValue.h" #import "TyphoonByReferenceCollectionValue.h" #import "TyphoonTypeConvertedCollectionValue.h" +#import "TyphoonParameterInjectedByRawValue.h" @implementation TyphoonComponentFactory (InstanceBuilder) @@ -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 returnValue = nil; diff --git a/Tests/Factory/Block/MiddleAgesAssemblyOverride.m b/Tests/Factory/Block/MiddleAgesAssemblyOverride.m index d6f7c4e5c..a112bf3b2 100644 --- a/Tests/Factory/Block/MiddleAgesAssemblyOverride.m +++ b/Tests/Factory/Block/MiddleAgesAssemblyOverride.m @@ -8,6 +8,7 @@ #import "MiddleAgesAssemblyOverride.h" #import "TyphoonDefinition.h" +#import "TyphoonInitializer.h" #import "Knight.h" @@ -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 diff --git a/Tests/Factory/Block/TyphoonBlockComponentFactoryOverrideTests.m b/Tests/Factory/Block/TyphoonBlockComponentFactoryOverrideTests.m index 80475bdf2..60db9e074 100644 --- a/Tests/Factory/Block/TyphoonBlockComponentFactoryOverrideTests.m +++ b/Tests/Factory/Block/TyphoonBlockComponentFactoryOverrideTests.m @@ -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 diff --git a/Typhoon.xcodeproj/project.pbxproj b/Typhoon.xcodeproj/project.pbxproj index 0b6e1c8c5..03418fcc2 100644 --- a/Typhoon.xcodeproj/project.pbxproj +++ b/Typhoon.xcodeproj/project.pbxproj @@ -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 */; }; @@ -216,6 +218,8 @@ 6B7CE44416C74919002E0107 /* OCMockito.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMockito.framework; path = External/OCMockito.framework; sourceTree = ""; }; 6BD2B6DD16AC02DD0066C5DB /* OCHamcrest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrest.framework; path = External/OCHamcrest.framework; sourceTree = ""; }; 6BD2B6E116AC031B0066C5DB /* OCHamcrest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCHamcrest.framework; path = External/OCHamcrest.framework; sourceTree = ""; }; + B594F87D174DF32700BF5DC5 /* TyphoonParameterInjectedByRawValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonParameterInjectedByRawValue.h; sourceTree = ""; }; + B594F87E174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonParameterInjectedByRawValue.m; sourceTree = ""; }; BA798012692BC6CFD0CCB60F /* TyphoonInitializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonInitializer.h; sourceTree = ""; }; BA79801A7ED2DD0708D6AF5F /* TyphoonTypeDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonTypeDescriptor.m; sourceTree = ""; }; BA79801AE4DCFB941CCC29CF /* TyphoonDefinitionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonDefinitionTests.m; sourceTree = ""; }; @@ -791,6 +795,8 @@ BA79832904B8D31EAB17C3CE /* TyphoonParameterInjectedByReference.m */, BA79866B01F50CC47F6507CE /* TyphoonParameterInjectedByValue.h */, BA7987099DAD3FC6A242E863 /* TyphoonParameterInjectedByValue.m */, + B594F87D174DF32700BF5DC5 /* TyphoonParameterInjectedByRawValue.h */, + B594F87E174DF32800BF5DC5 /* TyphoonParameterInjectedByRawValue.m */, ); path = Initializer; sourceTree = ""; @@ -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; }; @@ -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; };