appjam 0.1.8.6 → 0.1.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appjam.rb +1 -1
- data/lib/appjam/generators/blank.rb +133 -0
- data/lib/appjam/generators/help.rb +5 -3
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +855 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/EiffelApplication.xcscheme +96 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +156 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +45 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +30 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.h +636 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.m +1359 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.m +318 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.h +108 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.m +234 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.m +142 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.m +145 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworking.h +43 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.m +142 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.h +379 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.m +818 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.m +166 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.m +184 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.h +251 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.m +3067 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.h +155 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.m +1162 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.h +37 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.m +163 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.m +244 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m +176 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h +104 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m +413 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.h +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.m +370 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.h +41 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.m +99 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.h +334 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.m +1353 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.h +601 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.m +1083 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.h +167 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.m +1479 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.h +33 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.m +122 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.h +72 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.m +305 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.h +57 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.m +188 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.h +89 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.m +261 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore-Prefix.pch +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.h +50 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.m +100 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/main.m.tt +18 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +13 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +32 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/en.lproj/InfoPlist.strings +2 -0
- data/lib/appjam/generators/templates/resources/Default-568h@2x.png +0 -0
- data/lib/appjam/generators/templates/resources/Default.png +0 -0
- data/lib/appjam/generators/templates/resources/Default@2x.png +0 -0
- data/lib/appjam/generators/templates/resources/contents.tt +4 -0
- data/lib/appjam/version.rb +1 -1
- metadata +462 -326
- data/test/helper.rb +0 -132
- data/test/test_model_generator.rb +0 -28
- data/test/test_project_generator.rb +0 -38
data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
//
|
2
|
+
// USConstants.h
|
3
|
+
// Underscore
|
4
|
+
//
|
5
|
+
// Created by Robert Böhnke on 5/14/12.
|
6
|
+
// Copyright (C) 2012 Robert Böhnke
|
7
|
+
//
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
// of this software and associated documentation files (the "Software"), to
|
10
|
+
// deal in the Software without restriction, including without limitation the
|
11
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
13
|
+
// furnished to do so, subject to the following conditions:
|
14
|
+
//
|
15
|
+
// The above copyright notice and this permission notice shall be included in
|
16
|
+
// all copies or substantial portions of the Software.
|
17
|
+
//
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
24
|
+
// IN THE SOFTWARE.
|
25
|
+
//
|
26
|
+
|
27
|
+
#import <Foundation/Foundation.h>
|
28
|
+
|
29
|
+
typedef BOOL (^UnderscoreTestBlock)(id obj);
|
30
|
+
typedef id (^UnderscoreReduceBlock)(id memo, id obj);
|
31
|
+
|
32
|
+
typedef void (^UnderscoreArrayIteratorBlock)(id obj);
|
33
|
+
typedef id (^UnderscoreArrayMapBlock)(id obj);
|
34
|
+
|
35
|
+
typedef void (^UnderscoreDictionaryIteratorBlock)(id key, id obj);
|
36
|
+
typedef id (^UnderscoreDictionaryMapBlock)(id key, id obj);
|
37
|
+
|
38
|
+
typedef NSComparisonResult (^UnderscoreSortBlock)(id a, id b);
|
@@ -0,0 +1,57 @@
|
|
1
|
+
//
|
2
|
+
// USDictionaryWrapper.h
|
3
|
+
// Underscore
|
4
|
+
//
|
5
|
+
// Created by Robert Böhnke on 5/14/12.
|
6
|
+
// Copyright (C) 2012 Robert Böhnke
|
7
|
+
//
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
// of this software and associated documentation files (the "Software"), to
|
10
|
+
// deal in the Software without restriction, including without limitation the
|
11
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
13
|
+
// furnished to do so, subject to the following conditions:
|
14
|
+
//
|
15
|
+
// The above copyright notice and this permission notice shall be included in
|
16
|
+
// all copies or substantial portions of the Software.
|
17
|
+
//
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
24
|
+
// IN THE SOFTWARE.
|
25
|
+
//
|
26
|
+
|
27
|
+
#import <Foundation/Foundation.h>
|
28
|
+
|
29
|
+
#import "USArrayWrapper.h"
|
30
|
+
|
31
|
+
#import "USConstants.h"
|
32
|
+
|
33
|
+
@interface USDictionaryWrapper : NSObject
|
34
|
+
|
35
|
+
+ (USDictionaryWrapper *)wrap:(NSDictionary *)dictionary;
|
36
|
+
- (NSDictionary *)unwrap;
|
37
|
+
|
38
|
+
- (id)init __attribute__((deprecated("You should Underscore.dict() instead")));
|
39
|
+
|
40
|
+
@property (readonly) USArrayWrapper *keys;
|
41
|
+
@property (readonly) USArrayWrapper *values;
|
42
|
+
|
43
|
+
@property (readonly) USDictionaryWrapper *(^each)(UnderscoreDictionaryIteratorBlock block);
|
44
|
+
@property (readonly) USDictionaryWrapper *(^map)(UnderscoreDictionaryMapBlock block);
|
45
|
+
|
46
|
+
@property (readonly) USDictionaryWrapper *(^pick)(NSArray *keys);
|
47
|
+
|
48
|
+
@property (readonly) USDictionaryWrapper *(^extend)(NSDictionary *source);
|
49
|
+
@property (readonly) USDictionaryWrapper *(^defaults)(NSDictionary *defaults);
|
50
|
+
|
51
|
+
@property (readonly) USDictionaryWrapper *(^filterKeys)(UnderscoreTestBlock block);
|
52
|
+
@property (readonly) USDictionaryWrapper *(^filterValues)(UnderscoreTestBlock block);
|
53
|
+
|
54
|
+
@property (readonly) USDictionaryWrapper *(^rejectKeys)(UnderscoreTestBlock block);
|
55
|
+
@property (readonly) USDictionaryWrapper *(^rejectValues)(UnderscoreTestBlock block);
|
56
|
+
|
57
|
+
@end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
//
|
2
|
+
// USDictionaryWrapper.m
|
3
|
+
// Underscore
|
4
|
+
//
|
5
|
+
// Created by Robert Böhnke on 5/14/12.
|
6
|
+
// Copyright (C) 2012 Robert Böhnke
|
7
|
+
//
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
// of this software and associated documentation files (the "Software"), to
|
10
|
+
// deal in the Software without restriction, including without limitation the
|
11
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
13
|
+
// furnished to do so, subject to the following conditions:
|
14
|
+
//
|
15
|
+
// The above copyright notice and this permission notice shall be included in
|
16
|
+
// all copies or substantial portions of the Software.
|
17
|
+
//
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
24
|
+
// IN THE SOFTWARE.
|
25
|
+
//
|
26
|
+
|
27
|
+
#import "Underscore.h"
|
28
|
+
|
29
|
+
#import "USDictionaryWrapper.h"
|
30
|
+
|
31
|
+
@interface USDictionaryWrapper ()
|
32
|
+
|
33
|
+
- initWithDictionary:(NSDictionary *)dictionary;
|
34
|
+
|
35
|
+
@property (readwrite, retain) NSDictionary *dictionary;
|
36
|
+
|
37
|
+
@end
|
38
|
+
|
39
|
+
@implementation USDictionaryWrapper
|
40
|
+
|
41
|
+
#pragma mark Class methods
|
42
|
+
|
43
|
+
+ (USDictionaryWrapper *)wrap:(NSDictionary *)dictionary
|
44
|
+
{
|
45
|
+
return [[USDictionaryWrapper alloc] initWithDictionary:[dictionary copy]];
|
46
|
+
}
|
47
|
+
|
48
|
+
#pragma mark Lifecycle
|
49
|
+
|
50
|
+
- (id)init
|
51
|
+
{
|
52
|
+
return [super init];
|
53
|
+
}
|
54
|
+
|
55
|
+
- (id)initWithDictionary:(NSDictionary *)dictionary
|
56
|
+
{
|
57
|
+
if (self = [super init]) {
|
58
|
+
self.dictionary = dictionary;
|
59
|
+
}
|
60
|
+
return self;
|
61
|
+
}
|
62
|
+
@synthesize dictionary = _dictionary;
|
63
|
+
|
64
|
+
- (NSDictionary *)unwrap
|
65
|
+
{
|
66
|
+
return [self.dictionary copy];
|
67
|
+
}
|
68
|
+
|
69
|
+
#pragma mark Underscore methods
|
70
|
+
|
71
|
+
- (USArrayWrapper *)keys
|
72
|
+
{
|
73
|
+
return [USArrayWrapper wrap:self.dictionary.allKeys];
|
74
|
+
}
|
75
|
+
|
76
|
+
- (USArrayWrapper *)values
|
77
|
+
{
|
78
|
+
return [USArrayWrapper wrap:self.dictionary.allValues];
|
79
|
+
}
|
80
|
+
|
81
|
+
- (USDictionaryWrapper *(^)(UnderscoreDictionaryIteratorBlock))each
|
82
|
+
{
|
83
|
+
return ^USDictionaryWrapper *(UnderscoreDictionaryIteratorBlock block) {
|
84
|
+
[self.dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
85
|
+
block(key, obj);
|
86
|
+
}];
|
87
|
+
|
88
|
+
return self;
|
89
|
+
};
|
90
|
+
}
|
91
|
+
|
92
|
+
- (USDictionaryWrapper *(^)(UnderscoreDictionaryMapBlock))map
|
93
|
+
{
|
94
|
+
return ^USDictionaryWrapper *(UnderscoreDictionaryMapBlock block) {
|
95
|
+
NSMutableDictionary *result = [NSMutableDictionary dictionary];
|
96
|
+
|
97
|
+
[self.dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
98
|
+
id mapped = block(key, obj);
|
99
|
+
|
100
|
+
if (mapped) {
|
101
|
+
[result setObject:mapped
|
102
|
+
forKey:key];
|
103
|
+
}
|
104
|
+
}];
|
105
|
+
|
106
|
+
return [[USDictionaryWrapper alloc] initWithDictionary:result];
|
107
|
+
};
|
108
|
+
}
|
109
|
+
|
110
|
+
- (USDictionaryWrapper *(^)(NSArray *))pick
|
111
|
+
{
|
112
|
+
return ^USDictionaryWrapper *(NSArray *keys) {
|
113
|
+
__block NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:keys.count];
|
114
|
+
|
115
|
+
[self.dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
116
|
+
if ([keys containsObject:key]) {
|
117
|
+
[result setObject:obj
|
118
|
+
forKey:key];
|
119
|
+
}
|
120
|
+
}];
|
121
|
+
|
122
|
+
return [[USDictionaryWrapper alloc] initWithDictionary:result];
|
123
|
+
};
|
124
|
+
}
|
125
|
+
|
126
|
+
- (USDictionaryWrapper *(^)(NSDictionary *))extend
|
127
|
+
{
|
128
|
+
return ^USDictionaryWrapper *(NSDictionary *source) {
|
129
|
+
__block NSMutableDictionary *result = [self.dictionary mutableCopy];
|
130
|
+
|
131
|
+
[source enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
132
|
+
[result setObject:obj
|
133
|
+
forKey:key];
|
134
|
+
}];
|
135
|
+
|
136
|
+
return [[USDictionaryWrapper alloc] initWithDictionary:result];
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
140
|
+
- (USDictionaryWrapper *(^)(NSDictionary *))defaults
|
141
|
+
{
|
142
|
+
return ^USDictionaryWrapper *(NSDictionary *source) {
|
143
|
+
__block NSMutableDictionary *result = [self.dictionary mutableCopy];
|
144
|
+
|
145
|
+
[source enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
146
|
+
if (![result valueForKey:key]) {
|
147
|
+
[result setObject:obj
|
148
|
+
forKey:key];
|
149
|
+
}
|
150
|
+
}];
|
151
|
+
|
152
|
+
return [[USDictionaryWrapper alloc] initWithDictionary:result];
|
153
|
+
};
|
154
|
+
}
|
155
|
+
|
156
|
+
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))filterKeys
|
157
|
+
{
|
158
|
+
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
|
159
|
+
return self.map(^id (id key, id obj) {
|
160
|
+
return test(key) ? obj : nil;
|
161
|
+
});
|
162
|
+
};
|
163
|
+
}
|
164
|
+
|
165
|
+
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))filterValues
|
166
|
+
{
|
167
|
+
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
|
168
|
+
return self.map(^id (id key, id obj) {
|
169
|
+
return test(obj) ? obj : nil;
|
170
|
+
});
|
171
|
+
};
|
172
|
+
}
|
173
|
+
|
174
|
+
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))rejectKeys
|
175
|
+
{
|
176
|
+
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
|
177
|
+
return self.filterKeys(Underscore.negate(test));
|
178
|
+
};
|
179
|
+
}
|
180
|
+
|
181
|
+
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))rejectValues
|
182
|
+
{
|
183
|
+
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
|
184
|
+
return self.filterValues(Underscore.negate(test));
|
185
|
+
};
|
186
|
+
}
|
187
|
+
|
188
|
+
@end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
//
|
2
|
+
// Underscore+Functional.h
|
3
|
+
// Underscore
|
4
|
+
//
|
5
|
+
// Created by Robert Böhnke on 7/15/12.
|
6
|
+
// Copyright (c) 2012 Robert Böhnke. All rights reserved.
|
7
|
+
//
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
// of this software and associated documentation files (the "Software"), to
|
10
|
+
// deal in the Software without restriction, including without limitation the
|
11
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
13
|
+
// furnished to do so, subject to the following conditions:
|
14
|
+
//
|
15
|
+
// The above copyright notice and this permission notice shall be included in
|
16
|
+
// all copies or substantial portions of the Software.
|
17
|
+
//
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
24
|
+
// IN THE SOFTWARE.
|
25
|
+
//
|
26
|
+
|
27
|
+
#import "Underscore.h"
|
28
|
+
|
29
|
+
@interface Underscore (FunctionalStyle)
|
30
|
+
|
31
|
+
#pragma mark NSArray functional style methods
|
32
|
+
|
33
|
+
+ (USArrayWrapper *(^)(NSArray *))array;
|
34
|
+
|
35
|
+
+ (id (^)(NSArray *))first;
|
36
|
+
+ (id (^)(NSArray *))last;
|
37
|
+
|
38
|
+
+ (NSArray *(^)(NSArray *array, NSUInteger n))head;
|
39
|
+
+ (NSArray *(^)(NSArray *array, NSUInteger n))tail;
|
40
|
+
|
41
|
+
+ (NSUInteger (^)(NSArray *array, id obj))indexOf;
|
42
|
+
|
43
|
+
+ (NSArray *(^)(NSArray *array))flatten;
|
44
|
+
+ (NSArray *(^)(NSArray *array, NSArray *values))without;
|
45
|
+
|
46
|
+
+ (NSArray *(^)(NSArray *array))shuffle;
|
47
|
+
|
48
|
+
+ (id (^)(NSArray *array, id memo, UnderscoreReduceBlock block))reduce;
|
49
|
+
+ (id (^)(NSArray *array, id memo, UnderscoreReduceBlock block))reduceRight;
|
50
|
+
|
51
|
+
+ (void (^)(NSArray *array, UnderscoreArrayIteratorBlock block))arrayEach;
|
52
|
+
+ (NSArray *(^)(NSArray *array, UnderscoreArrayMapBlock block))arrayMap;
|
53
|
+
|
54
|
+
+ (NSArray *(^)(NSArray *array, NSString *keyPath))pluck;
|
55
|
+
|
56
|
+
+ (NSArray *(^)(NSArray *array))uniq;
|
57
|
+
|
58
|
+
+ (id (^)(NSArray *array, UnderscoreTestBlock block))find;
|
59
|
+
|
60
|
+
+ (NSArray *(^)(NSArray *array, UnderscoreTestBlock block))filter;
|
61
|
+
+ (NSArray *(^)(NSArray *array, UnderscoreTestBlock block))reject;
|
62
|
+
|
63
|
+
+ (BOOL (^)(NSArray *array, UnderscoreTestBlock block))all;
|
64
|
+
+ (BOOL (^)(NSArray *array, UnderscoreTestBlock block))any;
|
65
|
+
|
66
|
+
+ (NSArray *(^)(NSArray *array, UnderscoreSortBlock block))sort;
|
67
|
+
|
68
|
+
#pragma mark NSDictionary style methods
|
69
|
+
|
70
|
+
+ (USDictionaryWrapper *(^)(NSDictionary *dictionary))dict;
|
71
|
+
|
72
|
+
+ (NSArray *(^)(NSDictionary *dictionary))keys;
|
73
|
+
+ (NSArray *(^)(NSDictionary *dictionary))values;
|
74
|
+
|
75
|
+
+ (void (^)(NSDictionary *dictionary, UnderscoreDictionaryIteratorBlock block))dictEach;
|
76
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreDictionaryMapBlock block))dictMap;
|
77
|
+
|
78
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, NSArray *keys))pick;
|
79
|
+
|
80
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, NSDictionary *source))extend;
|
81
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, NSDictionary *defaults))defaults;
|
82
|
+
|
83
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))filterKeys;
|
84
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))filterValues;
|
85
|
+
|
86
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))rejectKeys;
|
87
|
+
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))rejectValues;
|
88
|
+
|
89
|
+
@end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
//
|
2
|
+
// Underscore+Functional.m
|
3
|
+
// Underscore
|
4
|
+
//
|
5
|
+
// Created by Robert Böhnke on 7/15/12.
|
6
|
+
// Copyright (c) 2012 Robert Böhnke. All rights reserved.
|
7
|
+
//
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
// of this software and associated documentation files (the "Software"), to
|
10
|
+
// deal in the Software without restriction, including without limitation the
|
11
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
13
|
+
// furnished to do so, subject to the following conditions:
|
14
|
+
//
|
15
|
+
// The above copyright notice and this permission notice shall be included in
|
16
|
+
// all copies or substantial portions of the Software.
|
17
|
+
//
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
24
|
+
// IN THE SOFTWARE.
|
25
|
+
//
|
26
|
+
|
27
|
+
#import "Underscore+Functional.h"
|
28
|
+
|
29
|
+
@implementation Underscore (Functional)
|
30
|
+
|
31
|
+
#pragma mark NSArray shortcuts
|
32
|
+
|
33
|
+
+ (USArrayWrapper *(^)(NSArray *))array
|
34
|
+
{
|
35
|
+
return ^(NSArray *array) {
|
36
|
+
return [USArrayWrapper wrap:array];
|
37
|
+
};
|
38
|
+
}
|
39
|
+
|
40
|
+
+ (id (^)(NSArray *))first
|
41
|
+
{
|
42
|
+
return ^(NSArray *array) {
|
43
|
+
return Underscore.array(array).first;
|
44
|
+
};
|
45
|
+
}
|
46
|
+
|
47
|
+
+ (id (^)(NSArray *))last
|
48
|
+
{
|
49
|
+
return ^(NSArray *array) {
|
50
|
+
return Underscore.array(array).last;
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
+ (NSArray *(^)(NSArray *, NSUInteger))head
|
55
|
+
{
|
56
|
+
return ^(NSArray *array, NSUInteger n) {
|
57
|
+
return Underscore.array(array).head(n).unwrap;
|
58
|
+
};
|
59
|
+
}
|
60
|
+
|
61
|
+
+ (NSArray *(^)(NSArray *, NSUInteger))tail
|
62
|
+
{
|
63
|
+
return ^(NSArray *array, NSUInteger n) {
|
64
|
+
return Underscore.array(array).tail(n).unwrap;
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
+ (NSUInteger (^)(NSArray *, id))indexOf
|
69
|
+
{
|
70
|
+
return ^(NSArray *array, id obj) {
|
71
|
+
return Underscore.array(array).indexOf(obj);
|
72
|
+
};
|
73
|
+
}
|
74
|
+
|
75
|
+
+ (NSArray *(^)(NSArray *))flatten
|
76
|
+
{
|
77
|
+
return ^(NSArray *array) {
|
78
|
+
return Underscore.array(array).flatten.unwrap;
|
79
|
+
};
|
80
|
+
}
|
81
|
+
|
82
|
+
+ (NSArray *(^)(NSArray *))uniq
|
83
|
+
{
|
84
|
+
return ^(NSArray *array) {
|
85
|
+
return Underscore.array(array).uniq.unwrap;
|
86
|
+
};
|
87
|
+
}
|
88
|
+
|
89
|
+
+ (NSArray *(^)(NSArray *, NSArray *))without
|
90
|
+
{
|
91
|
+
return ^(NSArray *array, NSArray *values) {
|
92
|
+
return Underscore.array(array).without(values).unwrap;
|
93
|
+
};
|
94
|
+
}
|
95
|
+
|
96
|
+
+ (NSArray *(^)(NSArray *))shuffle
|
97
|
+
{
|
98
|
+
return ^(NSArray *array) {
|
99
|
+
return Underscore.array(array).shuffle.unwrap;
|
100
|
+
};
|
101
|
+
}
|
102
|
+
|
103
|
+
+(id (^)(NSArray *, id, UnderscoreReduceBlock))reduce
|
104
|
+
{
|
105
|
+
return ^(NSArray *array, id memo, UnderscoreReduceBlock block) {
|
106
|
+
return Underscore.array(array).reduce(memo, block);
|
107
|
+
};
|
108
|
+
}
|
109
|
+
|
110
|
+
+ (id (^)(NSArray *, id, UnderscoreReduceBlock))reduceRight
|
111
|
+
{
|
112
|
+
return ^(NSArray *array, id memo, UnderscoreReduceBlock block) {
|
113
|
+
return Underscore.array(array).reduceRight(memo, block);
|
114
|
+
};
|
115
|
+
}
|
116
|
+
|
117
|
+
+ (void (^)(NSArray *, UnderscoreArrayIteratorBlock))arrayEach
|
118
|
+
{
|
119
|
+
return ^(NSArray *array, UnderscoreArrayIteratorBlock block) {
|
120
|
+
Underscore.array(array).each(block);
|
121
|
+
};
|
122
|
+
}
|
123
|
+
|
124
|
+
+ (NSArray *(^)(NSArray *array, UnderscoreArrayMapBlock block))arrayMap
|
125
|
+
{
|
126
|
+
return ^(NSArray *array, UnderscoreArrayMapBlock block) {
|
127
|
+
return Underscore.array(array).map(block).unwrap;
|
128
|
+
};
|
129
|
+
}
|
130
|
+
|
131
|
+
+ (NSArray *(^)(NSArray *, NSString *))pluck
|
132
|
+
{
|
133
|
+
return ^(NSArray *array, NSString *keyPath) {
|
134
|
+
return Underscore.array(array).pluck(keyPath).unwrap;
|
135
|
+
};
|
136
|
+
}
|
137
|
+
|
138
|
+
+ (id (^)(NSArray *, UnderscoreTestBlock))find
|
139
|
+
{
|
140
|
+
return ^(NSArray *array, UnderscoreTestBlock block) {
|
141
|
+
return Underscore.array(array).find(block);
|
142
|
+
};
|
143
|
+
}
|
144
|
+
|
145
|
+
+ (NSArray *(^)(NSArray *, UnderscoreTestBlock))filter
|
146
|
+
{
|
147
|
+
return ^(NSArray *array, UnderscoreTestBlock block) {
|
148
|
+
return Underscore.array(array).filter(block).unwrap;
|
149
|
+
};
|
150
|
+
}
|
151
|
+
+ (NSArray *(^)(NSArray *, UnderscoreTestBlock))reject
|
152
|
+
{
|
153
|
+
return ^(NSArray *array, UnderscoreTestBlock block) {
|
154
|
+
return Underscore.array(array).reject(block).unwrap;
|
155
|
+
};
|
156
|
+
}
|
157
|
+
|
158
|
+
+ (BOOL (^)(NSArray *, UnderscoreTestBlock))all
|
159
|
+
{
|
160
|
+
return ^(NSArray *array, UnderscoreTestBlock block) {
|
161
|
+
return Underscore.array(array).all(block);
|
162
|
+
};
|
163
|
+
}
|
164
|
+
+ (BOOL (^)(NSArray *, UnderscoreTestBlock))any
|
165
|
+
{
|
166
|
+
return ^(NSArray *array, UnderscoreTestBlock block) {
|
167
|
+
return Underscore.array(array).any(block);
|
168
|
+
};
|
169
|
+
}
|
170
|
+
|
171
|
+
+ (NSArray *(^)(NSArray *, UnderscoreSortBlock))sort
|
172
|
+
{
|
173
|
+
return ^(NSArray *array, UnderscoreSortBlock block) {
|
174
|
+
return Underscore.array(array).sort(block).unwrap;
|
175
|
+
};
|
176
|
+
}
|
177
|
+
|
178
|
+
#pragma mark NSDictionary shortcuts
|
179
|
+
|
180
|
+
+ (USDictionaryWrapper *(^)(NSDictionary *))dict
|
181
|
+
{
|
182
|
+
return ^(NSDictionary *dictionary) {
|
183
|
+
return [USDictionaryWrapper wrap:dictionary];
|
184
|
+
};
|
185
|
+
}
|
186
|
+
|
187
|
+
+ (NSArray *(^)(NSDictionary *))keys
|
188
|
+
{
|
189
|
+
return ^(NSDictionary *dictionary) {
|
190
|
+
return [USDictionaryWrapper wrap:dictionary].keys.unwrap;
|
191
|
+
};
|
192
|
+
}
|
193
|
+
+ (NSArray *(^)(NSDictionary *))values
|
194
|
+
{
|
195
|
+
return ^(NSDictionary *dictionary) {
|
196
|
+
return [USDictionaryWrapper wrap:dictionary].values.unwrap;
|
197
|
+
};
|
198
|
+
}
|
199
|
+
|
200
|
+
+ (void (^)(NSDictionary *, UnderscoreDictionaryIteratorBlock))dictEach
|
201
|
+
{
|
202
|
+
return ^(NSDictionary *dictionary, UnderscoreDictionaryIteratorBlock block) {
|
203
|
+
Underscore.dict(dictionary).each(block);
|
204
|
+
};
|
205
|
+
}
|
206
|
+
|
207
|
+
+ (NSDictionary *(^)(NSDictionary *, UnderscoreDictionaryMapBlock))dictMap
|
208
|
+
{
|
209
|
+
return ^(NSDictionary *dictionary, UnderscoreDictionaryMapBlock block) {
|
210
|
+
return Underscore.dict(dictionary).map(block).unwrap;
|
211
|
+
};
|
212
|
+
}
|
213
|
+
|
214
|
+
+ (NSDictionary *(^)(NSDictionary *, NSArray *))pick
|
215
|
+
{
|
216
|
+
return ^(NSDictionary *dictionary, NSArray *keys) {
|
217
|
+
return [USDictionaryWrapper wrap:dictionary].pick(keys).unwrap;
|
218
|
+
};
|
219
|
+
}
|
220
|
+
|
221
|
+
+ (NSDictionary *(^)(NSDictionary *, NSDictionary *))extend
|
222
|
+
{
|
223
|
+
return ^(NSDictionary *dictionary, NSDictionary *source) {
|
224
|
+
return [USDictionaryWrapper wrap:dictionary].extend(source).unwrap;
|
225
|
+
};
|
226
|
+
}
|
227
|
+
+ (NSDictionary *(^)(NSDictionary *, NSDictionary *))defaults
|
228
|
+
{
|
229
|
+
return ^(NSDictionary *dictionary, NSDictionary *defaults) {
|
230
|
+
return [USDictionaryWrapper wrap:dictionary].defaults(defaults).unwrap;
|
231
|
+
};
|
232
|
+
}
|
233
|
+
|
234
|
+
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))filterKeys
|
235
|
+
{
|
236
|
+
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
|
237
|
+
return [USDictionaryWrapper wrap:dictionary].filterKeys(block).unwrap;
|
238
|
+
};
|
239
|
+
}
|
240
|
+
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))filterValues
|
241
|
+
{
|
242
|
+
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
|
243
|
+
return [USDictionaryWrapper wrap:dictionary].filterValues(block).unwrap;
|
244
|
+
};
|
245
|
+
}
|
246
|
+
|
247
|
+
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))rejectKeys
|
248
|
+
{
|
249
|
+
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
|
250
|
+
return [USDictionaryWrapper wrap:dictionary].rejectKeys(block).unwrap;
|
251
|
+
};
|
252
|
+
}
|
253
|
+
|
254
|
+
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))rejectValues
|
255
|
+
{
|
256
|
+
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
|
257
|
+
return [USDictionaryWrapper wrap:dictionary].rejectValues(block).unwrap;
|
258
|
+
};
|
259
|
+
}
|
260
|
+
|
261
|
+
@end
|