50976dac94fdeb77fd253f5512e2ac2ce2ab30ad

Author: Mark Story

Date: 2009-06-14 20:16:19 -0400

Updating methods Updating shell, to include package insertion.

diff --git a/models/api_package.php b/models/api_package.php index 7489d92..4b203b3 100644 --- a/models/api_package.php +++ b/models/api_package.php @@ -126,4 +126,16 @@ class ApiPackage extends ApiGeneratorAppModel { } return true; } + +/** + * Find The last package's id value. + * + * @return mixed Id of last package. + **/ + public function findEndPackageId($packages) { + $lastPackage = array_pop($packages); + $last = $this->findBySlug($this->_makeSlug($lastPackage)); + return $last['ApiPackage']['id']; + } + } \ No newline at end of file diff --git a/tests/cases/models/api_package.test.php b/tests/cases/models/api_package.test.php index fb5b581..226a4b6 100644 --- a/tests/cases/models/api_package.test.php +++ b/tests/cases/models/api_package.test.php @@ -108,7 +108,7 @@ class ApiPackageTestCase extends CakeTestCase { $result = $this->ApiPackage->parsePackage($docBlock); $expected = array('cake', 'model', 'behavior'); $this->assertEqual($result, $expected); - + $docBlock = array( 'tags' => array( 'package' => 'cake', @@ -141,4 +141,15 @@ class ApiPackageTestCase extends CakeTestCase { $this->assertEqual(count($result), 1, 'Too many model slugs'); } +/** + * test that findEndPackageId finds the end package and returns its Id + * + * @return void + **/ + function testFindEndPackageId() { + $packages = array('cake', 'model'); + $result = $this->ApiPackage->findEndPackageId($packages); + $this->assertEqual($result, 4); + } + } diff --git a/vendors/shells/api_index.php b/vendors/shells/api_index.php index ecfedfc..5bbf78c 100644 --- a/vendors/shells/api_index.php +++ b/vendors/shells/api_index.php @@ -120,9 +120,11 @@ class ApiIndexShell extends Shell { $this->out('Clearing index and regenerating class index...'); $this->ApiClass = ClassRegistry::init('ApiGenerator.ApiClass'); + $this->ApiPackage = ClassRegistry::init('ApiGenerator.ApiPackage'); + $this->ApiClass->clearIndex(); $this->ApiFile->importCoreClasses(); - + $foundClasses = array(); foreach (array_keys($config['paths']) as $path) { $fileList = $this->ApiFile->fileList($path); @@ -138,6 +140,14 @@ class ApiIndexShell extends Shell { if (!isset($foundClasses[$className]) && $this->ApiClass->saveClassDocs($classDocs)) { $this->out('Added docs for ' . $classDocs->name . ' to index'); $foundClasses[$className] = true; + try { + $packages = $this->ApiPackage->parsePackage($classDocs->classInfo['comment']); + $this->ApiPackage->updatePackageTree($packages); + $lastPackage = $this->ApiPackage->findEndPackageId($packages); + $this->ApiClass->saveField('api_package_id', $lastPackage); + } catch (Exception $e) { + $this->out(sprintf('Warning: %s does not have any packages.', $classDocs->getName())); + } } } if (!empty($docsInFile['function'])) {