Skip to content

Commit

Permalink
Do not throw exception on not binded protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxRandom committed Feb 23, 2018
1 parent 7fe85d0 commit d281d0a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
26 changes: 20 additions & 6 deletions CRDI.xcodeproj/xcshareddata/xcschemes/CRDI.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,62 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EA5B9E3917E735C1002A0D81"
BuildableName = "CRDISpecs.octest"
BuildableName = "CRDISpecs.xctest"
BlueprintName = "CRDISpecs"
ReferencedContainer = "container:CRDI.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EA5B9E3917E735C1002A0D81"
BuildableName = "CRDISpecs.octest"
BuildableName = "CRDISpecs.xctest"
BlueprintName = "CRDISpecs"
ReferencedContainer = "container:CRDI.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EA16E22A17E7358100F90D98"
BuildableName = "libCRDI.a"
BlueprintName = "CRDI"
ReferencedContainer = "container:CRDI.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
Expand Down
26 changes: 20 additions & 6 deletions CRDI.xcodeproj/xcshareddata/xcschemes/CRDISpecs.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,62 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EA5B9E3917E735C1002A0D81"
BuildableName = "CRDISpecs.octest"
BuildableName = "CRDISpecs.xctest"
BlueprintName = "CRDISpecs"
ReferencedContainer = "container:CRDI.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EA5B9E3917E735C1002A0D81"
BuildableName = "CRDISpecs.octest"
BuildableName = "CRDISpecs.xctest"
BlueprintName = "CRDISpecs"
ReferencedContainer = "container:CRDI.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EA16E22A17E7358100F90D98"
BuildableName = "libCRDI.a"
BlueprintName = "CRDI"
ReferencedContainer = "container:CRDI.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
Expand Down
26 changes: 7 additions & 19 deletions CRDI/Code/DIContainer/CRDIContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)addBuilder:(id <CRDIDependencyBuilder>)aBuilder forProtocol:(Protocol *)
NSParameterAssert(aBuilder);
NSParameterAssert(aProtocol);

NSString *protocolKey = [self stringFromPorotocol:aProtocol];
NSString *protocolKey = [self stringFromProtocol:aProtocol];

self.configurationDictionary[protocolKey] = aBuilder;
}
Expand All @@ -107,7 +107,7 @@ - (void)addClassBuilder:(id <CRDIDependencyBuilder>)aBuilder forProtocol:(Protoc
NSParameterAssert(aBuilder);
NSParameterAssert(aProtocol);

NSString *protocolKey = [self stringFromPorotocol:aProtocol];
NSString *protocolKey = [self stringFromProtocol:aProtocol];

NSMutableArray *buildersArray = self.configurationDictionary[protocolKey];

Expand All @@ -124,9 +124,7 @@ - (void)addClassBuilder:(id <CRDIDependencyBuilder>)aBuilder forProtocol:(Protoc
{
NSParameterAssert(aProtocol);

[self checkIfProtocolNotBinded:aProtocol];

NSString *protocolKey = [self stringFromPorotocol:aProtocol];
NSString *protocolKey = [self stringFromProtocol:aProtocol];

id builderWrapper = self.configurationDictionary[protocolKey];

Expand All @@ -145,8 +143,6 @@ - (NSArray *)buidersForProtocol:(Protocol *)aProtocol
{
NSParameterAssert(aProtocol);

[self checkIfProtocolNotBinded:aProtocol];

NSString *protocolKey = NSStringFromProtocol(aProtocol);

NSArray *buildersArray = self.configurationDictionary[protocolKey];
Expand Down Expand Up @@ -198,26 +194,18 @@ - (void)checkIfBuilderForClass:(Class)aClass alreadyExistsForProtocol:(Protocol

- (void)checkIfProtocolAlreadyBinded:(Protocol *)aProtocol
{
if ([self protocolIsBinded:aProtocol]) {
@throw [CRDIException exceptionWithReason:[NSString stringWithFormat:@"Builder for protocol %@ already binded", [self stringFromPorotocol:aProtocol]]];
}
}

- (void)checkIfProtocolNotBinded:(Protocol *)aProtocol
{
if (![self protocolIsBinded:aProtocol]) {
@throw [CRDIException exceptionWithReason:[NSString stringWithFormat:@"Builder for protocol %@ is not binded", [self stringFromPorotocol:aProtocol]]];
}
NSString *messageIfAlreadyBinded = [NSString stringWithFormat:@"Builder for protocol %@ already binded", [self stringFromProtocol:aProtocol]];
NSAssert(![self protocolIsBinded:aProtocol], messageIfAlreadyBinded);
}

- (BOOL)protocolIsBinded:(Protocol *)aProtocol
{
NSString *protocolKey = [self stringFromPorotocol:aProtocol];
NSString *protocolKey = [self stringFromProtocol:aProtocol];

return self.configurationDictionary[protocolKey] != nil;
}

- (NSString *)stringFromPorotocol:(Protocol *)aProtocol
- (NSString *)stringFromProtocol:(Protocol *)aProtocol
{
return NSStringFromProtocol(aProtocol);
}
Expand Down

0 comments on commit d281d0a

Please sign in to comment.