Skip to content

Commit

Permalink
Merge pull request #135 from eriksundin/inject-primitives
Browse files Browse the repository at this point in the history
Block-style Initializer and properties: Allow injection of primitive
  • Loading branch information
jasperblues committed Dec 15, 2013
2 parents df1457a + b2d7faf commit f1a22c6
Show file tree
Hide file tree
Showing 9 changed files with 594 additions and 4 deletions.
115 changes: 114 additions & 1 deletion Source/Definition/Initializer/TyphoonInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ typedef enum
SEL _selector;
}

/**
* The selector used to initialize the component.
*/
@property(nonatomic) SEL selector;

- (id)initWithSelector:(SEL)initializer;
Expand All @@ -58,24 +61,134 @@ typedef enum
/* ====================================================================================================================================== */
#pragma mark - Block assembly

/**
* Injects with the given definition.
*/
- (void)injectWithDefinition:(TyphoonDefinition*)definition;

/**
* Injects with the value represented by the given text. The text will be used to create an instance of a class matching the
* required type.
*
* @see TyphoonTypeConverterRegistry for details on declaring your own type converters.
*/
- (void)injectWithValueAsText:(NSString*)text;

/**
* Injects with the value represented by the given text. The text will be used to create an instance of the given requiredType.
*/
- (void)injectWithValueAsText:(NSString*)text requiredTypeOrNil:(id)requiredTypeOrNil;

/**
* Injects with an object instance.
*/
- (void)injectWithObject:(id)value;

/**
* Injects with a collection of the given type.
*/
- (void)injectWithCollection:(void (^)(TyphoonParameterInjectedAsCollection*))collectionValues requiredType:(id)requiredType;

/**
* Injects with an int.
*/
- (void)injectWithInt:(int)intValue;

/**
* Injects with an unsigned int.
*/
- (void)injectWithUnsignedInt:(unsigned int)unsignedIntValue;

/**
* Injects with a short.
*/
- (void)injectWithShort:(short)shortValue;

/**
* Injects with an unsigned short.
*/
- (void)injectWithUnsignedShort:(unsigned short)unsignedShortValue;

/**
* Injects with a long.
*/
- (void)injectWithLong:(long)longValue;

/**
* Injects with an unsigned long.
*/
- (void)injectWithUnsignedLong:(unsigned long)unsignedLongValue;

/**
* Injects with a long long.
*/
- (void)injectWithLongLong:(long long)longLongValue;

/**
* Injects with an unsigned long long.
*/
- (void)injectWithUnsignedLongLong:(unsigned long long)unsignedLongLongValue;

/**
* Injects with an unsigned char.
*/
- (void)injectWithUnsignedChar:(unsigned char)unsignedCharValue;

/**
* Injects with a float.
*/
- (void)injectWithFloat:(float)floatValue;

/**
* Injects with a double.
*/
- (void)injectWithDouble:(double)doubleValue;

/**
* Injects with a boolean.
*/
- (void)injectWithBool:(BOOL)boolValue;

/**
* Injects with an integer.
*/
- (void)injectWithInteger:(NSInteger)integerValue;

/**
* Injects with an unsigned integer.
*/
- (void)injectWithUnsignedInteger:(NSUInteger)unsignedIntegerValue;

/**
* Injects with a class.
*/
- (void)injectWithClass:(Class)classValue;

/**
* Injects with a selector.
*/
- (void)injectWithSelector:(SEL)selectorValue;

/**
* Injects the parameter matched by the given name with the given definition.
*/
- (void)injectParameterNamed:(NSString*)name withDefinition:(TyphoonDefinition*)definition;

- (void)injectParameterAtIndex:(NSUInteger)index1 withDefinition:(TyphoonDefinition*)definition;
/**
* Injects the parameter at the given index with the given definition.
*/
- (void)injectParameterAtIndex:(NSUInteger)index withDefinition:(TyphoonDefinition*)definition;

/**
* Injects the parameter at the given index as a collection of the given requiredType.
*/
- (void)injectParameterAtIndex:(NSUInteger)index
asCollection:(void (^)(TyphoonParameterInjectedAsCollection*))collectionValues
requiredType:(id)requiredType;

/**
* Injects the parameter matched by the given name as a collection of the given requiredType.
*/
- (void)injectParameterNamed:(NSString*)name
asCollection:(void (^)(TyphoonParameterInjectedAsCollection*))collectionValues
requiredType:(id)requiredType;
Expand Down
80 changes: 80 additions & 0 deletions Source/Definition/Initializer/TyphoonInitializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,86 @@ - (void)injectWithCollection:(void (^)(TyphoonParameterInjectedAsCollection*))co
[self injectParameterAtIndex:[_injectedParameters count] asCollection:collectionValues requiredType:requiredType];
}

- (void)injectWithInt:(int)intValue
{
[self injectWithValueAsText:[@(intValue) stringValue]];
}

- (void)injectWithUnsignedInt:(unsigned int)unsignedIntValue
{
[self injectWithValueAsText:[@(unsignedIntValue) stringValue]];
}

- (void)injectWithShort:(short)shortValue
{
[self injectWithValueAsText:[@(shortValue) stringValue]];
}

- (void)injectWithUnsignedShort:(unsigned short)unsignedShortValue
{
[self injectWithValueAsText:[@(unsignedShortValue) stringValue]];
}

- (void)injectWithLong:(long)longValue
{
[self injectWithValueAsText:[@(longValue) stringValue]];
}

- (void)injectWithUnsignedLong:(unsigned long)unsignedLongValue
{
[self injectWithValueAsText:[@(unsignedLongValue) stringValue]];
}

- (void)injectWithLongLong:(long long)longLongValue
{
[self injectWithValueAsText:[@(longLongValue) stringValue]];
}

- (void)injectWithUnsignedLongLong:(unsigned long long)unsignedLongLongValue
{
[self injectWithValueAsText:[@(unsignedLongLongValue) stringValue]];
}

- (void)injectWithUnsignedChar:(unsigned char)unsignedCharValue
{
[self injectWithValueAsText:[@(unsignedCharValue) stringValue]];
}

- (void)injectWithFloat:(float)floatValue
{
[self injectWithValueAsText:[@(floatValue) stringValue]];
}

- (void)injectWithDouble:(double)doubleValue
{
[self injectWithValueAsText:[@(doubleValue) stringValue]];
}

- (void)injectWithBool:(BOOL)boolValue
{
[self injectWithValueAsText:[@(boolValue) stringValue]];
}

- (void)injectWithInteger:(NSInteger)integerValue
{
[self injectWithValueAsText:[@(integerValue) stringValue]];
}

- (void)injectWithUnsignedInteger:(NSUInteger)unsignedIntegerValue
{
[self injectWithValueAsText:[@(unsignedIntegerValue) stringValue]];
}

- (void)injectWithClass:(Class)classValue
{
[self injectWithValueAsText:NSStringFromClass(classValue)];
}

- (void)injectWithSelector:(SEL)selectorValue
{
[self injectWithValueAsText:NSStringFromSelector(selectorValue)];
}

/* ====================================================================================================================================== */
#pragma mark - Block assembly

Expand Down
86 changes: 86 additions & 0 deletions Source/Definition/TyphoonDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ typedef void(^TyphoonDefinitionBlock)(TyphoonDefinition* definition);
*/
- (void)injectProperty:(SEL)selector withDefinition:(TyphoonDefinition*)definition;

/**
* Injects property with the given object instance.
*/
- (void)injectProperty:(SEL)selector withObjectInstance:(id)instance;

/**
Expand All @@ -103,6 +106,89 @@ typedef void(^TyphoonDefinitionBlock)(TyphoonDefinition* definition);
*/
- (void)injectProperty:(SEL)withSelector withValueAsText:(NSString*)textValue;

/**
* Injects property as a collection.
*/
- (void)injectProperty:(SEL)withSelector asCollection:(void (^)(TyphoonPropertyInjectedAsCollection*))collectionValues;

/**
* Injects property as int.
*/
- (void)injectProperty:(SEL)selector withInt:(int)intValue;

/**
* Injects property as unsigned int.
*/
- (void)injectProperty:(SEL)selector withUnsignedInt:(unsigned int)unsignedIntValue;

/**
* Injects property as short.
*/
- (void)injectProperty:(SEL)selector withShort:(short)shortValue;

/**
* Injects property as unsigned short.
*/
- (void)injectProperty:(SEL)selector withUnsignedShort:(unsigned short)unsignedShortValue;

/**
* Injects property as long.
*/
- (void)injectProperty:(SEL)selector withLong:(long)longValue;

/**
* Injects property as unsigned long.
*/
- (void)injectProperty:(SEL)selector withUnsignedLong:(unsigned long)unsignedLongValue;

/**
* Injects property as long long.
*/
- (void)injectProperty:(SEL)selector withLongLong:(long long)longLongValue;

/**
* Injects property as unsigned long long.
*/
- (void)injectProperty:(SEL)selector withUnsignedLongLong:(unsigned long long)unsignedLongLongValue;

/**
* Injects property as unsigned char.
*/
- (void)injectProperty:(SEL)selector withUnsignedChar:(unsigned char)unsignedCharValue;

/**
* Injects property as float.
*/
- (void)injectProperty:(SEL)selector withFloat:(float)floatValue;

/**
* Injects property as double.
*/
- (void)injectProperty:(SEL)selector withDouble:(double)doubleValue;

/**
* Injects property as boolean.
*/
- (void)injectProperty:(SEL)selector withBool:(BOOL)boolValue;

/**
* Injects property as integeger.
*/
- (void)injectProperty:(SEL)selector withInteger:(NSInteger)integerValue;

/**
* Injects property as unsigned integer.
*/
- (void)injectProperty:(SEL)selector withUnsignedInteger:(NSUInteger)unsignedIntegerValue;

/**
* Injects property as class.
*/
- (void)injectProperty:(SEL)selector withClass:(Class)classValue;

/**
* Injects property as selector.
*/
- (void)injectProperty:(SEL)selector withSelector:(SEL)selectorValue;

@end
Loading

0 comments on commit f1a22c6

Please sign in to comment.