-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGemSpecs.m
56 lines (49 loc) · 1.41 KB
/
GemSpecs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// GemSpecs.m
// goo
//
// Created by Robin Lu on 8/21/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "GemSpecs.h"
@interface GemSpecs (Private)
- (void)sort;
@end
@implementation GemSpecs
@synthesize gemSpecIndex;
- (id)init
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"gem_helper" ofType:@"rb"];
NSTask *task = [[[NSTask alloc] init] autorelease];
[task setLaunchPath:@"/bin/bash"];
NSArray *arguments = [NSArray arrayWithObjects:@"-l", @"-c", path, nil];
[task setArguments:arguments];
NSPipe *outPipe = [[NSPipe alloc] init];
[task setStandardOutput:outPipe];
[outPipe release];
[task launch];
NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile];
NSPropertyListFormat format;
NSString *error;
gemSpecIndex = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error];
if (!gemSpecIndex)
NSLog(@"%@", error);
[self sort];
return self;
}
- (void)sort
{
NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"version" ascending:NO];
NSMutableArray * sda = [[NSMutableArray alloc] init];
[sda addObject:sd];
[sda addObject:sd2];
gemSpecIndex = [gemSpecIndex sortedArrayUsingDescriptors:sda];
[sda release];
[sd release];
[sd2 release];
}
@end