Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
rsobik committed Aug 23, 2013
1 parent 1b637b3 commit 786877b
Show file tree
Hide file tree
Showing 10 changed files with 659 additions and 0 deletions.
426 changes: 426 additions & 0 deletions Racoon.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions Racoon/RCOFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// RCOFactory.h
// Racoon
//
// Created by Raphael Sobik on 23.08.13.
// Copyright (c) 2013 Raphael Sobik. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface RCOFactory : NSObject

- (void)configureWithAssembly:(id)assembly;
- (id)componentForType:(Class)klass;

@end
71 changes: 71 additions & 0 deletions Racoon/RCOFactory.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// RCOFactory.m
// Racoon
//
// Created by Raphael Sobik on 23.08.13.
// Copyright (c) 2013 Raphael Sobik. All rights reserved.
//

#import "RCOFactory.h"

#import "RCOSelectorCache.h"

@interface RCOFactory ()

@property (nonatomic, strong) id assembly;
@property (nonatomic, strong) RCOSelectorCache *selectorCache;

@end

@implementation RCOFactory

#pragma mark - NSObject

- (id)init
{
self = [super init];
if (self) {
_selectorCache = [[RCOSelectorCache alloc] init];
}

return self;
}

#pragma mark - RCOFactory

- (void)configureWithAssembly:(id)assembly
{
self.assembly = assembly;
}

- (id)componentForType:(Class)klass
{
SEL selector = [self selectorForType:klass];

if ([(NSObject *)self.assembly respondsToSelector:selector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
return [(NSObject *)self.assembly performSelector:selector withObject:nil];
#pragma clang diagnostic pop
} else {
[NSException raise:NSInvalidArgumentException format:@"The assembly %@ is not able to provide a component of type %@", self.assembly, klass];
return nil;
}
}

#pragma mark - RCOFactory

- (SEL)selectorForType:(Class)klass
{
SEL selector = [self.selectorCache selectorForType:klass];
if (selector == RCOSelectorCacheSelectorNotFound) {
NSString *selectorString = [NSString stringWithFormat:@"componentForType%@", NSStringFromClass(klass)];
selector = NSSelectorFromString(selectorString);

[self.selectorCache setSelector:selector forType:klass];
}

return selector;
}

@end
19 changes: 19 additions & 0 deletions Racoon/RCOSelectorCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RCOSelectorCache.h
// Racoon
//
// Created by Raphael Sobik on 23.08.13.
// Copyright (c) 2013 Raphael Sobik. All rights reserved.
//

#import <Foundation/Foundation.h>

extern const SEL RCOSelectorCacheSelectorNotFound;

@interface RCOSelectorCache : NSObject

- (SEL)selectorForType:(Class)key;
- (void)setSelector:(SEL)selector forType:(Class)key;
- (void)evictCachedSelectors;

@end
49 changes: 49 additions & 0 deletions Racoon/RCOSelectorCache.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// RCOSelectorCache.m
// Racoon
//
// Created by Raphael Sobik on 23.08.13.
// Copyright (c) 2013 Raphael Sobik. All rights reserved.
//

#import "RCOSelectorCache.h"

const SEL RCOSelectorCacheSelectorNotFound = 0;

@implementation RCOSelectorCache {
CFMutableDictionaryRef dictionary;
}

- (id)init
{
self = [super init];
if (self) {
dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL);
}

return self;
}

- (void)dealloc
{
if (dictionary) {
CFRelease(dictionary);
}
}

- (SEL)selectorForType:(Class)key
{
return (SEL)CFDictionaryGetValue(dictionary, (__bridge const void *)(key));
}

- (void)setSelector:(SEL)selector forType:(Class)key
{
CFDictionarySetValue(dictionary, (__bridge const void *)(key), selector);
}

- (void)evictCachedSelectors
{
CFDictionaryRemoveAllValues(dictionary);
}

@end
9 changes: 9 additions & 0 deletions Racoon/Racoon-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif
11 changes: 11 additions & 0 deletions Racoon/Racoon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Racoon.h
// Racoon
//
// Created by Raphael Sobik on 23.08.13.
// Copyright (c) 2013 Raphael Sobik. All rights reserved.
//

#import <Foundation/Foundation.h>

#import <Racoon/RCOFactory.h>
22 changes: 22 additions & 0 deletions RacoonTests/RacoonTests-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>org.sobik.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
34 changes: 34 additions & 0 deletions RacoonTests/RacoonTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// RacoonTests.m
// RacoonTests
//
// Created by Raphael Sobik on 23.08.13.
// Copyright (c) 2013 Raphael Sobik. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface RacoonTests : XCTestCase

@end

@implementation RacoonTests

- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testExample
{
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}

@end
2 changes: 2 additions & 0 deletions RacoonTests/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

0 comments on commit 786877b

Please sign in to comment.