Skip to content

Commit

Permalink
Adding the ability of having a prefix on local classes that we won't …
Browse files Browse the repository at this point in the history
…have on remote classes

(cherry picked from commit 0bc678a)
  • Loading branch information
lgalabru authored and vickeryj committed Jul 29, 2009
1 parent 1d79765 commit 051cfa5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Classes/lib/NSObject+ObjectiveResource.h
Expand Up @@ -33,6 +33,9 @@ typedef enum {
+ (void)setRemoteResponseType:(ORSResponseFormat) format;
+ (ORSResponseFormat)getRemoteResponseType;

// Prefix additions
+ (NSString *)getLocalClassesPrefix;
+ (void)setLocalClassesPrefix:(NSString *)prefix;

// Finders
+ (NSArray *)findAllRemote;
Expand Down
23 changes: 21 additions & 2 deletions Classes/lib/NSObject+ObjectiveResource.m
Expand Up @@ -20,6 +20,8 @@
static SEL _activeResourceSerializeMethod = nil;
static NSString *_activeResourceProtocolExtension = @".xml";
static ORSResponseFormat _format;
static NSString *_activeResourcePrefix = nil;


@implementation NSObject (ObjectiveResource)

Expand Down Expand Up @@ -104,6 +106,17 @@ + (void)setRemoteProtocolExtension:(NSString *)protocolExtension {
}
}

// Prefix additions
+ (NSString *)getLocalClassesPrefix {
return _activeResourcePrefix;
}

+ (void)setLocalClassesPrefix:(NSString *)prefix {
if (prefix != _activeResourcePrefix) {
[_activeResourcePrefix autorelease];
_activeResourcePrefix = [prefix copy];
}
}

// Find all items
+ (NSArray *)findAllRemoteWithResponse:(NSError **)aError {
Expand Down Expand Up @@ -133,8 +146,14 @@ + (id)findRemote:(NSString *)elementId {
}

+ (NSString *)getRemoteElementName {
return [[NSStringFromClass([self class]) stringByReplacingCharactersInRange:NSMakeRange(0, 1)
withString:[[NSStringFromClass([self class]) substringWithRange:NSMakeRange(0,1)] lowercaseString]] underscore];
NSString * remoteElementName = NSStringFromClass([self class]);
if (_activeResourcePrefix != nil) {
remoteElementName = [remoteElementName substringFromIndex:[_activeResourcePrefix length]];
}
return [[remoteElementName stringByReplacingCharactersInRange:NSMakeRange(0, 1)
withString:[[remoteElementName substringWithRange:NSMakeRange(0, 1)]
lowercaseString]]
underscore];
}

+ (NSString *)getRemoteCollectionName {
Expand Down
2 changes: 2 additions & 0 deletions Classes/lib/ObjectiveResourceConfig.h
Expand Up @@ -24,5 +24,7 @@
+ (void)setProtocolExtension:(NSString *)protocolExtension;
+ (void)setResponseType:(ORSResponseFormat) format;
+ (ORSResponseFormat)getResponseType;
+ (NSString *)getLocalClassesPrefix;
+ (void)setLocalClassesPrefix:(NSString *)prefix;

@end

0 comments on commit 051cfa5

Please sign in to comment.