Sha256: d4f6ffb1d7d5c85d56a8f83f8e6e3ea8bc051616991f83e73c70e9b0e791e4ce

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

#import "OCSMethodCaller.h"
#import "OCSException.h"
#import "OCSInvocation.h"
#import "OCSSelector.h"

@interface OCSMethodCaller ()

@property (nonatomic, strong) id instance;
@property (nonatomic, strong) NSString* methodName;
@property (nonatomic, strong) NSArray* args;

@end

@implementation OCSMethodCaller

+(id) withInstance:(id) instance
        methodName:(NSString*) methodName
           andArgs:(NSArray*) args {
    OCSMethodCaller* methodCaller = [self new];
    methodCaller.instance = instance;
    methodCaller.methodName = methodName;
    methodCaller.args = args;
    return methodCaller;
}

-(NSString*) call {
    if([self isMethodMissingOnInstance]) {
        return [[self methodMissingException] stringValue];
    } else {
        return [self attemptCallWithTryCatch];
    }
}

-(NSString*) attemptCallWithTryCatch {
    @try {
        return [self attemptCall];
    } @catch (NSException* e) {
        return [[OCSException exceptionWithNSException: e] stringValue];
    }
}

-(NSString*) attemptCall {
    OCSInvocation* ocsInvocation = [OCSInvocation invocationWithInstance: self.instance
                                                              methodName: self.methodName
                                                            andArguments: self.args];
    return [ocsInvocation invoke];
}

-(BOOL) isMethodMissingOnInstance {
    return ![self.instance respondsToSelector: [self selector]];
}

-(OCSException*) methodMissingException {
    return [OCSException exceptionWithMessage: @"NO_METHOD_IN_CLASS %@ %@.",
            NSStringFromSelector([self selector]),
            NSStringFromClass([self.instance class])];
}

-(SEL) selector {
    return [OCSSelector selectorForString: self.methodName andArgs: self.args];
}

@end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
xcfit-0.9.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.8.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.7.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.6.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.5.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.4.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.3.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m
xcfit-0.2.0 XCFitDemo/Pods/cslim/src/ExecutorObjectiveC/OCSMethodCaller.m