Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a couple of minor bugs. #2

Merged
merged 1 commit into from Oct 7, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 27 additions & 27 deletions RestfulCappuccino.j
Expand Up @@ -43,15 +43,15 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
}

+ (void)addObserver:(id)anObserver
{
{
var center = [CPNotificationCenter defaultCenter];
if ([anObserver respondsToSelector:@selector(resourceWillLoad:)])

if ([anObserver respondsToSelector:@selector(resourceWillLoad:)])
{
[center removeObserver:anObserver name:CappuccinoRestfulResourceWillLoad object:self];
[center addObserver:anObserver selector:@selector(resourceWillLoad:) name:CappuccinoRestfulResourceWillLoad object:self];
}
if ([anObserver respondsToSelector:@selector(resourceDidLoad:)])
if ([anObserver respondsToSelector:@selector(resourceDidLoad:)])
{
[center removeObserver:anObserver name:RestfulCappuccinoResourceDidLoad object:self];
[center addObserver:anObserver selector:@selector(resourceDidLoad:) name:RestfulCappuccinoResourceDidLoad object:self];
Expand All @@ -60,12 +60,12 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
{
[center removeObserver:anObserver name:RestfulCappuccinoResourcesWillLoad object:self];
[center addObserver:anObserver selector:@selector(resourcesWillLoad:) name:RestfulCappuccinoResourcesWillLoad object:self];
}
if ([anObserver respondsToSelector:@selector(resourcesDidLoad:)])
}
if ([anObserver respondsToSelector:@selector(resourcesDidLoad:)])
{
[center removeObserver:anObserver name:RestfulCappuccinoResourcesDidLoad object:self];
[center addObserver:anObserver selector:@selector(resourcesDidLoad:) name:RestfulCappuccinoResourcesDidLoad object:self];
}
}
if ([anObserver respondsToSelector:@selector(resourceWillSave:)])
{
[center removeObserver:anObserver name:RestfulCappuccinoResourceWillSave object:self];
Expand Down Expand Up @@ -190,22 +190,22 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
[self setValue:value forKey:attributeName];
}
break;
case "object":
if (value == null)
case "object":
if (value == null)
{
[self setValue:nil forKey:attributeName];
[self setValue:nil forKey:attributeName];
}
else if (value.length != null)
{
var childs = [CPArray array];
var childs = [CPArray array];
for (var i=0; i<value.length; i++)
{
var child = [CPClassFromString([self className]) new:value[i]];
var child = [CPClassFromString([self className]) new:value[i]];
[childs addObject:child];
}
[self setValue:childs forKey:attributeName];
}
[self setValue:childs forKey:attributeName];
}

break;
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro

@implementation RestfulCappuccino (CRUD)
{

}

+ (CPArray)all
Expand Down Expand Up @@ -320,7 +320,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
+ (void)createAsyncWithParameters:(JSObject)parameters andRequestor:(id)theRequestor
{
var resource = [self new:attributes];
[resource saveAsyncWitRequestor:theRequestor];
[resource saveAsyncWithRequestor:theRequestor];
}

- (BOOL)save
Expand Down Expand Up @@ -348,7 +348,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro

- (void)saveAsync
{
[self saveAsyncWitRequestor:nil];
[self saveAsyncWithRequestor:nil];
}

- (void)saveAsyncWithRequestor:(id)theRequestor
Expand Down Expand Up @@ -405,7 +405,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
connection.requestor = theRequestor;
connection.eventType = request.eventType;
connection.modelTarget = self;
[connection start];
[connection start];
}

+ (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)aResponse
Expand All @@ -431,7 +431,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro

@implementation RestfulCappuccino (Notifications)
{

}

/*
Expand Down Expand Up @@ -472,7 +472,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
attributes = response[[self railsName]],
//notificationName = [self className] + "ResourceDidLoad",
resource = [self new];
[resource setAttributes:attributes];
[resource setAttributes:attributes];
[[CPNotificationCenter defaultCenter] postNotificationName:RestfulCappuccinoResourceDidLoad object:resource];
return resource;
}
Expand All @@ -485,7 +485,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
+ (CPURLRequest)resourcesWillLoadWithParameters:(id)params andRequestor:(id)theRequestor
{
var path = [self resourcePath];

if (params) {
if (params.isa && [params isKindOfClass:CPDictionary]) {
path += ("?" + [CPString paramaterStringFromCPDictionary:params]);
Expand Down Expand Up @@ -532,7 +532,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
else
{
[resourceArray addObject:[self new:collection]];
}
}
}
[notificationInfo setRequestor:theRequestor];
[notificationInfo setModelName:[self className]];
Expand Down Expand Up @@ -575,7 +575,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
{
[notificationInfo setRequestor:theRequestor];
[notificationInfo setModelName:[self className]];

if ([aResponse length] > 1)
{
var response = [aResponse toJSON],
Expand All @@ -598,7 +598,7 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
[notificationInfo setRequestor:theRequestor];
[notificationInfo setModelName:[self className]];
[notificationInfo setEventData:aResponse];

// TODO - do something with errors
if (identifier) {
[notificationInfo setEventType:@"Update"];
Expand Down Expand Up @@ -645,8 +645,8 @@ RestfulCappuccinoResourceDidNotDestroy = @"RestfulCappuccinoResourceDidNotDestro
[notificationInfo setModelName:[self className]];
[notificationInfo setEventData:[identifier]];
[notificationInfo setEventType:@"Delete"];

[[CPNotificationCenter defaultCenter] postNotificationName:RestfulCappuccinoResourceDidNotDestroy object:self];
}

@end
@end