Skip to content

Commit

Permalink
remove some duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
rhgills committed Jul 30, 2013
1 parent 95de77d commit 7da784f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

#import <Foundation/Foundation.h>
#import "TyphoonInjectedParameter.h"
#import "TyphoonComponentInjectedByValue.h"

@class TyphoonTypeDescriptor;


@interface TyphoonParameterInjectedByValue : NSObject <TyphoonInjectedParameter>
@interface TyphoonParameterInjectedByValue : NSObject <TyphoonInjectedParameter, TyphoonComponentInjectedByValue>
{
__unsafe_unretained TyphoonInitializer* _initializer;
}

@property(nonatomic, readonly) NSUInteger index;
@property(nonatomic, readonly) TyphoonParameterInjectionType type;
@property(nonatomic, strong) NSString* textValue;
@property(nonatomic, strong, readonly) Class requiredType;

- (id)initWithIndex:(NSUInteger)index value:(NSString*)value requiredTypeOrNil:(Class)requiredTypeOrNil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

@implementation TyphoonParameterInjectedByValue



@synthesize textValue = _textValue;

/* ============================================================ Initializers ============================================================ */
- (id)initWithIndex:(NSUInteger)index value:(NSString*)value requiredTypeOrNil:(Class)requiredTypeOrNil
{
Expand Down
9 changes: 3 additions & 6 deletions Source/Component/Properties/TyphoonPropertyInjectedByValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@

#import <Foundation/Foundation.h>
#import "TyphoonInjectedProperty.h"
#import "TyphoonComponentInjectedByValue.h"


@interface TyphoonPropertyInjectedByValue : NSObject <TyphoonInjectedProperty>
{
NSString* _textValue;
}
@interface TyphoonPropertyInjectedByValue : NSObject <TyphoonInjectedProperty, TyphoonComponentInjectedByValue>

@property (nonatomic, strong, readonly) NSString* name;
@property (nonatomic, readonly) TyphoonPropertyInjectionType type;
@property (nonatomic, strong, readonly) NSString* textValue;


- (id)initWithName:(NSString*)name value:(NSString*)value;

Expand Down
5 changes: 3 additions & 2 deletions Source/Component/Properties/TyphoonPropertyInjectedByValue.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@


@implementation TyphoonPropertyInjectedByValue
{

}


@synthesize textValue = _textValue;

/* ============================================================ Initializers ============================================================ */
- (id)initWithName:(NSString*)name value:(NSString*)value
Expand Down
15 changes: 15 additions & 0 deletions Source/Component/TyphoonComponentInjectedByValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// TyphoonComponentInjectedByValue.h
// Static Library
//
// Created by Robert Gilliam on 7/30/13.
// Copyright (c) 2013 Jasper Blues. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol TyphoonComponentInjectedByValue <NSObject>

@property(nonatomic, strong) NSString* textValue;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

- (void)setFactoryReference:(NSString*)factoryReference;

- (NSSet *)componentsInjectedByValue;

- (void)injectProperty:(SEL)withSelector withReference:(NSString*)reference;

- (NSSet*)propertiesInjectedByValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#import "TyphoonPropertyInjectedByValue.h"
#import "TyphoonPropertyInjectedByType.h"
#import "TyphoonPropertyInjectedByReference.h"

#import "TyphoonInitializer+InstanceBuilder.h"

@implementation TyphoonDefinition (InstanceBuilder)

Expand All @@ -30,6 +30,16 @@ - (void)setFactoryReference:(NSString*)factoryReference;
_factoryReference = factoryReference;
}

- (NSSet *)componentsInjectedByValue;
{
NSMutableSet *set = [[NSMutableSet alloc] init];
[set unionSet:[self propertiesInjectedByValue]];

NSArray *a = [self.initializer parametersInjectedByValue];
[set unionSet:[NSSet setWithArray:a]];
return set;
}

- (void)injectProperty:(SEL)selector withReference:(NSString*)reference
{
[_injectedProperties addObject:[[TyphoonPropertyInjectedByReference alloc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,7 @@
#import "TyphoonInitializer+InstanceBuilder.h"
#import "OCLogTemplate.h"

@interface TyphoonPropertyInjectedByValue (PropertyPlaceHolderConfigurer)

- (void)setTextValue:(NSString*)textValue;

@end


@implementation TyphoonPropertyInjectedByValue (PropertyPlaceHolderConfigurer)

- (void)setTextValue:(NSString*)textValue
{
_textValue = textValue;
}


@end

@implementation TyphoonPropertyPlaceholderConfigurer

Expand Down Expand Up @@ -117,29 +102,22 @@ - (void)mutateComponentDefinitionsIfRequired:(NSArray*)componentDefinitions
{
for (TyphoonDefinition* definition in componentDefinitions)
{
for (TyphoonParameterInjectedByValue* parameter in [definition.initializer parametersInjectedByValue])
for (id <TyphoonComponentInjectedByValue> component in [definition componentsInjectedByValue])
{
if ([parameter.textValue hasPrefix:_prefix] && [parameter.textValue hasSuffix:_suffix])
{
NSString* key = [parameter.textValue substringFromIndex:[_prefix length]];
key = [key substringToIndex:[key length] - [_suffix length]];
NSString* value = [_properties valueForKey:key];
LogTrace(@"Setting property '%@' to value '%@'", key, value);
parameter.textValue = value;
}
[self mutateComponentInjectedByValue:component];
}
}
}

for (TyphoonPropertyInjectedByValue* property in [definition propertiesInjectedByValue])
{
if ([property.textValue hasPrefix:_prefix] && [property.textValue hasSuffix:_suffix])
{
NSString* key = [property.textValue substringFromIndex:[_prefix length]];
key = [key substringToIndex:[key length] - [_suffix length]];
NSString* value = [_properties valueForKey:key];
LogTrace(@"Setting property '%@' to value '%@'", key, value);
property.textValue = value;
}
}
- (void)mutateComponentInjectedByValue:(id <TyphoonComponentInjectedByValue>)component;
{
if ([component.textValue hasPrefix:_prefix] && [component.textValue hasSuffix:_suffix])
{
NSString* key = [component.textValue substringFromIndex:[_prefix length]];
key = [key substringToIndex:[key length] - [_suffix length]];
NSString* value = [_properties valueForKey:key];
LogTrace(@"Setting property '%@' to value '%@'", key, value);
component.textValue = value;
}
}

Expand Down

0 comments on commit 7da784f

Please sign in to comment.