From d61a30b300f6a968db13c7e95ea6bb3e0588e543 Mon Sep 17 00:00:00 2001 From: jblues Date: Tue, 10 Nov 2015 17:40:43 +0800 Subject: [PATCH] Add convenience methods to assembly --- .idea/Typhoon.iml | 2 ++ Source/Factory/Assembly/TyphoonAssembly.h | 24 +++++++++++++++++++++-- Source/Factory/Assembly/TyphoonAssembly.m | 20 ++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.idea/Typhoon.iml b/.idea/Typhoon.iml index f120bbd74..f671fed29 100644 --- a/.idea/Typhoon.iml +++ b/.idea/Typhoon.iml @@ -141,6 +141,8 @@ + + diff --git a/Source/Factory/Assembly/TyphoonAssembly.h b/Source/Factory/Assembly/TyphoonAssembly.h index ad48433d5..52545a666 100644 --- a/Source/Factory/Assembly/TyphoonAssembly.h +++ b/Source/Factory/Assembly/TyphoonAssembly.h @@ -41,7 +41,7 @@ AnalyticsService* service = [assembly analyticsService]; * - Allows the use of IDE features like refactoring and code completion. * */ -@interface TyphoonAssembly : NSObject +@interface TyphoonAssembly : NSObject + (instancetype)assembly; @@ -60,6 +60,24 @@ AnalyticsService* service = [assembly analyticsService]; */ - (instancetype)activate; + +/** + * Activates the assembly, attaching the specified config resource name from the application bundle. + * + * This method is a convenience for: +@code + +TyphoonConfigPostProcessor *processor = [TyphoonConfigPostProcessor processor]; +[processor useResourceWithName:@"Config_production.plist"]; +[self attachPostProcessor:processor]; +[self activate]; + +@endcode + * + */ +- (instancetype)activateWithConfigResourceName:(NSString *)resourceName; + + /** * Activates the assembly, explicitly setting the types for collaborating assemblies. * @@ -67,6 +85,8 @@ AnalyticsService* service = [assembly analyticsService]; * references another assembly of type NetworkProvider, specifying a subclass TestNetworkProvider will override * the base type. If collaborating assemblies are backed by a protocol, they must be specified explicitly. */ -- (instancetype)activateWithCollaboratingAssemblies:(NSArray*)assemblies; +- (instancetype)activateWithCollaboratingAssemblies:(NSArray *)assemblies; + +- (instancetype)activateWithCollaboratingAssemblies:(NSArray *)assemblies postProcessors:(NSArray *)postProcessors; @end diff --git a/Source/Factory/Assembly/TyphoonAssembly.m b/Source/Factory/Assembly/TyphoonAssembly.m index 8a667964a..d79ee8a23 100644 --- a/Source/Factory/Assembly/TyphoonAssembly.m +++ b/Source/Factory/Assembly/TyphoonAssembly.m @@ -25,6 +25,7 @@ #import "OCLogTemplate.h" #import "TyphoonBlockComponentFactory.h" #import "TyphoonCollaboratingAssembliesCollector.h" +#import "TyphoonConfigPostProcessor.h" static NSMutableSet *reservedSelectorsAsStrings; @@ -243,7 +244,19 @@ - (instancetype)activate { return [self activateWithCollaboratingAssemblies:nil]; } +- (instancetype)activateWithConfigResourceName:(NSString *)resourceName { + TyphoonConfigPostProcessor *processor = [TyphoonConfigPostProcessor processor]; + [processor useResourceWithName:resourceName]; + return [self activateWithCollaboratingAssemblies:nil postProcessors:@[processor]]; +} + - (instancetype)activateWithCollaboratingAssemblies:(NSArray *)assemblies { + return [self activateWithCollaboratingAssemblies:assemblies postProcessors:nil]; +} + +- (instancetype)activateWithCollaboratingAssemblies:(NSArray *)assemblies postProcessors:(NSArray *)postProcessors { + [self attachProcessors:postProcessors]; + NSMutableSet *reconciledAssemblies = [NSMutableSet setWithArray:[@[self] arrayByAddingObjectsFromArray:assemblies]]; NSMutableSet *assembliesToRemove = [[NSMutableSet alloc] init]; @@ -278,11 +291,16 @@ - (instancetype)activateWithCollaboratingAssemblies:(NSArray *)assemblies { } - //------------------------------------------------------------------------------------------- #pragma mark - Private Methods //------------------------------------------------------------------------------------------- +- (void)attachProcessors:(NSArray *)postProcessors { + for (id processor in postProcessors) { + [self attachDefinitionPostProcessor:processor]; + } +} + - (void)proxyCollaboratingAssembliesPriorToActivation { TyphoonCollaboratingAssemblyPropertyEnumerator *enumerator = [[TyphoonCollaboratingAssemblyPropertyEnumerator alloc] initWithAssembly:self];