Skip to content

Commit

Permalink
Add data attribute to Typhoon resource. Convenience init on block ass…
Browse files Browse the repository at this point in the history
…embly.
  • Loading branch information
Jasper Blues committed Mar 1, 2013
1 parent 17578eb commit 66af9c2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Source/Factory/Block/TyphoonBlockComponentFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

@interface TyphoonBlockComponentFactory : TyphoonComponentFactory

+ (id)factoryWithAssembly:(TyphoonAssembly*)assembly;

- (id)initWithAssembly:(TyphoonAssembly*)assembly;

@end
5 changes: 5 additions & 0 deletions Source/Factory/Block/TyphoonBlockComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ + (void)initialize
}


+ (id)factoryWithAssembly:(TyphoonAssembly*)assembly
{
return [[[self class] alloc] initWithAssembly:assembly];
}

/* ============================================================ Initializers ============================================================ */
- (id)initWithAssembly:(TyphoonAssembly*)assembly;
{
Expand Down
3 changes: 1 addition & 2 deletions Source/Utils/Resource/TyphoonBundleResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
*/
@interface TyphoonBundleResource : NSObject <TyphoonResource>
{
NSString* _stringValue;
NSData* _data;
}



+ (id<TyphoonResource>)withName:(NSString*)name;

- (id)initWithStringValue:(NSString*)stringValue;

@end
22 changes: 14 additions & 8 deletions Source/Utils/Resource/TyphoonBundleResource.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ @implementation TyphoonBundleResource
/* =========================================================== Class Methods ============================================================ */
+ (id <TyphoonResource>)withName:(NSString*)name
{

NSString* contents;
NSString* filePath;
NSRange lastDot = [name rangeOfString:@"." options:NSBackwardsSearch];
if (lastDot.location != NSNotFound)
Expand All @@ -37,25 +35,33 @@ @implementation TyphoonBundleResource
{
[NSException raise:NSInvalidArgumentException format:@"Resource named '%@' not in bundle.", name];
}
contents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
return [[[self class] alloc] initWithStringValue:contents];
return [[[self class] alloc] initWithData:[NSData dataWithContentsOfFile:filePath]];
}

/* ============================================================ Initializers ============================================================ */
- (id)initWithStringValue:(NSString*)stringValue
- (id)initWithData:(NSData*)data
{
self = [super init];
if (self)
{
_stringValue = stringValue;
_data = data;
}

return self;
}

- (NSString*)asString
{
return _stringValue;
return [self asStringWithEncoding:NSUTF8StringEncoding];
}

- (NSString*)asStringWithEncoding:(NSStringEncoding)encoding
{
return [[NSString alloc] initWithData:_data encoding:encoding];
}

- (NSData*)data
{
return _data;
}


Expand Down
4 changes: 4 additions & 0 deletions Source/Utils/Resource/TyphoonResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@

- (NSString*)asString;

- (NSString*)asStringWithEncoding:(NSStringEncoding)encoding;

- (NSData*)data;


@end
2 changes: 0 additions & 2 deletions Tests/Factory/TyphoonComponentFactory+InstanceBuilderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
////////////////////////////////////////////////////////////////////////////////

#import <SenTestingKit/SenTestingKit.h>
#import <objc/runtime.h>
#import "Typhoon.h"
#import "Knight.h"
#import "CampaignQuest.h"
#import "TyphoonInitializer.h"


@interface ComponentDefinition_InstanceBuilderTests : SenTestCase
Expand Down

0 comments on commit 66af9c2

Please sign in to comment.