vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m in nano-store-0.5.2 vs vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m in nano-store-0.6.0
- old
+ new
@@ -24,39 +24,38 @@
SUCH DAMAGE.
*/
#import "NSFNanoExpression.h"
#import "NanoStore_Private.h"
+#import "NSFOrderedDictionary.h"
@implementation NSFNanoExpression
{
/** \cond */
- NSMutableArray *predicates;
- NSMutableArray *operators;
+ NSMutableArray *_predicates;
+ NSMutableArray *_operators;
/** \endcond */
}
-@synthesize predicates, operators;
-
+ (NSFNanoExpression*)expressionWithPredicate:(NSFNanoPredicate *)aPredicate
{
return [[self alloc]initWithPredicate:aPredicate];
}
- (id)initWithPredicate:(NSFNanoPredicate *)aPredicate
{
if (nil == aPredicate) {
[[NSException exceptionWithName:NSFUnexpectedParameterException
- reason:[NSString stringWithFormat:@"*** -[%@ %s]: the predicate is nil.", [self class], _cmd]
+ reason:[NSString stringWithFormat:@"*** -[%@ %@]: the predicate is nil.", [self class], NSStringFromSelector(_cmd)]
userInfo:nil]raise];
}
if ((self = [super init])) {
- predicates = [NSMutableArray new];
- [predicates addObject:aPredicate];
- operators = [NSMutableArray new];
- [operators addObject:[NSNumber numberWithInt:NSFAnd]];
+ _predicates = [NSMutableArray new];
+ [_predicates addObject:aPredicate];
+ _operators = [NSMutableArray new];
+ [_operators addObject:[NSNumber numberWithInt:NSFAnd]];
}
return self;
}
@@ -69,31 +68,46 @@
- (void)addPredicate:(NSFNanoPredicate *)aPredicate withOperator:(NSFOperator)someOperator
{
if (nil == aPredicate)
[[NSException exceptionWithName:NSFUnexpectedParameterException
- reason:[NSString stringWithFormat:@"*** -[%@ %s]: the predicate is nil.", [self class], _cmd]
+ reason:[NSString stringWithFormat:@"*** -[%@ %@]: the predicate is nil.", [self class], NSStringFromSelector(_cmd)]
userInfo:nil]raise];
- [predicates addObject:aPredicate];
- [operators addObject:[NSNumber numberWithInt:someOperator]];
+ [_predicates addObject:aPredicate];
+ [_operators addObject:[NSNumber numberWithInt:someOperator]];
}
- (NSString *)description
{
- NSUInteger i, count = [predicates count];
+ NSArray *values = [self arrayDescription];
+
+ return [values componentsJoinedByString:@""];
+}
+
+- (NSArray *)arrayDescription
+{
+ NSUInteger i, count = [_predicates count];
NSMutableArray *values = [NSMutableArray new];
// We always have one predicate, so make sure add it
- [values addObject:[[predicates objectAtIndex:0]description]];
-
+ [values addObject:[[_predicates objectAtIndex:0]description]];
+
for (i = 1; i < count; i++) {
- NSString *compound = [[NSString alloc]initWithFormat:@" %@ %@", ([[operators objectAtIndex:i]intValue] == NSFAnd) ? @"AND" : @"OR", [[predicates objectAtIndex:i]description]];
+ NSString *compound = [[NSString alloc]initWithFormat:@" %@ %@", ([[_operators objectAtIndex:i]intValue] == NSFAnd) ? @"AND" : @"OR", [[_predicates objectAtIndex:i]description]];
[values addObject:compound];
}
- NSString *value = [values componentsJoinedByString:@""];
+ return values;
+}
+
+- (NSString *)JSONDescription
+{
+ NSArray *values = [self arrayDescription];
- return value;
+ NSError *outError = nil;
+ NSString *description = [NSFNanoObject _NSObjectToJSONString:values error:&outError];
+
+ return description;
}
@end
\ No newline at end of file