Permalink
Browse files

Added subscripting operators to JSObjectionInjector and JSObjectFactory

  • Loading branch information...
thestoics committed Nov 17, 2012
1 parent 5060bb7 commit 1ede795d5d163c4eb96a950c4a387ee37105c61f
View
@@ -13,10 +13,10 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
- <string>0.13.2</string>
+ <string>0.13.3</string>
<key>CFBundleSignature</key>
<string>ATOM</string>
<key>CFBundleVersion</key>
- <string>0.13.2</string>
+ <string>0.13.3</string>
</dict>
</plist>
View
@@ -2,7 +2,7 @@ PROJECT_NAME = "Objection"
CONFIGURATION = "Debug"
SPECS_TARGET_NAME = "Specs-OSX"
UI_SPECS_TARGET_NAME = "Specs-iOS"
-SDK_DIR = "iphonesimulator5.1"
+SDK_DIR = "iphonesimulator6.0"
def xcodebuild_executable
ENV['XCODEBUILD'] || "xcodebuild"
View
@@ -10,5 +10,6 @@
- (id)initWithInjector:(JSObjectionInjector *)injector;
- (id)getObject:(id)classOrProtocol;
+- (id)objectForKeyedSubscript: (id)key;
- (id)getObjectWithArgs:(id)classOrProtocol, ... NS_REQUIRES_NIL_TERMINATION;
@end
View
@@ -15,6 +15,11 @@ - (id)getObject:(id)classOrProtocol {
return [self.injector getObject:classOrProtocol];
}
+- (id)objectForKeyedSubscript: (id)key {
+ return [self getObject:key];
+}
+
+
- (id)getObjectWithArgs:(id)classOrProtocol, ... {
va_list va_arguments;
va_start(va_arguments, classOrProtocol);
@@ -13,4 +13,5 @@
- (id)getObject:(id)classOrProtocol;
- (id)getObjectWithArgs:(id)classOrProtocol, ... NS_REQUIRES_NIL_TERMINATION;
- (id)getObject:(id)classOrProtocol arguments:(va_list)argList;
+- (id)objectForKeyedSubscript: (id)key;
@end
@@ -77,6 +77,10 @@ - (id)getObjectWithArgs:(id)classOrProtocol, ... {
return object;
}
+- (id)objectForKeyedSubscript: (id)key {
+ return [self getObjectWithArgs:key, nil];
+}
+
- (id)getObject:(id)classOrProtocol {
return [self getObjectWithArgs:classOrProtocol, nil];
}
View
@@ -40,6 +40,13 @@
assertThat(thomas, isNot(sameInstance(gordan)));
});
+it(@"supports the subscript operator", ^{
+ Car *car = [JSObjection defaultInjector][[Car class]];
+
+ assertThat(car, isNot(nilValue()));
+ assertThat(car.engine, is(instanceOf([Engine class])));
+});
+
it(@"will return the same instance if it is registered as a singleton", ^{
id carFactory1 = [[JSObjection defaultInjector] getObject:[CarFactory class]];
id carFactory2 = [[JSObjection defaultInjector] getObject:[CarFactory class]];
@@ -87,7 +94,7 @@
JSObjectFactoryHolder *holder1 = [injector1 getObject:[JSObjectFactoryHolder class]];
JSObjectFactoryHolder *holder2 = [injector2 getObject:[JSObjectFactoryHolder class]];
- SingletonItem *item1 = [holder1.objectFactory getObject:[SingletonItem class]];
+ SingletonItem *item1 = holder1.objectFactory[[SingletonItem class]];
SingletonItem *item2 = [holder2.objectFactory getObject:[SingletonItem class]];
[[item1 shouldNot] equal:item2];
@@ -119,7 +119,7 @@ Class KWSetupObjectInterceptSupport(id anObject) {
Class canonicalInterceptClass = KWInterceptClassForCanonicalClass(canonicalClass);
Class interceptClass = objectIsClass ? object_getClass(canonicalInterceptClass) : canonicalInterceptClass;
- anObject->isa = interceptClass;
+ object_setClass(anObject, interceptClass);
return interceptClass;
}
@@ -165,9 +165,9 @@ void KWInterceptedForwardInvocation(id anObject, SEL aSelector, NSInvocation* an
Class interceptClass = object_getClass(anObject);
Class originalClass = class_getSuperclass(interceptClass);
- anObject->isa = originalClass;
+ object_setClass(anObject, originalClass);
[anInvocation invoke];
- anObject->isa = interceptClass;
+ object_setClass(anObject, interceptClass);
}
void KWInterceptedDealloc(id anObject, SEL aSelector) {
@@ -177,7 +177,7 @@ void KWInterceptedDealloc(id anObject, SEL aSelector) {
Class interceptClass = object_getClass(anObject);
Class originalClass = class_getSuperclass(interceptClass);
- anObject->isa = originalClass;
+ object_setClass(anObject, originalClass);
[anObject dealloc];
}

0 comments on commit 1ede795

Please sign in to comment.