Skip to content

Commit

Permalink
Merge branch 'release/0.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed May 26, 2012
2 parents 8d0d9fc + 8647fa5 commit 5556180
Show file tree
Hide file tree
Showing 666 changed files with 41,278 additions and 11,198 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Docs/API
# temp nibs and swap files
*~.nib
*.swp
*.orig

# OS X folder attributes
.DS_Store
Expand All @@ -20,6 +21,4 @@ Docs/API

Examples/RKDiscussionBoardExample/discussion_board_backend/public/system/attachments/*

# UISpecRunner cached build path
.uispec.app
Specs/Runner/UISpec
test-reports/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "Examples/RKCatalog/Server"]
path = Examples/RKCatalog/Server
url = git://github.com/twotoasters/RKCatalog-Server.git
url = git://github.com/RestKit/RKCatalog-Server.git
105 changes: 76 additions & 29 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,79 @@ as a Ruby on Rails specific object mapper for XML data. In early 2010 the framew
rebranded as RestKit and evolved into a general purpose HTTP toolkit and object mapping
system.

RestKit is a production of Two Toasters and available as an Open Source package under
the terms of the Apache License (see LICENSE for details).

Original Author
---------------
* Blake Watters (blakewatters) @blakewatters

Core Team
---------
* Jeremy Ellison (jeremyellison)
* Daniel Hammond (danielrhammond)
* Jeff Arena (jeffarena)

Web Designer
------------
* Adit Shukla (aditshukla)

Contributors
------------
* Marc Weil (aspir)
* Pat Shields (pashields)
* Tim Kerchmar (timkerchmar)
* Rachit Shukla (rachitshukla)
* Adam Hinz (ahinz)
* Stefan Eletzhofer (seletz)
* Peter Marks (tassock)
* Chad Podoski (chadpod)
* Andras Hatvani (andrashatvani)
* Ed McManus (emcmanus)
RestKit is available as an Open Source package under the terms of the Apache License (see
LICENSE for details).

## Original Author
* Blake Watters (blakewatters) @blakewatters

## Core Team
* Jeff Arena (jeffarena)
* Gregory Combs (grgcombs)
* Brian Morton (bmorton)

## Web Designer
* Adit Shukla (aditshukla)

## Contributors
#### Version 0.9.3 and earlier
* Jeremy Ellison (jeremyellison)
* Daniel Hammond (danielrhammond)
* Marc Weil (aspir)
* Pat Shields (pashields)
* Tim Kerchmar (timkerchmar)
* Rachit Shukla (rachitshukla)
* Adam Hinz (ahinz)
* Stefan Eletzhofer (seletz)
* Peter Marks (tassock)
* Chad Podoski (chadpod)
* Andras Hatvani (andrashatvani)
* Ed McManus (emcmanus)

#### Version 0.10.0
* Christopher Swasey (endash)
* Aneil Mallavarapu (amallavarapu)
* Rui D Lopes (ruidlopes)
* Robert Altman (inquinity)
* Beat Besmer (besi)
* Scott Penrose (spenrose)
* Charlie Savage (cfis)
* Jawwad Ahmad (jawwad)
* John Stallings (jstallings)
* Bob Spryn (sprynmr)
* Ray Fix (rayfix)
* Marlon Andrade (marlonandrade)
* David Young-Chan Kay (DavidYKay)
* Chethan Reddy (creddy)
* Julien Grimault (juliengrimault)
* Matthias Bartelmeß
* Nolan Waite (nolanw)
* Michael Fleet (fantasticmf)
* Tony Lee (hktonylee)
* Aaron Crespo (aaroncrespo)
* James Sullivan (jsullivanlive)
* Marco Pesenti Gritti (marcopg)
* Brad Phelan (bradphelan)
* Ivan Vučica (ivucica)
* Felix Holmgren (Felixyz)
* Open Thread (OpenFibers)
* Sergej Tatarincev (SevInf)
* Ben Einstein (beinstein)
* Johan Bilien (jobi)
* Björn Jonsson (bjornjonsson)
* Ralf van der Zanden (ralfvdz)
* Parker Boundy (parkerboundy)
* Jeremy Mack (mutewinter)
* Allen Wei (allenwei)
* Robin Eggenkamp (Edubits)
* Emil Wojtaszek (emilwojtaszek)
* Victor Kryukov (victorkryukov)
* Cody Rayment (crayment)
* Arne Harren (aharren)
* Cameron Royal (cammm)

## Honorable Mentions
RestKit would like to thank the following companies for aiding in the support of this product:

* GateGuru - http://www.gateguru.com
* Two Toasters - http://www.twotoasters.com
20 changes: 15 additions & 5 deletions Code/CoreData/CoreData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// RestKit
//
// Created by Blake Watters on 9/30/10.
// Copyright 2010 Two Toasters
//
// Copyright (c) 2009-2012 RestKit. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,6 +23,16 @@
#import "NSManagedObject+ActiveRecord.h"
#import "RKManagedObjectStore.h"
#import "RKManagedObjectSeeder.h"
#import "RKManagedObjectCache.h"
#import "RKManagedObjectMapping.h"
#import "RKManagedObjectMappingOperation.h"
#import "RKManagedObjectCaching.h"
#import "RKInMemoryManagedObjectCache.h"
#import "RKFetchRequestManagedObjectCache.h"
#import "RKSearchableManagedObject.h"
#import "RKSearchWord.h"

#import "RKObjectPropertyInspector+CoreData.h"
#import "RKObjectMappingProvider+CoreData.h"
#import "NSManagedObjectContext+RKAdditions.h"
#import "NSManagedObject+RKAdditions.h"
#import "NSEntityDescription+RKAdditions.h"
93 changes: 93 additions & 0 deletions Code/CoreData/NSEntityDescription+RKAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// NSEntityDescription+RKAdditions.h
// RestKit
//
// Created by Blake Watters on 3/22/12.
// Copyright (c) 2009-2012 RestKit. All rights reserved.
//

#import <CoreData/CoreData.h>

/**
The key for retrieving the name of the attribute that acts as
the primary key from the user info dictionary of the receiving NSEntityDescription.
**Value**: @"primaryKeyAttribute"
*/
extern NSString * const RKEntityDescriptionPrimaryKeyAttributeUserInfoKey;

/**
The substitution variable used in predicateForPrimaryKeyAttribute.
**Value**: @"PRIMARY_KEY_VALUE"
@see predicateForPrimaryKeyAttribute
*/
extern NSString * const RKEntityDescriptionPrimaryKeyAttributeValuePredicateSubstitutionVariable;

/**
Provides extensions to NSEntityDescription for various common tasks.
*/
@interface NSEntityDescription (RKAdditions)

/**
The name of the attribute that acts as the primary key for the receiver.
The primary key attribute can be configured in two ways:
1. From within the Xcode Core Data editing view by
adding the desired attribute's name as the value for the
key `primaryKeyAttribute` to the user info dictionary.
1. Programmatically, by retrieving the NSEntityDescription instance and
setting the property's value.
Programmatically configured values take precedence over the user info
dictionary.
*/
@property (nonatomic, retain) NSString *primaryKeyAttributeName;

/**
The attribute description object for the attribute designated as the primary key for the receiver.
*/
@property (nonatomic, readonly) NSAttributeDescription *primaryKeyAttribute;

/**
The class representing the value of the attribute designated as the primary key for the receiver.
*/
@property (nonatomic, readonly) Class primaryKeyAttributeClass;

/**
Returns a cached predicate specifying that the primary key attribute is equal to the $PRIMARY_KEY_VALUE
substitution variable.
This predicate is cached to avoid parsing overhead during object mapping operations
and must be evaluated using [NSPredicate predicateWithSubstitutionVariables:]
@return A cached predicate specifying the value of the primary key attribute is equal to the $PRIMARY_KEY_VALUE
substitution variable.
*/
- (NSPredicate *)predicateForPrimaryKeyAttribute;

/**
Returns a predicate specifying that the value of the primary key attribute is equal to a given
value. This predicate is constructed by evaluating the cached predicate returned by the
predicateForPrimaryKeyAttribute with a dictionary of substitution variables specifying that
$PRIMARY_KEY_VALUE is equal to the given value.
**NOTE**: This method considers the type of the receiver's primary key attribute when constructing
the predicate. It will coerce the given value into either an NSString or an NSNumber as
appropriate. This behavior is a convenience to avoid annoying issues related to Core Data's
handling of predicates for NSString and NSNumber types that were not appropriately casted.
@return A predicate speciying that the value of the primary key attribute is equal to a given value.
*/
- (NSPredicate *)predicateForPrimaryKeyAttributeWithValue:(id)value;

/**
Coerces the given value into the class representing the primary key. Currently support NSString
and NSNumber coercsions.
@bug **NOTE** This API is temporary and will be deprecated and replaced.
@since 0.10.1
*/
- (id)coerceValueForPrimaryKey:(id)primaryKeyValue;

@end
107 changes: 107 additions & 0 deletions Code/CoreData/NSEntityDescription+RKAdditions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// NSEntityDescription+RKAdditions.m
// RestKit
//
// Created by Blake Watters on 3/22/12.
// Copyright (c) 2009-2012 RestKit. All rights reserved.
//

#import <objc/runtime.h>
#import "NSEntityDescription+RKAdditions.h"

NSString * const RKEntityDescriptionPrimaryKeyAttributeUserInfoKey = @"primaryKeyAttribute";
NSString * const RKEntityDescriptionPrimaryKeyAttributeValuePredicateSubstitutionVariable = @"PRIMARY_KEY_VALUE";

static char primaryKeyAttributeNameKey, primaryKeyPredicateKey;

@implementation NSEntityDescription (RKAdditions)

- (void)setPredicateForPrimaryKeyAttribute:(NSString *)primaryKeyAttribute
{
NSPredicate *predicate = (primaryKeyAttribute) ? [NSPredicate predicateWithFormat:@"%K == $PRIMARY_KEY_VALUE", primaryKeyAttribute] : nil;
objc_setAssociatedObject(self,
&primaryKeyPredicateKey,
predicate,
OBJC_ASSOCIATION_RETAIN);
}

#pragma mark - Public

- (NSAttributeDescription *)primaryKeyAttribute
{
return [[self attributesByName] valueForKey:[self primaryKeyAttributeName]];
}

- (Class)primaryKeyAttributeClass
{
NSAttributeDescription *attributeDescription = [self primaryKeyAttribute];
if (attributeDescription) {
return NSClassFromString(attributeDescription.attributeValueClassName);
}

return nil;
}

- (NSString *)primaryKeyAttributeName
{
// Check for an associative object reference
NSString *primaryKeyAttribute = (NSString *) objc_getAssociatedObject(self, &primaryKeyAttributeNameKey);

// Fall back to the userInfo dictionary
if (! primaryKeyAttribute) {
primaryKeyAttribute = [self.userInfo valueForKey:RKEntityDescriptionPrimaryKeyAttributeUserInfoKey];

// If we have loaded from the user info, ensure we have a predicate
if (! [self predicateForPrimaryKeyAttribute]) {
[self setPredicateForPrimaryKeyAttribute:primaryKeyAttribute];
}
}

return primaryKeyAttribute;
}

- (void)setPrimaryKeyAttributeName:(NSString *)primaryKeyAttributeName
{
objc_setAssociatedObject(self,
&primaryKeyAttributeNameKey,
primaryKeyAttributeName,
OBJC_ASSOCIATION_RETAIN);
[self setPredicateForPrimaryKeyAttribute:primaryKeyAttributeName];
}

- (NSPredicate *)predicateForPrimaryKeyAttribute
{
return (NSPredicate *) objc_getAssociatedObject(self, &primaryKeyPredicateKey);
}

- (id)coerceValueForPrimaryKey:(id)primaryKeyValue
{
id searchValue = primaryKeyValue;
Class theClass = [self primaryKeyAttributeClass];
if (theClass) {
// TODO: This coercsion behavior should be pluggable and reused from the mapper
if ([theClass isSubclassOfClass:[NSNumber class]] && ![searchValue isKindOfClass:[NSNumber class]]) {
// Handle NSString -> NSNumber
if ([searchValue isKindOfClass:[NSString class]]) {
searchValue = [NSNumber numberWithDouble:[searchValue doubleValue]];
}
} else if ([theClass isSubclassOfClass:[NSString class]] && ![searchValue isKindOfClass:[NSString class]]) {
// Coerce to string
if ([searchValue respondsToSelector:@selector(stringValue)]) {
searchValue = [searchValue stringValue];
}
}
}

return searchValue;
}

- (NSPredicate *)predicateForPrimaryKeyAttributeWithValue:(id)value
{
id substitutionValue = [self coerceValueForPrimaryKey:value];
NSDictionary *variables = [NSDictionary dictionaryWithObject:substitutionValue
forKey:RKEntityDescriptionPrimaryKeyAttributeValuePredicateSubstitutionVariable];
return [[self predicateForPrimaryKeyAttribute] predicateWithSubstitutionVariables:variables];
}

@end
Loading

0 comments on commit 5556180

Please sign in to comment.