Skip to content

Commit 88bdd66

Browse files
committed
refactor determining method arguments
1 parent df7ff39 commit 88bdd66

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

lib/deploy.js

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ var Deploy = function(options) {
1515
});
1616
};
1717

18+
Deploy.prototype.determineArguments = function(suppliedArgs) {
19+
var realArgs = [], l, arg, contractName, referedContract;
20+
21+
for (l = 0; l < suppliedArgs.length; l++) {
22+
arg = suppliedArgs[l];
23+
if (arg[0] === "$") {
24+
contractName = arg.substr(1);
25+
referedContract = this.contractsManager.getContract(contractName);
26+
realArgs.push(referedContract.deployedAddress);
27+
} else {
28+
realArgs.push(arg);
29+
}
30+
}
31+
};
32+
1833
Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
1934
var self = this;
2035
var suppliedArgs;
@@ -32,20 +47,7 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
3247

3348
if (contract.address !== undefined) {
3449

35-
// determine arguments
36-
suppliedArgs = (params || contract.args);
37-
realArgs = [];
38-
39-
for (l = 0; l < suppliedArgs.length; l++) {
40-
arg = suppliedArgs[l];
41-
if (arg[0] === "$") {
42-
contractName = arg.substr(1);
43-
referedContract = this.contractsManager.getContract(contractName);
44-
realArgs.push(referedContract.deployedAddress);
45-
} else {
46-
realArgs.push(arg);
47-
}
48-
}
50+
realArgs = self.determineArguments(params || contract.args);
4951

5052
contract.deployedAddress = contract.address;
5153
self.deployTracker.trackContract(contract.className, contract.code, realArgs, contract.address);
@@ -63,20 +65,7 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
6365
return callback();
6466
} else {
6567

66-
// determine arguments
67-
suppliedArgs = (params || contract.args);
68-
realArgs = [];
69-
70-
for (l = 0; l < suppliedArgs.length; l++) {
71-
arg = suppliedArgs[l];
72-
if (arg[0] === "$") {
73-
contractName = arg.substr(1);
74-
referedContract = this.contractsManager.getContract(contractName);
75-
realArgs.push(referedContract.deployedAddress);
76-
} else {
77-
realArgs.push(arg);
78-
}
79-
}
68+
realArgs = self.determineArguments(params || contract.args);
8069

8170
this.deployContract(contract, realArgs, function(err, address) {
8271
if (err) {

0 commit comments

Comments
 (0)