Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #283 from octokit/nested-objects
Browse files Browse the repository at this point in the history
Set the baseURL for nested objects
  • Loading branch information
joshaber committed Oct 6, 2015
2 parents a0194fc + 4328141 commit 852a11e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
17 changes: 17 additions & 0 deletions OctoKit/OCTObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ - (void)setBaseURL:(NSURL *)baseURL {
NSString *baseURLString = [NSString stringWithFormat:@"%@://%@", baseURL.scheme, baseURL.host];
self.server = [OCTServer serverWithBaseURL:[NSURL URLWithString:baseURLString]];
}

// Also set the base URL for any nested objects.
for (NSString *propertyKey in self.class.JSONKeyPathsByPropertyKey) {
id value = [self valueForKey:propertyKey];
if ([value isKindOfClass:OCTObject.class]) {
OCTObject *object = value;
object.baseURL = baseURL;
} else if ([value conformsToProtocol:@protocol(NSFastEnumeration)]) {
id<NSFastEnumeration> enumerator = value;
for (id value in enumerator) {
if ([value isKindOfClass:OCTObject.class]) {
OCTObject *object = value;
object.baseURL = baseURL;
}
}
}
}
}

- (BOOL)validateObjectID:(id *)objectID error:(NSError **)error {
Expand Down
9 changes: 1 addition & 8 deletions OctoKit/OCTPullRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//

#import "OCTPullRequest.h"

#import "OCTUser.h"
#import "OCTRepository.h"
#import "NSValueTransformer+OCTPredefinedTransformerAdditions.h"
#import "OCTObject+Private.h"

@implementation OCTPullRequest

Expand Down Expand Up @@ -102,11 +102,4 @@ + (NSValueTransformer *)baseRepositoryJSONTransformer {
return [MTLValueTransformer mtl_JSONDictionaryTransformerWithModelClass:OCTRepository.class];
}

- (void)setBaseURL:(NSURL *)baseURL {
super.baseURL = baseURL;

self.headRepository.baseURL = baseURL;
self.baseRepository.baseURL = baseURL;
}

@end
1 change: 1 addition & 0 deletions OctoKit/OCTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "OCTRepository.h"

#import "NSValueTransformer+OCTPredefinedTransformerAdditions.h"

static NSString *const OCTRepositoryHTMLIssuesPath = @"issues";
Expand Down
8 changes: 8 additions & 0 deletions OctoKitTests/OCTRepositorySpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <Quick/Quick.h>

#import "OCTObjectSpec.h"
#import "OCTObject+Private.h"

QuickSpecBegin(OCTRepositorySpec)

Expand Down Expand Up @@ -135,6 +136,13 @@
expect(repository.forkParent).notTo(beNil());
expect(repository.forkParent.objectID).to(equal(@"1296267"));
});

it(@"should set its nested OCTObjects' servers", ^{
NSURL *URL = [NSURL URLWithString:@"https://myserver.com"];
repository.baseURL = URL;
expect(repository.forkParent.baseURL).to(equal(URL));
expect(repository.forkSource.baseURL).to(equal(URL));
});
});

it(@"should migrate from pre-MTLModel OCTObject", ^{
Expand Down

0 comments on commit 852a11e

Please sign in to comment.