Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Close #464 - Server contextual configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Mar 7, 2015
1 parent 3ab9f4c commit 07ecb64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,9 @@
2.0.7
------------------

### Added
- Added ability to have contextual server configuration by adding a `config` array to a server's configuration

### Fixed
- Fixed an issue when igniting with a connection other than "production"
- Fixed an issue with Polyglot strategies not properly propagating their results to parent tasks
Expand Down
10 changes: 9 additions & 1 deletion src/Rocketeer/Rocketeer.php
Expand Up @@ -109,14 +109,18 @@ public function getOption($option)
return $contextual;
}

if ($contextual = $this->getContextualOption($option, 'servers', $original)) {
return $contextual;
}

return $original;
}

/**
* Get a contextual option.
*
* @param string $option
* @param string $type [stage,connection]
* @param string $type [stage,connection]
* @param string|array|null $original
*
* @return string|array|\Closure
Expand All @@ -125,6 +129,10 @@ protected function getContextualOption($option, $type, $original = null)
{
// Switch context
switch ($type) {
case 'servers':
$contextual = sprintf('rocketeer::connections.%s.servers.%d.config.%s', $this->connections->getConnection(), $this->connections->getServer(), $option);
break;

case 'stages':
$contextual = sprintf('rocketeer::on.stages.%s.%s', $this->connections->getStage(), $option);
break;
Expand Down
9 changes: 9 additions & 0 deletions tests/RocketeerTest.php
Expand Up @@ -62,4 +62,13 @@ public function testRocketeerCanGuessWhichStageHesIn()
$stage = Rocketeer::getDetectedStage('foobar', $path);
$this->assertEquals(false, $stage);
}

public function testCanUserServerContextualConfiguration()
{
$this->swapConfig([
'rocketeer::connections.production.servers.0.config.remote.root_directory' => '/foo/bar',
]);

$this->assertEquals('/foo/bar', $this->rocketeer->getOption('remote.root_directory'));
}
}

0 comments on commit 07ecb64

Please sign in to comment.