Permalink
Browse files

Initial commit

  • Loading branch information...
casademora committed Jul 28, 2010
0 parents commit 738628f400fbe6fde8cc77adf68abb3fd709a3a2
@@ -0,0 +1,15 @@
+.DS_Store
+*.swp
+*~.nib
+
+build/
+
+*.pbxuser
+*.perspective
+*.perspectivev3
+
+.hg
+.hgtags
+
+*.mode1v3
+*.mode2v3
@@ -0,0 +1,26 @@
+//
+// ActiveRecordHelpers.h
+// DocBook
+//
+// Created by Saul Mora on 3/11/10.
+// Copyright 2010 Willow Tree Mobile, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface ActiveRecordHelpers : NSObject {
+
+}
+
++ (void) cleanUp;
+
++ (void) handleErrors:(NSError *)error;
+- (void) handleErrors:(NSError *)error;
+
++ (void) setupDefaultCoreDataStack;
++ (void) setupCoreDataStackWithInMemoryStore;
++ (void) setupDefaultCoreDataStackWithStoreNamed:(NSString *)storeName;
++ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;
+
+@end
@@ -0,0 +1,96 @@
+//
+// ActiveRecordHelpers.m
+// DocBook
+//
+// Created by Saul Mora on 3/11/10.
+// Copyright 2010 Willow Tree Mobile, Inc. All rights reserved.
+//
+
+#import "ActiveRecordHelpers.h"
+#import "NSManagedObjectContext+ActiveRecord.h"
+#import "NSPersistentStoreCoordinator+ActiveRecord.h"
+#import "NSManagedObjectModel+ActiveRecord.h"
+#import "NSPersistentStore+ActiveRecord.h"
+
+@implementation ActiveRecordHelpers
+
++ (void) cleanUp
+{
+ [NSManagedObjectContext setDefaultContext:nil];
+ [NSManagedObjectModel setDefaultManagedObjectModel:nil];
+ [NSPersistentStoreCoordinator setDefaultStoreCoordinator:nil];
+ [NSPersistentStore setDetaultPersistentStore:nil];
+}
+
++ (void) handleErrors:(NSError *)error
+{
+ if (error)
+ {
+ // NSLog(@"NSManagedObjectContext errors: %@", error);
+ // NSLog(@"Details: %@", [error userInfo]);
+ NSDictionary *userInfo = [error userInfo];
+ for (NSArray *detailedError in [userInfo allValues])
+ {
+ if ([detailedError isKindOfClass:[NSArray class]])
+ {
+ for (NSError *e in detailedError)
+ {
+ if ([e respondsToSelector:@selector(userInfo)])
+ {
+ NSLog(@"Error Details: %@", [e userInfo]);
+ }
+ else
+ {
+ NSLog(@"Error Details: %@", e);
+ }
+ }
+ }
+ else
+ {
+ NSLog(@"Error: %@", detailedError);
+ }
+ }
+ NSLog(@"Error Domain: %@", [error domain]);
+ NSLog(@"Recovery Suggestion: %@", [error localizedRecoverySuggestion]);
+ }
+}
+
+- (void) handleErrors:(NSError *)error
+{
+ [[self class] handleErrors:error];
+}
+
++ (void) setupDefaultCoreDataStack
+{
+ NSManagedObjectContext *context = [NSManagedObjectContext context];
+ [NSManagedObjectContext setDefaultContext:context];
+}
+
++ (void) setupDefaultCoreDataStackWithStoreNamed:(NSString *)storeName
+{
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithSqliteStoreNamed:storeName];
+ [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator];
+
+ NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator];
+ [NSManagedObjectContext setDefaultContext:context];
+}
+
++ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName
+{
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithAutoMigratingSqliteStoreNamed:storeName];
+ [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator];
+
+ NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator];
+ [NSManagedObjectContext setDefaultContext:context];
+}
+
++ (void) setupCoreDataStackWithInMemoryStore
+{
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithInMemoryStore];
+ [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator];
+
+ NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator];
+ [NSManagedObjectContext setDefaultContext:context];
+}
+
+@end
@@ -0,0 +1,7 @@
+
+#import "ActiveRecordHelpers.h"
+#import "NSManagedObject+ActiveRecord.h"
+#import "NSManagedObjectContext+ActiveRecord.h"
+#import "NSPersistentStoreCoordinator+ActiveRecord.h"
+#import "NSManagedObjectModel+ActiveRecord.h"
+#import "NSPersistentStore+ActiveRecord.h"
22 LICENSE
@@ -0,0 +1,22 @@
+ Copyright (c) 2010, Magical Panda Software, LLC
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,84 @@
+//
+// CARDBase.h
+// Freshpod
+//
+// Created by Saul Mora on 11/15/09.
+// Copyright 2009 Magical Panda Software, LLC. All rights reserved.
+//
+
+#import <CoreData/CoreData.h>
+#import "ActiveRecordHelpers.h"
+
+#define kActiveRecordDefaultBatchSize 6
+
+@interface NSManagedObject (ActiveRecord)
+
++ (void) handleErrors:(NSError *)error;
+
++ (NSArray *) executeFetchRequest:(NSFetchRequest *)request;
++ (NSArray *) executeFetchRequest:(NSFetchRequest *)request inContext:(NSManagedObjectContext *)context;
++ (NSFetchRequest *)createFetchRequest;
++ (NSFetchRequest *)createFetchRequestInContext:(NSManagedObjectContext *)context;
++ (NSEntityDescription *)entityDescription;
++ (NSEntityDescription *)entityDescriptionInContext:(NSManagedObjectContext *)context;
++ (NSArray *)propertiesNamed:(NSArray *)properties;
+
++ (id) createEntity;
++ (id) createInContext:(NSManagedObjectContext *)context;
+- (BOOL) deleteEntity;
+- (BOOL) deleteInContext:(NSManagedObjectContext *)context;
+
++ (NSArray *) ascendingSortDescriptors:(id)attributesToSortBy, ...;
++ (NSArray *) descendingSortDescriptors:(id)attributesToSortyBy, ...;
+
++ (NSNumber *) numberOfEntities;
++ (NSNumber *) numberOfEntitiesWithContext:(NSManagedObjectContext *)context;
++ (NSNumber *) numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm;
++ (NSNumber *) numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;
+
++ (NSFetchRequest *) requestAll;
++ (NSFetchRequest *) requestAllInContext:(NSManagedObjectContext *)context;
++ (NSFetchRequest *) requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending;
++ (NSFetchRequest *) requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context;
++ (NSFetchRequest *) requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm;
++ (NSFetchRequest *) requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;
+
++ (NSArray *)findAll;
++ (NSArray *)findAllInContext:(NSManagedObjectContext *)context;
++ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending;
++ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context;
++ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm;
++ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;
++ (NSFetchRequest *) requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;
+
++ (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm;
++ (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;
+
+- (id) objectWithMinValueFor:(NSString *)property;
+- (id) objectWithMinValueFor:(NSString *)property inContext:(NSManagedObjectContext *)context;
+
++ (id)findFirst;
++ (id)findFirstInContext:(NSManagedObjectContext *)context;
++ (id)findFirstWithPredicate:(NSPredicate *)searchterm sortedBy:(NSString *)property ascending:(BOOL)ascending;
++ (id)findFirstWithPredicate:(NSPredicate *)searchterm sortedBy:(NSString *)property ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context;
++ (id)findFirstWithPredicate:(NSPredicate *)searchTerm andRetrieveAttributes:(NSArray *)attributes;
++ (id)findFirstWithPredicate:(NSPredicate *)searchTerm andRetrieveAttributes:(NSArray *)attributes inContext:(NSManagedObjectContext *)context;
++ (id) findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortBy ascending:(BOOL)ascending andRetrieveAttributes:(id)attributes, ...;
++ (id) findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortBy ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context andRetrieveAttributes:(id)attributes, ...;
+
++ (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue;
++ (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context;
++ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue;
++ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context;
++ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending;
++ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context;
+
+#if TARGET_OS_IPHONE
++ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath;
++ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath inContext:(NSManagedObjectContext *)context;
+
++ (NSFetchedResultsController *) fetchRequest:(NSFetchRequest *)request groupedBy:(NSString *)group;
++ (NSFetchedResultsController *) fetchRequest:(NSFetchRequest *)request groupedBy:(NSString *)group inContext:(NSManagedObjectContext *)context;
+#endif
+
+@end
Oops, something went wrong.

0 comments on commit 738628f

Please sign in to comment.