Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Succumbing to 4 soft tabs for indentation

  • Loading branch information...
commit 390fad0c0a39ef9b6f2dfe70386a87978b1213a3 1 parent 2a5cdef
@dewind dewind authored
View
6 Objection.xcodeproj/project.pbxproj
@@ -965,7 +965,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0420;
+ LastUpgradeCheck = 0430;
};
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "Objection" */;
compatibilityVersion = "Xcode 3.2";
@@ -1338,6 +1338,7 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_THUMB_SUPPORT = NO;
INSTALL_PATH = /usr/local/lib;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
ONLY_ACTIVE_ARCH = NO;
@@ -1361,6 +1362,7 @@
"\"$(SRCROOT)/..\"",
);
GCC_MODEL_TUNING = G5;
+ GCC_THUMB_SUPPORT = NO;
INSTALL_PATH = /usr/local/lib;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
ONLY_ACTIVE_ARCH = NO;
@@ -1404,6 +1406,7 @@
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_THUMB_SUPPORT = NO;
PRODUCT_NAME = "Objection-iOS";
SDKROOT = iphoneos;
};
@@ -1419,6 +1422,7 @@
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
PRODUCT_NAME = "Objection-iOS";
SDKROOT = iphoneos;
View
2  Source/JSObjectFactory.h
@@ -3,7 +3,7 @@
@class JSObjectionInjector;
@interface JSObjectFactory : NSObject {
- JSObjectionInjector *_injector;
+ JSObjectionInjector *_injector;
}
@property (nonatomic, readonly, retain) JSObjectionInjector *injector;
View
13 Source/JSObjectFactory.m
@@ -5,14 +5,13 @@ @implementation JSObjectFactory
@synthesize injector = _injector;
- (id)initWithInjector:(JSObjectionInjector *)injector {
- if ((self = [super init])) {
- _injector = injector;
- }
- return self;
+ if ((self = [super init])) {
+ _injector = injector;
+ }
+ return self;
}
-- (id)getObject:(id)classOrProtocol
-{
- return [self.injector getObject:classOrProtocol];
+- (id)getObject:(id)classOrProtocol {
+ return [self.injector getObject:classOrProtocol];
}
@end
View
4 Source/JSObjection.h
@@ -10,7 +10,7 @@
+ (JSObjectionInjector *)createInjector:(JSObjectionModule *)module;
+ (JSObjectionInjector *)createInjector;
+ (void)registerClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)lifeCycle;
-+ (void)setGlobalInjector:(JSObjectionInjector *)anInjector;
-+ (JSObjectionInjector *)globalInjector;
++ (void)setDefaultInjector:(JSObjectionInjector *)anInjector;
++ (JSObjectionInjector *)defaultInjector;
+ (void)reset;
@end
View
143 Source/JSObjection.m
@@ -9,95 +9,88 @@
@implementation JSObjection
+ (JSObjectionInjector *)createInjector:(JSObjectionModule *)module {
- pthread_mutex_lock(&gObjectionMutex);
- @try {
- return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext andModule:module] autorelease];
- }
- @finally {
- pthread_mutex_unlock(&gObjectionMutex);
- }
-
- return nil;
+ pthread_mutex_lock(&gObjectionMutex);
+ @try {
+ return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext andModule:module] autorelease];
+ }
+ @finally {
+ pthread_mutex_unlock(&gObjectionMutex);
+ }
+
+ return nil;
}
-+ (JSObjectionInjector *) createInjectorWithModules:(JSObjectionModule *)first, ...
-{
- pthread_mutex_lock(&gObjectionMutex);
- @try {
- va_list va_modules;
- NSMutableArray *modules = [NSMutableArray arrayWithObject:first];
- va_start(va_modules, first);
-
- JSObjectionModule *module;
- while ((module = va_arg( va_modules, JSObjectionModule *) )) {
- [modules addObject:module];
++ (JSObjectionInjector *)createInjectorWithModules:(JSObjectionModule *)first, ... {
+ pthread_mutex_lock(&gObjectionMutex);
+ @try {
+ va_list va_modules;
+ NSMutableArray *modules = [NSMutableArray arrayWithObject:first];
+ va_start(va_modules, first);
+
+ JSObjectionModule *module;
+ while ((module = va_arg( va_modules, JSObjectionModule *) )) {
+ [modules addObject:module];
+ }
+
+ va_end(va_modules);
+ return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext andModules:modules] autorelease];
}
-
- va_end(va_modules);
- return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext andModules:modules] autorelease];
- }
- @finally {
- pthread_mutex_unlock(&gObjectionMutex);
- }
-
- return nil;
+ @finally {
+ pthread_mutex_unlock(&gObjectionMutex);
+ }
+
+ return nil;
}
-+ (JSObjectionInjector *) createInjector
-{
- pthread_mutex_lock(&gObjectionMutex);
- @try {
- return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext] autorelease];
- }
- @finally {
- pthread_mutex_unlock(&gObjectionMutex);
- }
-
- return nil;
++ (JSObjectionInjector *)createInjector {
+ pthread_mutex_lock(&gObjectionMutex);
+ @try {
+ return [[[JSObjectionInjector alloc] initWithContext:gObjectionContext] autorelease];
+ }
+ @finally {
+ pthread_mutex_unlock(&gObjectionMutex);
+ }
+
+ return nil;
}
-+ (void)initialize
-{
- if (self == [JSObjection class]) {
- gObjectionContext = [[NSMutableDictionary alloc] init];
- pthread_mutexattr_t mutexattr;
- pthread_mutexattr_init(&mutexattr);
- pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&gObjectionMutex, &mutexattr);
- pthread_mutexattr_destroy(&mutexattr);
- }
++ (void)initialize {
+ if (self == [JSObjection class]) {
+ gObjectionContext = [[NSMutableDictionary alloc] init];
+ pthread_mutexattr_t mutexattr;
+ pthread_mutexattr_init(&mutexattr);
+ pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&gObjectionMutex, &mutexattr);
+ pthread_mutexattr_destroy(&mutexattr);
+ }
}
-+ (void) registerClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)lifeCycle
-{
- pthread_mutex_lock(&gObjectionMutex);
- if (lifeCycle != JSObjectionInstantiationRuleSingleton && lifeCycle != JSObjectionInstantiationRuleNormal) {
- @throw [NSException exceptionWithName:@"JSObjectionInjectorException" reason:@"Invalid Instantiation Rule" userInfo:nil];
- }
-
- if (theClass && [gObjectionContext objectForKey:NSStringFromClass(theClass)] == nil) {
- [gObjectionContext setObject:[JSObjectionInjectorEntry entryWithClass:theClass lifeCycle:lifeCycle] forKey:NSStringFromClass(theClass)];
- }
- pthread_mutex_unlock(&gObjectionMutex);
++ (void) registerClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)lifeCycle {
+ pthread_mutex_lock(&gObjectionMutex);
+ if (lifeCycle != JSObjectionInstantiationRuleSingleton && lifeCycle != JSObjectionInstantiationRuleNormal) {
+ @throw [NSException exceptionWithName:@"JSObjectionInjectorException" reason:@"Invalid Instantiation Rule" userInfo:nil];
+ }
+
+ if (theClass && [gObjectionContext objectForKey:NSStringFromClass(theClass)] == nil) {
+ [gObjectionContext setObject:[JSObjectionInjectorEntry entryWithClass:theClass lifeCycle:lifeCycle] forKey:NSStringFromClass(theClass)];
+ }
+ pthread_mutex_unlock(&gObjectionMutex);
}
-+ (void) reset
-{
- pthread_mutex_lock(&gObjectionMutex);
- [gObjectionContext removeAllObjects];
- pthread_mutex_unlock(&gObjectionMutex);
++ (void) reset {
+ pthread_mutex_lock(&gObjectionMutex);
+ [gObjectionContext removeAllObjects];
+ pthread_mutex_unlock(&gObjectionMutex);
}
-+ (void)setGlobalInjector:(JSObjectionInjector *)anInjector
-{
- if (gGlobalInjector != anInjector) {
- [gGlobalInjector release];
- gGlobalInjector = [anInjector retain];
- }
++ (void)setDefaultInjector:(JSObjectionInjector *)anInjector {
+ if (gGlobalInjector != anInjector) {
+ [gGlobalInjector release];
+ gGlobalInjector = [anInjector retain];
+ }
}
-+ (JSObjectionInjector *) globalInjector
-{
- return [[gGlobalInjector retain] autorelease];
++ (JSObjectionInjector *) defaultInjector {
+ return [[gGlobalInjector retain] autorelease];
}
@end
View
2  Source/JSObjectionBindingEntry.h
@@ -2,7 +2,7 @@
#import "JSObjectionEntry.h"
@interface JSObjectionBindingEntry : JSObjectionEntry {
- id _instance;
+ id _instance;
}
- (id)initWithObject:(id)theObject;
View
28 Source/JSObjectionBindingEntry.m
@@ -3,28 +3,24 @@
@implementation JSObjectionBindingEntry
-- (id)initWithObject:(id)theObject
-{
- if ((self = [super init])) {
- _instance = [theObject retain];
- }
- return self;
+- (id)initWithObject:(id)theObject {
+ if ((self = [super init])) {
+ _instance = [theObject retain];
+ }
+ return self;
}
-- (id)extractObject
-{
- return _instance;
+- (id)extractObject {
+ return _instance;
}
-- (JSObjectionInstantiationRule)lifeCycle
-{
- return JSObjectionInstantiationRuleSingleton;
+- (JSObjectionInstantiationRule)lifeCycle {
+ return JSObjectionInstantiationRuleSingleton;
}
-- (void)dealloc
-{
- [_instance release]; _instance = nil;
- [super dealloc];
+- (void)dealloc {
+ [_instance release]; _instance = nil;
+ [super dealloc];
}
@end
View
8 Source/JSObjectionEntry.h
@@ -1,9 +1,9 @@
#import <Foundation/Foundation.h>
typedef enum {
- JSObjectionInstantiationRuleNone = -1,
- JSObjectionInstantiationRuleNormal,
- JSObjectionInstantiationRuleSingleton
+ JSObjectionInstantiationRuleNone = -1,
+ JSObjectionInstantiationRuleNormal,
+ JSObjectionInstantiationRuleSingleton
} JSObjectionInstantiationRule;
@@ -18,7 +18,7 @@ typedef enum {
@interface JSObjectionEntry : NSObject<JSObjectionEntry>
{
- id _injector;
+ id _injector;
}
@end
View
15 Source/JSObjectionEntry.m
@@ -4,18 +4,15 @@ @implementation JSObjectionEntry
@synthesize injector = _injector;
@dynamic lifeCycle;
-- (id)extractObject
-{
- return nil;
+- (id)extractObject {
+ return nil;
}
-+ (id)entryWithEntry:(JSObjectionEntry *)entry
-{
- return [[entry retain] autorelease];
++ (id)entryWithEntry:(JSObjectionEntry *)entry {
+ return [[entry retain] autorelease];
}
-- (JSObjectionInstantiationRule)lifeCycle
-{
- return JSObjectionInstantiationRuleNone;
+- (JSObjectionInstantiationRule)lifeCycle {
+ return JSObjectionInstantiationRuleNone;
}
@end
View
6 Source/JSObjectionInjector.h
@@ -2,9 +2,9 @@
#import "JSObjectionModule.h"
@interface JSObjectionInjector : NSObject {
- NSDictionary *_globalContext;
- NSMutableDictionary *_context;
- NSSet *_eagerSingletons;
+ NSDictionary *_globalContext;
+ NSMutableDictionary *_context;
+ NSSet *_eagerSingletons;
}
- (id)initWithContext:(NSDictionary *)theGlobalContext;
View
187 Source/JSObjectionInjector.m
@@ -7,30 +7,26 @@
@interface __JSObjectionInjectorDefaultModule : JSObjectionModule
{
- JSObjectionInjector *_injector;
+ JSObjectionInjector *_injector;
}
@end
@implementation __JSObjectionInjectorDefaultModule
-- (id)initWithInjector:(JSObjectionInjector *)injector
-{
- if ((self = [super init])) {
- _injector = [injector retain];
- }
- return self;
+- (id)initWithInjector:(JSObjectionInjector *)injector {
+ if ((self = [super init])) {
+ _injector = [injector retain];
+ }
+ return self;
}
-- (void)configure
-{
- [self bind:[[[JSObjectFactory alloc] initWithInjector:_injector] autorelease]
- toClass:[JSObjectFactory class]];
+- (void)configure {
+ [self bind:[[[JSObjectFactory alloc] initWithInjector:_injector] autorelease] toClass:[JSObjectFactory class]];
}
-- (void)dealloc
-{
- [_injector release];
- [super dealloc];
+- (void)dealloc {
+ [_injector release];
+ [super dealloc];
}
@end
@@ -42,116 +38,107 @@ - (void)configureModule:(JSObjectionModule *)module;
@implementation JSObjectionInjector
-- (id)initWithContext:(NSDictionary *)theGlobalContext
-{
- if ((self = [super init])) {
- _globalContext = [theGlobalContext retain];
- _context = [[NSMutableDictionary alloc] init];
- [self configureDefaultModule];
- [self initializeEagerSingletons];
- }
-
- return self;
+- (id)initWithContext:(NSDictionary *)theGlobalContext {
+ if ((self = [super init])) {
+ _globalContext = [theGlobalContext retain];
+ _context = [[NSMutableDictionary alloc] init];
+ [self configureDefaultModule];
+ [self initializeEagerSingletons];
+ }
+
+ return self;
}
-- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule
-{
- if ((self = [self initWithContext:theGlobalContext])) {
- [self configureModule:theModule];
- [self initializeEagerSingletons];
- }
- return self;
+- (id)initWithContext:(NSDictionary *)theGlobalContext andModule:(JSObjectionModule *)theModule {
+ if ((self = [self initWithContext:theGlobalContext])) {
+ [self configureModule:theModule];
+ [self initializeEagerSingletons];
+ }
+ return self;
}
-- (id)initWithContext:(NSDictionary *)theGlobalContext andModules:(NSArray *)modules
-{
- if ((self = [self initWithContext:theGlobalContext])) {
- for (JSObjectionModule *module in modules) {
- [self configureModule:module];
+- (id)initWithContext:(NSDictionary *)theGlobalContext andModules:(NSArray *)modules {
+ if ((self = [self initWithContext:theGlobalContext])) {
+ for (JSObjectionModule *module in modules) {
+ [self configureModule:module];
+ }
+ [self initializeEagerSingletons];
}
- [self initializeEagerSingletons];
- }
- return self;
+ return self;
}
-- (id)getObject:(id)classOrProtocol
-{
- @synchronized(self) {
-
- if (!classOrProtocol) {
- return nil;
- }
-
- NSString *key = nil;
- if (class_isMetaClass(object_getClass(classOrProtocol))) {
- key = NSStringFromClass(classOrProtocol);
- } else {
- key = [NSString stringWithFormat:@"<%@>", NSStringFromProtocol(classOrProtocol)];
- }
+- (id)getObject:(id)classOrProtocol {
+ @synchronized(self) {
+ if (!classOrProtocol) {
+ return nil;
+ }
+
+ NSString *key = nil;
+ if (class_isMetaClass(object_getClass(classOrProtocol))) {
+ key = NSStringFromClass(classOrProtocol);
+ } else {
+ key = [NSString stringWithFormat:@"<%@>", NSStringFromProtocol(classOrProtocol)];
+ }
+
-
- id<JSObjectionEntry> injectorEntry = [_context objectForKey:key];
- injectorEntry.injector = self;
-
- if (!injectorEntry) {
- id<JSObjectionEntry> entry = [_globalContext objectForKey:key];
- if (entry) {
- injectorEntry = [[entry class] entryWithEntry:entry];
+ id<JSObjectionEntry> injectorEntry = [_context objectForKey:key];
injectorEntry.injector = self;
- [_context setObject:injectorEntry forKey:key];
- }
+
+ if (!injectorEntry) {
+ id<JSObjectionEntry> entry = [_globalContext objectForKey:key];
+ if (entry) {
+ injectorEntry = [[entry class] entryWithEntry:entry];
+ injectorEntry.injector = self;
+ [_context setObject:injectorEntry forKey:key];
+ }
+ }
+
+ if (classOrProtocol && injectorEntry) {
+ return [injectorEntry extractObject];
+ }
+
+ return nil;
}
-
- if (classOrProtocol && injectorEntry) {
- return [injectorEntry extractObject];
- }
-
- return nil;
- }
-
- return nil;
+
+ return nil;
}
#pragma mark - Private
-- (void)initializeEagerSingletons
-{
- for (NSString *eagerSingletonKey in _eagerSingletons) {
- id entry = [_globalContext objectForKey:eagerSingletonKey];
- if ([entry lifeCycle] == JSObjectionInstantiationRuleSingleton) {
- [self getObject:NSClassFromString(eagerSingletonKey)];
- } else {
- @throw [NSException exceptionWithName:@"JSObjectionException"
- reason:[NSString stringWithFormat:@"Unable to initialize eager singleton for the class '%@' because it was never registered as a singleton", eagerSingletonKey]
- userInfo:nil];
+- (void)initializeEagerSingletons {
+ for (NSString *eagerSingletonKey in _eagerSingletons) {
+ id entry = [_globalContext objectForKey:eagerSingletonKey];
+ if ([entry lifeCycle] == JSObjectionInstantiationRuleSingleton) {
+ [self getObject:NSClassFromString(eagerSingletonKey)];
+ } else {
+ @throw [NSException exceptionWithName:@"JSObjectionException"
+ reason:[NSString stringWithFormat:@"Unable to initialize eager singleton for the class '%@' because it was never registered as a singleton", eagerSingletonKey]
+ userInfo:nil];
+ }
}
-
- }
}
-- (void)configureModule:(JSObjectionModule *)module
-{
- [module configure];
- NSSet *mergedSet = [module.eagerSingletons setByAddingObjectsFromSet:_eagerSingletons];
- [_eagerSingletons release];
- _eagerSingletons = [mergedSet retain];
- [_context addEntriesFromDictionary:module.bindings];
+- (void)configureModule:(JSObjectionModule *)module {
+ [module configure];
+ NSSet *mergedSet = [module.eagerSingletons setByAddingObjectsFromSet:_eagerSingletons];
+ [_eagerSingletons release];
+ _eagerSingletons = [mergedSet retain];
+ [_context addEntriesFromDictionary:module.bindings];
}
-- (void)configureDefaultModule
-{
- __JSObjectionInjectorDefaultModule *module = [[[__JSObjectionInjectorDefaultModule alloc] initWithInjector:self] autorelease];
- [self configureModule:module];
+- (void)configureDefaultModule {
+ __JSObjectionInjectorDefaultModule *module = [[[__JSObjectionInjectorDefaultModule alloc] initWithInjector:self] autorelease];
+ [self configureModule:module];
}
#pragma mark -
- (void)dealloc {
- [_globalContext release];
- [_context release];
- [_eagerSingletons release];
- [super dealloc];
+ [_globalContext release];
+ [_context release];
+ [_eagerSingletons release];
+ [super dealloc];
}
@end
View
4 Source/JSObjectionInjectorEntry.h
@@ -3,8 +3,8 @@
@interface JSObjectionInjectorEntry : JSObjectionEntry {
Class _classEntry;
- JSObjectionInstantiationRule _lifeCycle;
- id _storageCache;
+ JSObjectionInstantiationRule _lifeCycle;
+ id _storageCache;
}
@property (nonatomic, readonly) Class classEntry;
View
89 Source/JSObjectionInjectorEntry.m
@@ -52,60 +52,57 @@ - (void)notifyObjectThatItIsReady: (id) object
}
}
-- (id)buildObject
-{
- id objectUnderConstruction = [[[self.classEntry alloc] init] autorelease];
-
- if (self.lifeCycle != JSObjectionInstantiationRuleNormal) {
- _storageCache = [objectUnderConstruction retain];
- }
-
- if ([self.classEntry respondsToSelector:@selector(objectionRequires)]) {
- NSArray *properties = [self.classEntry performSelector:@selector(objectionRequires)];
- NSMutableDictionary *propertiesDictionary = [NSMutableDictionary dictionaryWithCapacity:properties.count];
-
- for (NSString *propertyName in properties) {
- objc_property_t property = JSObjectionUtils.propertyForClass(self.classEntry, propertyName);
- JSObjectionPropertyInfo propertyInfo = JSObjectionUtils.findClassOrProtocolForProperty(property);
- id desiredClassOrProtocol = propertyInfo.value;
- // Ensure that the class is initialized before attempting to retrieve it.
- // Using +load would force all registered classes to be initialized so we are
- // lazily initializing them.
- if (propertyInfo.type == JSObjectionTypeClass) {
- [desiredClassOrProtocol class];
- }
-
- id theObject = [self.injector getObject:desiredClassOrProtocol];
-
- if(theObject == nil && propertyInfo.type == JSObjectionTypeClass) {
- [JSObjection registerClass:desiredClassOrProtocol lifeCycle: JSObjectionInstantiationRuleNormal];
- theObject = [_injector getObject:desiredClassOrProtocol];
- } else if (!theObject) {
- @throw [NSException exceptionWithName:@"JSObjectionException"
- reason:[NSString stringWithFormat:@"Cannot find an instance that is bound to the protocol '%@' to assign to the property '%@'", NSStringFromProtocol(desiredClassOrProtocol), propertyName]
- userInfo:nil];
- }
-
- [propertiesDictionary setObject:theObject forKey:propertyName];
+- (id)buildObject {
+ id objectUnderConstruction = [[[self.classEntry alloc] init] autorelease];
+
+ if (self.lifeCycle != JSObjectionInstantiationRuleNormal) {
+ _storageCache = [objectUnderConstruction retain];
}
-
- [objectUnderConstruction setValuesForKeysWithDictionary:propertiesDictionary];
- }
- [self notifyObjectThatItIsReady: objectUnderConstruction];
- return objectUnderConstruction;
+ if ([self.classEntry respondsToSelector:@selector(objectionRequires)]) {
+ NSArray *properties = [self.classEntry performSelector:@selector(objectionRequires)];
+ NSMutableDictionary *propertiesDictionary = [NSMutableDictionary dictionaryWithCapacity:properties.count];
+
+ for (NSString *propertyName in properties) {
+ objc_property_t property = JSObjectionUtils.propertyForClass(self.classEntry, propertyName);
+ JSObjectionPropertyInfo propertyInfo = JSObjectionUtils.findClassOrProtocolForProperty(property);
+ id desiredClassOrProtocol = propertyInfo.value;
+ // Ensure that the class is initialized before attempting to retrieve it.
+ // Using +load would force all registered classes to be initialized so we are
+ // lazily initializing them.
+ if (propertyInfo.type == JSObjectionTypeClass) {
+ [desiredClassOrProtocol class];
+ }
+
+ id theObject = [self.injector getObject:desiredClassOrProtocol];
+
+ if(theObject == nil && propertyInfo.type == JSObjectionTypeClass) {
+ [JSObjection registerClass:desiredClassOrProtocol lifeCycle: JSObjectionInstantiationRuleNormal];
+ theObject = [_injector getObject:desiredClassOrProtocol];
+ } else if (!theObject) {
+ @throw [NSException exceptionWithName:@"JSObjectionException"
+ reason:[NSString stringWithFormat:@"Cannot find an instance that is bound to the protocol '%@' to assign to the property '%@'", NSStringFromProtocol(desiredClassOrProtocol), propertyName]
+ userInfo:nil];
+ }
+
+ [propertiesDictionary setObject:theObject forKey:propertyName];
+ }
+
+ [objectUnderConstruction setValuesForKeysWithDictionary:propertiesDictionary];
+ }
+
+ [self notifyObjectThatItIsReady: objectUnderConstruction];
+ return objectUnderConstruction;
}
#pragma mark Class Methods
#pragma mark -
-+ (id)entryWithClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)theLifeCycle
-{
- return [[[JSObjectionInjectorEntry alloc] initWithClass:theClass lifeCycle:theLifeCycle] autorelease];
++ (id)entryWithClass:(Class)theClass lifeCycle:(JSObjectionInstantiationRule)theLifeCycle {
+ return [[[JSObjectionInjectorEntry alloc] initWithClass:theClass lifeCycle:theLifeCycle] autorelease];
}
-+ (id)entryWithEntry:(JSObjectionInjectorEntry *)entry
-{
- return [[[JSObjectionInjectorEntry alloc] initWithClass:entry.classEntry lifeCycle:entry.lifeCycle] autorelease];
++ (id)entryWithEntry:(JSObjectionInjectorEntry *)entry {
+ return [[[JSObjectionInjectorEntry alloc] initWithClass:entry.classEntry lifeCycle:entry.lifeCycle] autorelease];
}
@end
View
4 Source/JSObjectionModule.h
@@ -8,8 +8,8 @@
@interface JSObjectionModule : NSObject {
- NSMutableDictionary *_bindings;
- NSMutableSet *_eagerSingletons;
+ NSMutableDictionary *_bindings;
+ NSMutableSet *_eagerSingletons;
}
@property (nonatomic, readonly) NSDictionary *bindings;
View
161 Source/JSObjectionModule.m
@@ -6,24 +6,22 @@
@interface __JSClassProvider : NSObject<JSObjectionProvider>
{
- Class _class;
+ Class _class;
}
- (id)initWithClass:(Class)aClass;
@end
@implementation __JSClassProvider
-- (id)initWithClass:(Class)aClass
-{
- if ((self = [super init])) {
- _class = aClass;
- }
- return self;
+- (id)initWithClass:(Class)aClass {
+ if ((self = [super init])) {
+ _class = aClass;
+ }
+ return self;
}
-- (id)provide:(JSObjectionInjector *)context
-{
- return [context getObject:_class];
+- (id)provide:(JSObjectionInjector *)context {
+ return [context getObject:_class];
}
@end
@@ -37,118 +35,103 @@ @implementation JSObjectionModule
@synthesize bindings = _bindings;
@synthesize eagerSingletons = _eagerSingletons;
-- (id)init
-{
- if ((self = [super init])) {
- _bindings = [[NSMutableDictionary alloc] init];
- _eagerSingletons = [[NSMutableSet alloc] init];
- }
- return self;
+- (id)init {
+ if ((self = [super init])) {
+ _bindings = [[NSMutableDictionary alloc] init];
+ _eagerSingletons = [[NSMutableSet alloc] init];
+ }
+ return self;
}
-- (void)bindMetaClass:(Class)metaClass toProtocol:(Protocol *)aProtocol
-{
- if (!class_isMetaClass(object_getClass(metaClass))) {
- @throw [NSException exceptionWithName:@"JSObjectionException"
- reason:[NSString stringWithFormat:@"\"%@\" can not be bound to the protocol \"%@\" because it is not a meta class", metaClass, NSStringFromProtocol(aProtocol)]
- userInfo:nil];
- }
- NSString *key = [self protocolKey:aProtocol];
- JSObjectionBindingEntry *entry = [[[JSObjectionBindingEntry alloc] initWithObject:metaClass] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void)bindMetaClass:(Class)metaClass toProtocol:(Protocol *)aProtocol {
+ if (!class_isMetaClass(object_getClass(metaClass))) {
+ @throw [NSException exceptionWithName:@"JSObjectionException"
+ reason:[NSString stringWithFormat:@"\"%@\" can not be bound to the protocol \"%@\" because it is not a meta class", metaClass, NSStringFromProtocol(aProtocol)]
+ userInfo:nil];
+ }
+ NSString *key = [self protocolKey:aProtocol];
+ JSObjectionBindingEntry *entry = [[[JSObjectionBindingEntry alloc] initWithObject:metaClass] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void) bind:(id)instance toProtocol:(Protocol *)aProtocol
-{
- [self ensureInstance: instance conformsTo: aProtocol];
- NSString *key = [self protocolKey:aProtocol];
- JSObjectionBindingEntry *entry = [[[JSObjectionBindingEntry alloc] initWithObject:instance] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void) bind:(id)instance toProtocol:(Protocol *)aProtocol {
+ [self ensureInstance: instance conformsTo: aProtocol];
+ NSString *key = [self protocolKey:aProtocol];
+ JSObjectionBindingEntry *entry = [[[JSObjectionBindingEntry alloc] initWithObject:instance] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void) bind:(id)instance toClass:(Class)aClass
-{
- NSString *key = NSStringFromClass(aClass);
- JSObjectionBindingEntry *entry = [[[JSObjectionBindingEntry alloc] initWithObject:instance] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void) bind:(id)instance toClass:(Class)aClass {
+ NSString *key = NSStringFromClass(aClass);
+ JSObjectionBindingEntry *entry = [[[JSObjectionBindingEntry alloc] initWithObject:instance] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void)bindProvider:(id<JSObjectionProvider>)provider toClass:(Class)aClass
-{
- NSString *key = NSStringFromClass(aClass);
- JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void)bindProvider:(id<JSObjectionProvider>)provider toClass:(Class)aClass {
+ NSString *key = NSStringFromClass(aClass);
+ JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void)bindProvider:(id<JSObjectionProvider>)provider toProtocol:(Protocol *)aProtocol
-{
- NSString *key = [self protocolKey:aProtocol];
- JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void)bindProvider:(id<JSObjectionProvider>)provider toProtocol:(Protocol *)aProtocol {
+ NSString *key = [self protocolKey:aProtocol];
+ JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void)bindClass:(Class)aClass toProtocol:(Protocol *)aProtocol
-{
- NSString *key = [self protocolKey:aProtocol];
- __JSClassProvider *provider = [[[__JSClassProvider alloc] initWithClass:aClass] autorelease];
- JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void)bindClass:(Class)aClass toProtocol:(Protocol *)aProtocol {
+ NSString *key = [self protocolKey:aProtocol];
+ __JSClassProvider *provider = [[[__JSClassProvider alloc] initWithClass:aClass] autorelease];
+ JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
+ [_bindings setObject:entry forKey:key];
}
- (void)bindClass:(Class)aClass toClass:(Class)toClass {
- NSString *key = NSStringFromClass(toClass);
- __JSClassProvider *provider = [[[__JSClassProvider alloc] initWithClass:aClass] autorelease];
- JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
- [_bindings setObject:entry forKey:key];
+ NSString *key = NSStringFromClass(toClass);
+ __JSClassProvider *provider = [[[__JSClassProvider alloc] initWithClass:aClass] autorelease];
+ JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithProvider:provider] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void)bindBlock:(id (^)(JSObjectionInjector *context))block toClass:(Class)aClass
-{
- NSString *key = NSStringFromClass(aClass);
- JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithBlock:block] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void)bindBlock:(id (^)(JSObjectionInjector *context))block toClass:(Class)aClass {
+ NSString *key = NSStringFromClass(aClass);
+ JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithBlock:block] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void)bindBlock:(id (^)(JSObjectionInjector *context))block toProtocol:(Protocol *)aProtocol
-{
- NSString *key = [self protocolKey:aProtocol];
- JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithBlock:block] autorelease];
- [_bindings setObject:entry forKey:key];
+- (void)bindBlock:(id (^)(JSObjectionInjector *context))block toProtocol:(Protocol *)aProtocol {
+ NSString *key = [self protocolKey:aProtocol];
+ JSObjectionProviderEntry *entry = [[[JSObjectionProviderEntry alloc] initWithBlock:block] autorelease];
+ [_bindings setObject:entry forKey:key];
}
-- (void) registerEagerSingleton:(Class)klass
-{
- [_eagerSingletons addObject:NSStringFromClass(klass)];
+- (void) registerEagerSingleton:(Class)klass {
+ [_eagerSingletons addObject:NSStringFromClass(klass)];
}
-- (void) configure
-{
+- (void) configure {
}
-- (void)dealloc
-{
- [_bindings release]; _bindings = nil;
- [_eagerSingletons release]; _eagerSingletons = nil;
- [super dealloc];
+- (void)dealloc {
+ [_bindings release]; _bindings = nil;
+ [_eagerSingletons release]; _eagerSingletons = nil;
+ [super dealloc];
}
#pragma mark Private
#pragma mark -
-- (void)ensureInstance:(id)instance conformsTo:(Protocol *)aProtocol
-{
- if (![instance conformsToProtocol:aProtocol]) {
- @throw [NSException exceptionWithName:@"JSObjectionException"
- reason:[NSString stringWithFormat:@"Instance does not conform to the %@ protocol", NSStringFromProtocol(aProtocol)]
- userInfo:nil];
- }
-
+- (void)ensureInstance:(id)instance conformsTo:(Protocol *)aProtocol {
+ if (![instance conformsToProtocol:aProtocol]) {
+ @throw [NSException exceptionWithName:@"JSObjectionException"
+ reason:[NSString stringWithFormat:@"Instance does not conform to the %@ protocol", NSStringFromProtocol(aProtocol)]
+ userInfo:nil];
+ }
}
-- (NSString *)protocolKey:(Protocol *)aProtocol
-{
- return [NSString stringWithFormat:@"<%@>", NSStringFromProtocol(aProtocol)];
+- (NSString *)protocolKey:(Protocol *)aProtocol {
+ return [NSString stringWithFormat:@"<%@>", NSStringFromProtocol(aProtocol)];
}
@end
View
4 Source/JSObjectionProviderEntry.h
@@ -5,8 +5,8 @@
@class JSObjectionInjector;
@interface JSObjectionProviderEntry : JSObjectionEntry {
- id<JSObjectionProvider> _provider;
- id(^_block)(JSObjectionInjector *context);
+ id<JSObjectionProvider> _provider;
+ id(^_block)(JSObjectionInjector *context);
}
- (id)initWithProvider:(id<JSObjectionProvider>)theProvider;
View
44 Source/JSObjectionProviderEntry.m
@@ -3,36 +3,32 @@
@implementation JSObjectionProviderEntry
-- (id)initWithProvider:(id<JSObjectionProvider>)theProvider
-{
- if ((self = [super init])) {
- _provider = [theProvider retain];
- }
-
- return self;
+- (id)initWithProvider:(id<JSObjectionProvider>)theProvider {
+ if ((self = [super init])) {
+ _provider = [theProvider retain];
+ }
+
+ return self;
}
-- (id)initWithBlock:(id(^)(JSObjectionInjector *context))theBlock
-{
- if ((self = [super init])) {
- _block = [theBlock copy];
- }
+- (id)initWithBlock:(id(^)(JSObjectionInjector *context))theBlock {
+ if ((self = [super init])) {
+ _block = [theBlock copy];
+ }
- return self;
+ return self;
}
-- (id)extractObject
-{
- if (_block) {
- return _block(self.injector);
- }
- return [_provider provide:self.injector];
+- (id)extractObject {
+ if (_block) {
+ return _block(self.injector);
+ }
+ return [_provider provide:self.injector];
}
-- (void)dealloc
-{
- [_provider release];
- [_block release];
- [super dealloc];
+- (void)dealloc {
+ [_provider release];
+ [_block release];
+ [super dealloc];
}
@end
View
14 Source/JSObjectionUtils.h
@@ -2,17 +2,17 @@
#import <objc/runtime.h>
typedef enum {
- JSObjectionTypeClass,
- JSObjectionTypeProtocol
+ JSObjectionTypeClass,
+ JSObjectionTypeProtocol
} JSObjectionType;
typedef struct objection_property_info {
- void *value;
- JSObjectionType type;
+ void *value;
+ JSObjectionType type;
} JSObjectionPropertyInfo;
extern const struct JSObjectionUtils {
- JSObjectionPropertyInfo (*findClassOrProtocolForProperty)(objc_property_t property);
- objc_property_t (*propertyForClass)(Class klass, NSString *propertyName);
- NSSet* (*buildDependenciesForClass)(Class klass, NSSet *requirements);
+ JSObjectionPropertyInfo (*findClassOrProtocolForProperty)(objc_property_t property);
+ objc_property_t (*propertyForClass)(Class klass, NSString *propertyName);
+ NSSet* (*buildDependenciesForClass)(Class klass, NSSet *requirements);
} JSObjectionUtils;
View
105 Source/JSObjectionUtils.m
@@ -3,68 +3,67 @@
static NSString *const JSObjectionException = @"JSObjectionException";
-static JSObjectionPropertyInfo FindClassOrProtocolForProperty(objc_property_t property)
-{
- NSString *attributes = [NSString stringWithCString: property_getAttributes(property) encoding: NSASCIIStringEncoding];
- NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSASCIIStringEncoding];
-
- NSRange startRange = [attributes rangeOfString:@"T@\""];
- if (startRange.location == NSNotFound) {
- @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
- }
-
- NSString *startOfClassName = [attributes substringFromIndex:startRange.length];
- NSRange endRange = [startOfClassName rangeOfString:@"\""];
-
- if (endRange.location == NSNotFound) {
- @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
- }
-
- NSString *classOrProtocolName = [startOfClassName substringToIndex:endRange.location];
- id classOrProtocol = nil;
- JSObjectionPropertyInfo propertyInfo;
-
- if ([classOrProtocolName hasPrefix:@"<"] && [classOrProtocolName hasSuffix:@">"]) {
- classOrProtocolName = [classOrProtocolName stringByReplacingOccurrencesOfString:@"<" withString:@""];
- classOrProtocolName = [classOrProtocolName stringByReplacingOccurrencesOfString:@">" withString:@""];
- classOrProtocol = objc_getProtocol([classOrProtocolName UTF8String]);
- propertyInfo.type = JSObjectionTypeProtocol;
- } else {
- classOrProtocol = NSClassFromString(classOrProtocolName);
- propertyInfo.type = JSObjectionTypeClass;
- }
-
- if(!classOrProtocol) {
- @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable get class for name '%@' for property '%@'", classOrProtocolName, propertyName] userInfo:nil];
- }
- propertyInfo.value = classOrProtocol;
-
- return propertyInfo;
+static JSObjectionPropertyInfo FindClassOrProtocolForProperty(objc_property_t property) {
+ NSString *attributes = [NSString stringWithCString: property_getAttributes(property) encoding: NSASCIIStringEncoding];
+ NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSASCIIStringEncoding];
+
+ NSRange startRange = [attributes rangeOfString:@"T@\""];
+ if (startRange.location == NSNotFound) {
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
+ }
+
+ NSString *startOfClassName = [attributes substringFromIndex:startRange.length];
+ NSRange endRange = [startOfClassName rangeOfString:@"\""];
+
+ if (endRange.location == NSNotFound) {
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to determine class type for property declaration: '%@'", propertyName] userInfo:nil];
+ }
+
+ NSString *classOrProtocolName = [startOfClassName substringToIndex:endRange.location];
+ id classOrProtocol = nil;
+ JSObjectionPropertyInfo propertyInfo;
+
+ if ([classOrProtocolName hasPrefix:@"<"] && [classOrProtocolName hasSuffix:@">"]) {
+ classOrProtocolName = [classOrProtocolName stringByReplacingOccurrencesOfString:@"<" withString:@""];
+ classOrProtocolName = [classOrProtocolName stringByReplacingOccurrencesOfString:@">" withString:@""];
+ classOrProtocol = objc_getProtocol([classOrProtocolName UTF8String]);
+ propertyInfo.type = JSObjectionTypeProtocol;
+ } else {
+ classOrProtocol = NSClassFromString(classOrProtocolName);
+ propertyInfo.type = JSObjectionTypeClass;
+ }
+
+ if(!classOrProtocol) {
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable get class for name '%@' for property '%@'", classOrProtocolName, propertyName] userInfo:nil];
+ }
+ propertyInfo.value = classOrProtocol;
+
+ return propertyInfo;
}
static NSSet* BuildDependenciesForClass(Class klass, NSSet *requirements)
{
- Class superClass = class_getSuperclass([klass class]);
- if([superClass respondsToSelector:@selector(objectionRequires)]) {
- NSSet *parentsRequirements = [superClass performSelector:@selector(objectionRequires)];
- NSMutableSet *dependencies = [NSMutableSet setWithSet:parentsRequirements];
- [dependencies unionSet:requirements];
- requirements = dependencies;
- }
- return requirements;
+ Class superClass = class_getSuperclass([klass class]);
+ if([superClass respondsToSelector:@selector(objectionRequires)]) {
+ NSSet *parentsRequirements = [superClass performSelector:@selector(objectionRequires)];
+ NSMutableSet *dependencies = [NSMutableSet setWithSet:parentsRequirements];
+ [dependencies unionSet:requirements];
+ requirements = dependencies;
+ }
+ return requirements;
}
static objc_property_t GetProperty(Class klass, NSString *propertyName)
{
- objc_property_t property = class_getProperty(klass, (const char *)[propertyName UTF8String]);
- if (property == NULL) {
- @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to find property declaration: '%@'", propertyName] userInfo:nil];
- }
- return property;
+ objc_property_t property = class_getProperty(klass, (const char *)[propertyName UTF8String]);
+ if (property == NULL) {
+ @throw [NSException exceptionWithName:JSObjectionException reason:[NSString stringWithFormat:@"Unable to find property declaration: '%@'", propertyName] userInfo:nil];
+ }
+ return property;
}
const struct JSObjectionUtils JSObjectionUtils = {
- .findClassOrProtocolForProperty = FindClassOrProtocolForProperty,
- .propertyForClass = GetProperty,
- .buildDependenciesForClass = BuildDependenciesForClass
+ .findClassOrProtocolForProperty = FindClassOrProtocolForProperty,
+ .propertyForClass = GetProperty,
+ .buildDependenciesForClass = BuildDependenciesForClass
};
View
3  Source/NSObject+Objection.m
@@ -2,8 +2,7 @@
@implementation NSObject(JSObjection)
-- (void)awakeFromObjection
-{
+- (void)awakeFromObjection {
}
@end
View
28 Source/Objection.h
@@ -14,21 +14,21 @@
#import "JSObjection.h"
#define objection_register(value) \
- + (void)initialize { \
- if (self == [value class]) { \
- [JSObjection registerClass:[value class] lifeCycle: JSObjectionInstantiationRuleNormal]; \
- } \
- }
+ + (void)initialize { \
+ if (self == [value class]) { \
+ [JSObjection registerClass:[value class] lifeCycle: JSObjectionInstantiationRuleNormal]; \
+ } \
+ }
#define objection_register_singleton(value) \
- + (void)initialize { \
- if (self == [value class]) { \
- [JSObjection registerClass:[value class] lifeCycle: JSObjectionInstantiationRuleSingleton]; \
- } \
- }
+ + (void)initialize { \
+ if (self == [value class]) { \
+ [JSObjection registerClass:[value class] lifeCycle: JSObjectionInstantiationRuleSingleton]; \
+ } \
+ }
#define objection_requires(args...) \
- + (NSSet *)objectionRequires { \
- NSSet *requirements = [NSSet setWithObjects: args, nil]; \
- return JSObjectionUtils.buildDependenciesForClass(self, requirements); \
- }
+ + (NSSet *)objectionRequires { \
+ NSSet *requirements = [NSSet setWithObjects: args, nil]; \
+ return JSObjectionUtils.buildDependenciesForClass(self, requirements); \
+ }
View
30 Specs/BasicUsageSpecs.m
@@ -6,11 +6,11 @@
beforeEach(^{
JSObjectionInjector *injector = [JSObjection createInjector];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"correctly builds a registered object", ^{
- id engine = [[JSObjection globalInjector] getObject:[Engine class]];
+ id engine = [[JSObjection defaultInjector] getObject:[Engine class]];
assertThat(engine, isNot(nilValue()));
});
@@ -18,11 +18,11 @@
it(@"returns nil for a non-registered object", ^{
Class newClass = objc_allocateClassPair([NSObject class], "MyFooClass", 0);
objc_registerClassPair(newClass);
- assertThat([[JSObjection globalInjector] getObject:newClass], is(nilValue()));
+ assertThat([[JSObjection defaultInjector] getObject:newClass], is(nilValue()));
});
it(@"correctly builds and object with dependencies", ^{
- Car *car = [[JSObjection globalInjector] getObject:[Car class]];
+ Car *car = [[JSObjection defaultInjector] getObject:[Car class]];
assertThat(car, isNot(nilValue()));
@@ -34,15 +34,15 @@
});
it(@"defaults to returning a new instance", ^{
- id thomas = [[JSObjection globalInjector] getObject:[Engine class]];
- id gordan = [[JSObjection globalInjector] getObject:[Engine class]];
+ id thomas = [[JSObjection defaultInjector] getObject:[Engine class]];
+ id gordan = [[JSObjection defaultInjector] getObject:[Engine class]];
assertThat(thomas, isNot(sameInstance(gordan)));
});
it(@"will return the same instance if it is registered as a singleton", ^{
- id carFactory1 = [[JSObjection globalInjector] getObject:[CarFactory class]];
- id carFactory2 = [[JSObjection globalInjector] getObject:[CarFactory class]];
+ id carFactory1 = [[JSObjection defaultInjector] getObject:[CarFactory class]];
+ id carFactory2 = [[JSObjection defaultInjector] getObject:[CarFactory class]];
assertThat(carFactory1, isNot(nilValue()));
assertThat(carFactory1, is(sameInstance(carFactory2)));
@@ -50,20 +50,20 @@
it(@"ensures that singletons are properly registered even if they have not been referenced", ^{
// Ensure that the class is initialized before attempting to retrieve it.
- id holder1 = [[JSObjection globalInjector] getObject:[SingletonItemHolder class]];
- id holder2 = [[JSObjection globalInjector] getObject:[SingletonItemHolder class]];
+ id holder1 = [[JSObjection defaultInjector] getObject:[SingletonItemHolder class]];
+ id holder2 = [[JSObjection defaultInjector] getObject:[SingletonItemHolder class]];
assertThat([holder1 singletonItem], is(sameInstance([holder2 singletonItem])));
});
it(@"will not return the same instance per injector if object is a singleton", ^{
- id carFactory1 = [[JSObjection globalInjector] getObject:[CarFactory class]];
+ id carFactory1 = [[JSObjection defaultInjector] getObject:[CarFactory class]];
id carFactory2 = [[JSObjection createInjector] getObject:[CarFactory class]];
assertThat(carFactory1, isNot(sameInstance(carFactory2)));
});
it(@"returns nil if the class is nil", ^{
- assertThat([[JSObjection globalInjector] getObject:nil], is(nilValue()));
+ assertThat([[JSObjection defaultInjector] getObject:nil], is(nilValue()));
});
it(@"doesn't blow up if a nil class is passed into register", ^{
@@ -71,8 +71,8 @@
});
it(@"calls awakeFromObjection when an object has been constructed", ^{
- id engine = [[JSObjection globalInjector] getObject:[Engine class]];
- id car = [[JSObjection globalInjector] getObject:[Car class]];
+ id engine = [[JSObjection defaultInjector] getObject:[Engine class]];
+ id car = [[JSObjection defaultInjector] getObject:[Car class]];
assertThatBool([engine awake], equalToBool(YES));
assertThatBool([car awake], equalToBool(YES));
@@ -80,7 +80,7 @@
it(@"returns a JSObjectFactory for the given injector context", ^{
JSObjectionInjector *injector1 = [JSObjection createInjector];
- JSObjectionInjector *injector2 = [JSObjection globalInjector];
+ JSObjectionInjector *injector2 = [JSObjection defaultInjector];
JSObjectFactoryHolder *holder1 = [injector1 getObject:[JSObjectFactoryHolder class]];
JSObjectFactoryHolder *holder2 = [injector2 getObject:[JSObjectFactoryHolder class]];
View
6 Specs/CircularDependencySpecs.m
@@ -7,12 +7,12 @@
describe(@"circular dependencies", ^{
beforeEach(^{
JSObjectionInjector *injector = [JSObjection createInjector];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"are resolved between singletons", ^{
- SingletonFoo *foo = [[JSObjection globalInjector] getObject:[SingletonFoo class]];
- SingletonBar *bar = [[JSObjection globalInjector] getObject:[SingletonBar class]];
+ SingletonFoo *foo = [[JSObjection defaultInjector] getObject:[SingletonFoo class]];
+ SingletonBar *bar = [[JSObjection defaultInjector] getObject:[SingletonBar class]];
assertThat(foo, is(sameInstance(bar.foo)));
assertThat(foo.bar, is(sameInstance(bar)));
View
6 Specs/InheritanceSpecs.m
@@ -49,18 +49,18 @@ @implementation NoInheritance
SPEC_BEGIN(InheritanceSpecs)
beforeEach(^{
JSObjectionInjector *injector = [JSObjection createInjector];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"coalesces dependencies from parent to child", ^{
- Programmer *programmer = [[JSObjection globalInjector] getObject:[Programmer class]];
+ Programmer *programmer = [[JSObjection defaultInjector] getObject:[Programmer class]];
assertThat(programmer, is(notNilValue()));
assertThat(programmer.favoriteLanguages, is(notNilValue()));
assertThat(programmer.attributes, is(notNilValue()));
});
it(@"does not throw a fit if the base class does not implement .objectionRequires", ^{
- NoInheritance *noParentObjectWithRequires = [[JSObjection globalInjector] getObject:[NoInheritance class]];
+ NoInheritance *noParentObjectWithRequires = [[JSObjection defaultInjector] getObject:[NoInheritance class]];
assertThat(noParentObjectWithRequires.something, is(notNilValue()));
});
SPEC_END
View
8 Specs/InjectionErrorsSpecs.m
@@ -6,24 +6,24 @@
beforeEach(^{
JSObjectionInjector *injector = [JSObjection createInjector];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"throws an exception if property type is not an object", ^{
[[theBlock(^{
- [[JSObjection globalInjector] getObject:[UnsupportedPropertyObject class]];
+ [[JSObjection defaultInjector] getObject:[UnsupportedPropertyObject class]];
}) should] raiseWithReason:@"Unable to determine class type for property declaration: 'myInteger'"];
});
it(@"throws an exception if property cannot be found", ^{
[[theBlock(^{
- [[JSObjection globalInjector] getObject:[BadPropertyObject class]];
+ [[JSObjection defaultInjector] getObject:[BadPropertyObject class]];
}) should] raiseWithReason:@"Unable to find property declaration: 'badProperty'"];
});
it(@"throws if an object requires a protocol that does not exist in the context", ^{
[[theBlock(^{
- [[JSObjection globalInjector] getObject:[ManualCar class]];
+ [[JSObjection defaultInjector] getObject:[ManualCar class]];
}) should] raiseWithReason:@"Cannot find an instance that is bound to the protocol 'GearBox' to assign to the property 'gearBox'"];
});
View
32 Specs/ModuleUsageSpecs.m
@@ -11,22 +11,22 @@
module = [[[MyModule alloc] initWithEngine:engine andGearBox:gearBox] autorelease];
JSObjectionInjector *injector = [JSObjection createInjector:module];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"merges the modules instance bindings with the injector's context", ^{
- assertThat([[JSObjection globalInjector] getObject:[Engine class]], is(sameInstance(module.engine)));
+ assertThat([[JSObjection defaultInjector] getObject:[Engine class]], is(sameInstance(module.engine)));
});
it(@"uses the module's bounded instance to fill out other objects dependencies", ^{
- ManualCar *car = [[JSObjection globalInjector] getObject:[ManualCar class]];
+ ManualCar *car = [[JSObjection defaultInjector] getObject:[ManualCar class]];
assertThat(car.engine, is(sameInstance(module.engine)));
assertThat(car.gearBox, is(sameInstance(module.gearBox)));
});
it(@"supports binding an instance to a protocol", ^{
- assertThat([[JSObjection globalInjector] getObject:@protocol(GearBox)], is(sameInstance(module.gearBox)));
+ assertThat([[JSObjection defaultInjector] getObject:@protocol(GearBox)], is(sameInstance(module.gearBox)));
});
it(@"throws an exception if the instance does not conform to the protocol", ^{
@@ -60,11 +60,11 @@
beforeEach(^{
providerModule = [[[ProviderModule alloc] init] autorelease];
JSObjectionInjector *injector = [JSObjection createInjector:providerModule];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"allows a bound protocol to be created through a provider", ^{
- ManualCar *car = [[JSObjection globalInjector] getObject:[Car class]];
+ ManualCar *car = [[JSObjection defaultInjector] getObject:[Car class]];
assertThat(car, is(instanceOf([ManualCar class])));
assertThat(car.brakes, is(instanceOf([Brakes class])));
@@ -72,7 +72,7 @@
});
it(@"allows a bound class to be created through a provider", ^{
- AfterMarketGearBox *gearBox = [[JSObjection globalInjector] getObject:@protocol(GearBox)];
+ AfterMarketGearBox *gearBox = [[JSObjection defaultInjector] getObject:@protocol(GearBox)];
assertThat(gearBox, is(instanceOf([AfterMarketGearBox class])));
});
});
@@ -83,11 +83,11 @@
beforeEach(^{
blockModule = [[[BlockModule alloc] init] autorelease];
JSObjectionInjector *injector = [JSObjection createInjector:blockModule];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"allows a bound protocol to be created using a block", ^{
- ManualCar *car = [[JSObjection globalInjector] getObject:[Car class]];
+ ManualCar *car = [[JSObjection defaultInjector] getObject:[Car class]];
assertThat(car, is(instanceOf([ManualCar class])));
assertThat(car.brakes, is(instanceOf([Brakes class])));
@@ -95,14 +95,14 @@
});
it(@"allows a bound class to be created using a block", ^{
- AfterMarketGearBox *gearBox = [[JSObjection globalInjector] getObject:@protocol(GearBox)];
+ AfterMarketGearBox *gearBox = [[JSObjection defaultInjector] getObject:@protocol(GearBox)];
assertThat(gearBox, is(instanceOf([AfterMarketGearBox class])));
});
});
describe(@"meta class bindings", ^{
it(@"supports binding to a meta class instance via a protocol", ^{
- id<MetaCar> car = [[JSObjection globalInjector] getObject:@protocol(MetaCar)];
+ id<MetaCar> car = [[JSObjection defaultInjector] getObject:@protocol(MetaCar)];
assertThat(car, is([Car class]));
assertThat([car manufacture], is(instanceOf([Car class])));
});
@@ -122,7 +122,7 @@
describe(@"class to protocol bindings", ^{
it(@"supports associating a concrete class with a protocol", ^{
- VisaCCProcessor *processor = [[JSObjection globalInjector] getObject:@protocol(CreditCardProcessor)];
+ VisaCCProcessor *processor = [[JSObjection defaultInjector] getObject:@protocol(CreditCardProcessor)];
assertThat(processor, is(instanceOf([VisaCCProcessor class])));
assertThat(processor.validator, is(instanceOf([CreditCardValidator class])));
@@ -131,7 +131,7 @@
describe(@"subclass to superclass bindings", ^{
it(@"supports associating a concrete class with a protocol", ^{
- VisaCCProcessor *processor = [[JSObjection globalInjector] getObject:[BaseCreditCardProcessor class]];
+ VisaCCProcessor *processor = [[JSObjection defaultInjector] getObject:[BaseCreditCardProcessor class]];
assertThat(processor, is(instanceOf([VisaCCProcessor class])));
assertThat(processor.validator, is(instanceOf([CreditCardValidator class])));
@@ -143,12 +143,12 @@
FirstModule *first = [[[FirstModule alloc] init] autorelease];
SecondModule *second = [[[SecondModule alloc] init] autorelease];
JSObjectionInjector *injector = [JSObjection createInjectorWithModules:first, second, nil];
- [JSObjection setGlobalInjector:injector];
+ [JSObjection setDefaultInjector:injector];
});
it(@"merges the binding in each module", ^{
- AfterMarketGearBox *gearBox = [[JSObjection globalInjector] getObject:@protocol(GearBox)];
- Car *car = [[JSObjection globalInjector] getObject:[Car class]];
+ AfterMarketGearBox *gearBox = [[JSObjection defaultInjector] getObject:@protocol(GearBox)];
+ Car *car = [[JSObjection defaultInjector] getObject:[Car class]];
assertThat(gearBox, is(instanceOf([AfterMarketGearBox class])));
assertThat(car, is(instanceOf([ManualCar class])));
Please sign in to comment.
Something went wrong with that request. Please try again.