Skip to content

Commit

Permalink
Add convenience methods to assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
jblues committed Nov 10, 2015
1 parent fd71d88 commit d61a30b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .idea/Typhoon.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions Source/Factory/Assembly/TyphoonAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ AnalyticsService* service = [assembly analyticsService];
* - Allows the use of IDE features like refactoring and code completion.
*
*/
@interface TyphoonAssembly : NSObject<TyphoonComponentFactory>
@interface TyphoonAssembly : NSObject <TyphoonComponentFactory>

+ (instancetype)assembly;

Expand All @@ -60,13 +60,33 @@ 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.
*
* @param assemblies The explicit types to be used for collaborating assemblies. For example if this assembly
* 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
20 changes: 19 additions & 1 deletion Source/Factory/Assembly/TyphoonAssembly.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "OCLogTemplate.h"
#import "TyphoonBlockComponentFactory.h"
#import "TyphoonCollaboratingAssembliesCollector.h"
#import "TyphoonConfigPostProcessor.h"

static NSMutableSet *reservedSelectorsAsStrings;

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -278,11 +291,16 @@ - (instancetype)activateWithCollaboratingAssemblies:(NSArray *)assemblies {
}



//-------------------------------------------------------------------------------------------
#pragma mark - Private Methods
//-------------------------------------------------------------------------------------------

- (void)attachProcessors:(NSArray *)postProcessors {
for (id<TyphoonDefinitionPostProcessor> processor in postProcessors) {
[self attachDefinitionPostProcessor:processor];
}
}

- (void)proxyCollaboratingAssembliesPriorToActivation {
TyphoonCollaboratingAssemblyPropertyEnumerator *enumerator = [[TyphoonCollaboratingAssemblyPropertyEnumerator alloc]
initWithAssembly:self];
Expand Down

0 comments on commit d61a30b

Please sign in to comment.