Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Named CommandPayload #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ package robotlegs.bender.extensions.commandCenter.api
{
return _classes;
}

private var _names:Array;

/**
* Ordered list of value names
*/
public function get names():Array
{
return _names;
}

/**
* The number of payload items
Expand All @@ -54,11 +64,23 @@ package robotlegs.bender.extensions.commandCenter.api
* Creates a command payload
* @param values Optional values
* @param classes Optional classes
* @param names Optional names
*/
public function CommandPayload(values:Array = null, classes:Array = null)
public function CommandPayload(values:Array = null, classes:Array = null, names:Array = null)
{
_values = values;
_classes = classes;

if(names)
{
_names = names;
}
else if(classes)
{
_names = new Array();
for(var i:int = 0; i<classes.length; i++)
_names[i] = '';
}
}

/*============================================================================*/
Expand All @@ -71,7 +93,7 @@ package robotlegs.bender.extensions.commandCenter.api
* @param payloadClass The class of the value
* @return Self
*/
public function addPayload(payloadValue:Object, payloadClass:Class):CommandPayload
public function addPayload(payloadValue:Object, payloadClass:Class, payloadName:String = ''):CommandPayload
{
if (_values)
{
Expand All @@ -89,6 +111,15 @@ package robotlegs.bender.extensions.commandCenter.api
{
_classes = [payloadClass];
}
if (_names)
{
_names.push(payloadName);
}
else
{
_names = [payloadName];
}


return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ package robotlegs.bender.extensions.commandCenter.impl
var i:uint = payload.length;
while (i--)
{
_injector.map(payload.classes[i]).toValue(payload.values[i]);
_injector.map(payload.classes[i], payload.names[i]).toValue(payload.values[i]);
}
}

Expand All @@ -120,7 +120,7 @@ package robotlegs.bender.extensions.commandCenter.impl
var i:uint = payload.length;
while (i--)
{
_injector.unmap(payload.classes[i]);
_injector.unmap(payload.classes[i], payload.names[i]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ package robotlegs.bender.extensions.commandCenter.impl
public function payload_is_injected_into_command():void
{
addMapping(PayloadInjectionPointsCommand);
const payload:CommandPayload = new CommandPayload(['message', 1], [String, int]);
const payload:CommandPayload = new CommandPayload(['message', 1, 'messageNamed', 2],
[String, int, String, int],
['', '', 'named', 'named']);
executeCommands(payload);
assertThat(reported, array(payload.values));
}
Expand Down Expand Up @@ -392,6 +394,12 @@ class PayloadInjectionPointsCommand

[Inject]
public var code:int;

[Inject(name="named")]
public var messageNamed:String;

[Inject(name="named")]
public var codeNamed:int;

[Inject(name="reportingFunction")]
public var reportingFunc:Function;
Expand All @@ -404,6 +412,8 @@ class PayloadInjectionPointsCommand
{
reportingFunc(message);
reportingFunc(code);
reportingFunc(messageNamed);
reportingFunc(codeNamed);
}
}

Expand Down