TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Lucas Medeiros Leite.
Depends on: | |
CouchCocoa | ~> 1.0 |
TouchDB | = 1.0 |
Mantle | ~> 1.0 |
Kiwi | ~> 2.0.6 |
ActiveTouch is an implementation of ActiveRecord using TouchDB-iOS (an implementation of CouchDB for iOS)
Developed by Lucas Medeiros
To install cocoapods you will need ruby.
gem install cocoapods
More information about cocoapods:
Add the dependency to your Podfile
:
platform :ios
...
pod 'ActiveTouch'
...
Run pod install
to install the dependencies.
#import "ATDatabaseContainer.h"
@implementation ATAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[ATDatabaseContainer sharedInstance] openDatabaseWithName:@"your_database_name"];
return YES;
}
#import <Foundation/Foundation.h>
#import "ATModel.h"
@interface Car : ATModel
@property (nonatomic, copy) NSString *model;
@property (nonatomic, copy) NSString *year;
@end
[Car allWithSuccessBlock:^(NSArray *collection) {
self.cars = [NSMutableArray arrayWithArray:collection];
[self.tableView reloadData];
} withErrorBlock:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
[Car allWithLimit:10 skipping:5 withSuccessBlock:^(NSArray *collection) {
} withErrorBlock:^(NSError *error) {
}];
Car *car = [Car findById:@"12312-ASADSD"];
Validating model:
ATModel has a method called isValid that returns a BOOL, by default it returns YES. If you want some sort of validation you can override it and validates the model as you wish.
Creating a car:
Car *car = [[Car alloc] init];
car.model = @"aModel";
car.year = @"aYear";
[car createWithSuccessBlock:^{
} withErrorBlock:^(NSError *error) {
}];
[car updateWithSuccessBlock:^{
} withErrorBlock:^(NSError *error) {
}];
[car destroyWithSuccessBlock:^{
} withErrorBlock:^(NSError *error) {
}];
If want to add another couchdb view you can overrir the +(void)registerViews method of ATModel
like this:
+ (void)registerViews
{
[super registerViews];
//Add another view here
}
When you call the all method it will order your documents by _id, if you would like to change the order do this:
+ (NSArray *)sortOrder
{
return @[ @"name", @"age" ];
}
#import "ATDatabaseTestRunner.h"
#import "ATDatabaseContainer.h"
#import "Kiwi.h"
SPEC_BEGIN(ATModelIntegrationSpec)
beforeAll(^{
[ATDatabaseTestRunner openTestDatabaseNamed:@"your_test_database"];
});
beforeEach(^{
[ATDatabaseContainer stub:@selector(sharedInstance) andReturn:[ATDatabaseTestRunner databaseContainer]];
[ATDatabaseTestRunner cleanDatabase];
});
afterAll(^{
[ATDatabaseTestRunner removeDatabase];
});
SPEC_END
specify(^{
[[model should] beValid];
});
The ATModel
class inherits from MTLModel
class from Github's Mantle,
which can be used to unmarshall JSONs that comes from webservices calls.
This make your integration with network frameworks, such as AFNetworking, easier.
ActiveTouch
requires iOS 5.x or greater.
Eduardo Gurgel for giving me the project name.
Usage is provided under the MIT License. See LICENSE for the full details.