Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BloodMagic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
46535A1518207993004A9DA4 /* BMClass.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46535A1418207993004A9DA4 /* BMClass.mm */; };
4665B8FE181DE41600E56A01 /* BMDerivedLazyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 4665B8FD181DE41600E56A01 /* BMDerivedLazyModel.m */; };
4665B901181F167100E56A01 /* BMDerivedExtendedModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 4665B900181F167100E56A01 /* BMDerivedExtendedModel.m */; };
467029D7182D958E003EAFB0 /* BMInheritedModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 467029D6182D958E003EAFB0 /* BMInheritedModel.m */; };
467029DD182DA49D003EAFB0 /* BMInheritedExcludedModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 467029DC182DA49D003EAFB0 /* BMInheritedExcludedModel.m */; };
5898A017EC315B4F7ACA8ED4 /* BMPrimitiveDoubleProperty.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5898A44ADC6CBCAB1D7450AF /* BMPrimitiveDoubleProperty.mm */; };
5898A0CDBC271D861D86A9D4 /* BMPropertyValueService.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5898A964B7BE16D059B05D2B /* BMPropertyValueService.mm */; };
5898A1CBA9606A1BD3D94399 /* BMDerivedModel.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5898A29F077635D7ABE153A4 /* BMDerivedModel.mm */; };
Expand Down Expand Up @@ -78,6 +80,11 @@
4665B8FD181DE41600E56A01 /* BMDerivedLazyModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMDerivedLazyModel.m; sourceTree = "<group>"; };
4665B8FF181F167100E56A01 /* BMDerivedExtendedModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMDerivedExtendedModel.h; sourceTree = "<group>"; };
4665B900181F167100E56A01 /* BMDerivedExtendedModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMDerivedExtendedModel.m; sourceTree = "<group>"; };
467029D4182D94CC003EAFB0 /* BMLazyExclude.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BMLazyExclude.h; sourceTree = "<group>"; };
467029D5182D958E003EAFB0 /* BMInheritedModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMInheritedModel.h; sourceTree = "<group>"; };
467029D6182D958E003EAFB0 /* BMInheritedModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMInheritedModel.m; sourceTree = "<group>"; };
467029DB182DA49D003EAFB0 /* BMInheritedExcludedModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMInheritedExcludedModel.h; sourceTree = "<group>"; };
467029DC182DA49D003EAFB0 /* BMInheritedExcludedModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMInheritedExcludedModel.m; sourceTree = "<group>"; };
5898A00A6BF6E6793CD7D67F /* BMPrimitiveLongLongProperty.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BMPrimitiveLongLongProperty.mm; sourceTree = "<group>"; };
5898A05C65B2C230BF4EEA30 /* BMLazyTestProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMLazyTestProtocol.h; sourceTree = "<group>"; };
5898A0F6CC0832C2AAC67AE6 /* BMPropertyFinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMPropertyFinder.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -269,6 +276,10 @@
4665B8FD181DE41600E56A01 /* BMDerivedLazyModel.m */,
4665B8FF181F167100E56A01 /* BMDerivedExtendedModel.h */,
4665B900181F167100E56A01 /* BMDerivedExtendedModel.m */,
467029D5182D958E003EAFB0 /* BMInheritedModel.h */,
467029D6182D958E003EAFB0 /* BMInheritedModel.m */,
467029DB182DA49D003EAFB0 /* BMInheritedExcludedModel.h */,
467029DC182DA49D003EAFB0 /* BMInheritedExcludedModel.m */,
);
path = LazySpecs;
sourceTree = "<group>";
Expand Down Expand Up @@ -528,6 +539,7 @@
5898AB9F4613E1ECA2E75711 /* BMInitializerRegistry+LazyRegistry.h */,
5898AC5D06D970807E136F41 /* BMInitializerRegistry+LazyRegistry.mm */,
5898AEF8CAA0DB0BBB750EA0 /* BMLazy.h */,
467029D4182D94CC003EAFB0 /* BMLazyExclude.h */,
5898A19E3E1505FD50FF5637 /* cxx */,
5898AEB1DF36EF33AFE5A21B /* BMLazyDefinitions.h */,
);
Expand Down Expand Up @@ -803,7 +815,9 @@
5898A234C8F98F32DEA0C427 /* BMLazyInitializer.mm in Sources */,
5898A5B8898AB5C3BB60B7D7 /* BMPropertyFinder.mm in Sources */,
5898A5D5376DD0CC1122BA2A /* BMPropertyTypeParser.mm in Sources */,
467029DD182DA49D003EAFB0 /* BMInheritedExcludedModel.m in Sources */,
5898A440B7DF163D8A5829CB /* BMPropertyTypeParserSpec.mm in Sources */,
467029D7182D958E003EAFB0 /* BMInheritedModel.m in Sources */,
4665B901181F167100E56A01 /* BMDerivedExtendedModel.m in Sources */,
5898AEFE4638A4A76E754D55 /* BMTestProtocolModel.m in Sources */,
5898AF46023327D4875EE89A /* BMBaseModel.mm in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
@interface BMPropertyCollector : NSObject

- (NSArray *)collectForClass:(Class)klass withProtocol:(Protocol *)protocol;
- (NSArray *)collectForClass:(Class)klass withProtocol:(Protocol *)protocol excludingProtocol:(Protocol *)excludingProtocol;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

@implementation BMPropertyCollector

- (NSArray *)collectForClass:(Class)objcClass withProtocol:(Protocol *)protocol
- (NSArray *)collectForClass:(Class)objcClass withProtocol:(Protocol *)protocol {
return [self collectForClass:objcClass withProtocol:protocol excludingProtocol:nil];
}

- (NSArray *)collectForClass:(Class)objcClass withProtocol:(Protocol *)protocol excludingProtocol:(Protocol *)excludingProtocol
{
NSArray *cachedProperties = objc_getAssociatedObject(objcClass, kCachedPropertiesKey);
if (cachedProperties != nil) {
Expand All @@ -22,7 +26,10 @@ - (NSArray *)collectForClass:(Class)objcClass withProtocol:(Protocol *)protocol
Class superClass = objcClass;
while ([superClass conformsToProtocol:protocol]) {
BMClass *klass = [[BMClass alloc] initWithClass:superClass];
[properties unionSet:[klass dynamicProperties]];
BOOL isExcludedClass = [[klass protocols] containsObject:excludingProtocol];
if (!isExcludedClass) {
[properties unionSet:[klass dynamicProperties]];
}

superClass = [superClass superclass];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
@property (nonatomic, strong) BMPropertyCollector *propertyCollector;

- (void)injectDynamicHandlersIntoClass:(Class)klass withProtocol:(Protocol *)protocol;
- (void)injectDynamicHandlersIntoClass:(Class)klass withProtocol:(Protocol *)protocol excludingProtocol:(Protocol *)excludingProtocol;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ - (instancetype)init
return self;
}

- (void)injectDynamicHandlersIntoClass:(Class)klass withProtocol:(Protocol *)protocol
- (void)injectDynamicHandlersIntoClass:(Class)klass withProtocol:(Protocol *)protocol {
return [self injectDynamicHandlersIntoClass:klass withProtocol:protocol excludingProtocol:nil];
}

- (void)injectDynamicHandlersIntoClass:(Class)klass withProtocol:(Protocol *)protocol excludingProtocol:(Protocol *)excludingProtocol
{
NSArray *properties = [self.propertyCollector collectForClass:klass withProtocol:protocol];
NSArray *properties = [self.propertyCollector collectForClass:klass withProtocol:protocol excludingProtocol:excludingProtocol];
for (BMProperty *property in properties) {
class_addMethod(klass,
NSSelectorFromString(property.accessor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
@interface BMBloodMagicInjector : NSObject

- (void)injectBloodMagicInto:(Protocol *)protocol;
- (void)injectBloodMagicInto:(Protocol *)protocol excluding:(Protocol *)excludingProtocol;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ - (instancetype)init
return self;
}

- (void)injectBloodMagicInto:(Protocol *)protocol
- (void)injectBloodMagicInto:(Protocol *)protocol {
return [self injectBloodMagicInto:protocol excluding:nil];
}

- (void)injectBloodMagicInto:(Protocol *)protocol excluding:(Protocol *)excludingProtocol
{
NSArray *classes = [classCollector collectForProtocol:protocol];
for (Class klass in classes) {
[kvcInjector injectKVCHandlersIntoClass:klass];
[propertyInjector injectDynamicHandlersIntoClass:klass withProtocol:protocol];
[propertyInjector injectDynamicHandlersIntoClass:klass withProtocol:protocol excludingProtocol:excludingProtocol];
}
}

Expand Down
1 change: 1 addition & 0 deletions BloodMagic/Sources/Modules/Lazy/Lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#import "BMLazy.h"
#import "BMLazyExclude.h"
#import "BMInitializer+LazyInitializer.h"
#import "BMInitializerRegistry+LazyRegistry.h"
#import "BMLazyDefinitions.h"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ + (void)load
{
@autoreleasepool {
BMBloodMagicInjector *injector = [BMBloodMagicInjector new];
[injector injectBloodMagicInto:@protocol(BMLazy)];
[injector injectBloodMagicInto:@protocol(BMLazy) excluding:@protocol(BMLazyExclude)];
}
}

Expand Down
14 changes: 14 additions & 0 deletions BloodMagic/Sources/Modules/Lazy/Public/BMLazyExclude.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// BMLazyExclude.h
// BloodMagic
//
// Created by Eugene Solodovnykov on 08/11/13.
// Copyright (c) 2013 Railsware. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol BMLazyExclude
<NSObject>

@end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
beforeEach(^{
injector = [BMBloodMagicInjector new];

[injector injectBloodMagicInto:@protocol(BMFatTestProtocol)];
[injector injectBloodMagicInto:@protocol(BMFatTestProtocol) excluding:nil];
});

afterEach(^{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
describe(@"responds to", ^{

it(@"collectorForClass:", ^{
[subject respondsToSelector:@selector(collectForClass:withProtocol:)] should be_truthy;
[subject respondsToSelector:@selector(collectForClass:withProtocol:excludingProtocol:)] should be_truthy;
});

});
Expand All @@ -32,12 +32,12 @@
__block NSArray *properties = nil;

it(@"only dynamic properties", ^{
properties = [subject collectForClass:[BMUser class] withProtocol:@protocol(BMTestProtocol)];
properties = [subject collectForClass:[BMUser class] withProtocol:@protocol(BMTestProtocol) excludingProtocol:nil];
properties.count should equal(2);
});

it(@"including base class' properties", ^{
properties = [subject collectForClass:[BMDerivedExtendedModel class] withProtocol:@protocol(BMLazy)];
properties = [subject collectForClass:[BMDerivedExtendedModel class] withProtocol:@protocol(BMLazy) excludingProtocol:nil];
properties.count should equal(2);
});

Expand Down
41 changes: 41 additions & 0 deletions BloodMagic/Specs/Specs/Modules/Lazy/LazySpec.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "BMDerivedModel.h"
#import "BMDerivedLazyModel.h"
#import "BMDerivedExtendedModel.h"
#import "BMInheritedModel.h"
#import "BMInheritedExcludedModel.h"

using namespace Cedar::Matchers;
using namespace Cedar::Doubles;
Expand Down Expand Up @@ -155,6 +157,45 @@

});

context(@"inheritance", ^{
__block BMInheritedModel *inheritedModel = nil;

describe(@"inherited lazyness", ^{
beforeEach(^{
inheritedModel = [BMInheritedModel new];
});
afterEach(^{
[inheritedModel release];
inheritedModel = nil;
});

it(@"not nil", ^{
inheritedModel.user should_not be_nil;
});
});
});

context(@"excluding", ^{
__block BMInheritedExcludedModel *excludedModel = nil;

describe(@"inherited lazyness", ^{
beforeEach(^{
excludedModel = [BMInheritedExcludedModel new];
});
afterEach(^{
[excludedModel release];
excludedModel = nil;
});

it(@"super's property is not nil", ^{
excludedModel.user should_not be_nil;
});
it(@"doesn't instntiate exluded property", ^{
^{[excludedModel admin];} should raise_exception([NSException class]);
});
});
});

});

});
Expand Down
16 changes: 16 additions & 0 deletions BloodMagic/Specs/TestModels/LazySpecs/BMInheritedExcludedModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BMInheritedExcludedModel.h
// BloodMagic
//
// Created by Eugene Solodovnykov on 09/11/13.
// Copyright (c) 2013 Railsware. All rights reserved.
//

#import "BMLazyModel.h"
#import "BMLazyExclude.h"

@interface BMInheritedExcludedModel : BMLazyModel <BMLazyExclude>

@property (nonatomic, strong) BMUser *admin;

@end
15 changes: 15 additions & 0 deletions BloodMagic/Specs/TestModels/LazySpecs/BMInheritedExcludedModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BMInheritedExcludedModel.m
// BloodMagic
//
// Created by Eugene Solodovnykov on 09/11/13.
// Copyright (c) 2013 Railsware. All rights reserved.
//

#import "BMInheritedExcludedModel.h"

@implementation BMInheritedExcludedModel

@dynamic admin;

@end
15 changes: 15 additions & 0 deletions BloodMagic/Specs/TestModels/LazySpecs/BMInheritedModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BMInheritedModel.h
// BloodMagic
//
// Created by Eugene Solodovnykov on 08/11/13.
// Copyright (c) 2013 Railsware. All rights reserved.
//

#import "BMLazyModel.h"

@interface BMInheritedModel : BMLazyModel

@property (nonatomic, strong) BMUser *referal;

@end
15 changes: 15 additions & 0 deletions BloodMagic/Specs/TestModels/LazySpecs/BMInheritedModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BMInheritedModel.m
// BloodMagic
//
// Created by Eugene Solodovnykov on 08/11/13.
// Copyright (c) 2013 Railsware. All rights reserved.
//

#import "BMInheritedModel.h"

@implementation BMInheritedModel

@dynamic referal;

@end