@@ -166,16 +166,16 @@ repository.prototype.getByName = function(type, name, limit) {
166166 var criteria = { } ;
167167 criteria [ type ] = name ;
168168
169- var result = [ ] ;
170- for ( var k in this . files ) {
171- if ( this . files [ k ] instanceof file ) {
172- var items = this . files [ k ] . getByName ( type , name , limit ) ;
173- if ( items . length > 0 ) {
174- result = result . concat ( items ) ;
175- }
169+ var result = [ ] ;
170+ for ( var k in this . files ) {
171+ if ( this . files [ k ] instanceof file ) {
172+ var items = this . files [ k ] . getByName ( type , name , limit ) ;
173+ if ( items . length > 0 ) {
174+ result = result . concat ( items ) ;
175+ }
176+ }
176177 }
177- }
178- return result ;
178+ return result ;
179179} ;
180180
181181/**
@@ -232,21 +232,23 @@ repository.prototype.getNamespace = function(name) {
232232 var result = node . create ( 'namespace' , this ) ;
233233
234234 items . forEach ( function ( ns ) {
235- if ( ns . constants . length > 0 ) {
236- result . constants = result . constants . concat ( ns . constants ) ;
237- }
238- if ( ns . functions . length > 0 ) {
239- result . functions = result . functions . concat ( ns . functions ) ;
240- }
241- if ( ns . classes . length > 0 ) {
242- result . classes = result . classes . concat ( ns . classes ) ;
243- }
244- if ( ns . traits . length > 0 ) {
245- result . traits = result . traits . concat ( ns . traits ) ;
246- }
247- if ( ns . interfaces . length > 0 ) {
248- result . interfaces = result . interfaces . concat ( ns . interfaces ) ;
249- }
235+ /** @todo
236+ if (ns.constants.length > 0) {
237+ result.constants = result.constants.concat(ns.constants);
238+ }
239+ if (ns.functions.length > 0) {
240+ result.functions = result.functions.concat(ns.functions);
241+ }
242+ if (ns.classes.length > 0) {
243+ result.classes = result.classes.concat(ns.classes);
244+ }
245+ if (ns.traits.length > 0) {
246+ result.traits = result.traits.concat(ns.traits);
247+ }
248+ if (ns.interfaces.length > 0) {
249+ result.interfaces = result.interfaces.concat(ns.interfaces);
250+ }
251+ */
250252 } ) ;
251253 return result ;
252254 } else {
@@ -267,71 +269,61 @@ repository.prototype.sync = require('./repository/sync');
267269 * @return {repository }
268270 */
269271repository . prototype . cleanAll = function ( ) {
270- this . db = new db ( this ) ;
272+ this . db = new db . graph ( this ) ;
271273 return this ;
272274} ;
273275
274276/**
275- * Removes a file
277+ * Iterate over each symbol
276278 * @public
279+ * @param {function } cb A closure : `function(node, name)`
277280 * @return {repository }
278281 */
279- repository . prototype . remove = function ( filename ) {
280- var items = this . db . search ( {
281- file : filename
282+ repository . prototype . each = function ( type , cb ) {
283+ this . db . readIndex ( type , function ( items ) {
284+ for ( var name in items ) {
285+ var nodes = items [ name ] ;
286+ if ( nodes . length !== 1 ) {
287+ for ( var i = 0 ; i < nodes . length ; i ++ ) {
288+ cb ( this . db . get ( nodes [ i ] ) , name ) ;
289+ }
290+ } else {
291+ cb ( this . db . get ( nodes [ 0 ] ) , name ) ;
292+ }
293+ }
282294 } ) ;
283- for ( var i = 0 ; i < items . length ; i ++ ) {
284- var item = this . db . get ( items [ i ] ) ;
285- item . delete ( ) ;
286- }
287295 return this ;
288296} ;
289297
290298/**
291- * Iterate over each file
299+ * Gets the scope for the specified offset
292300 * @public
293- * @param {function } cb A closure : `function(file, name)`
294- * @return {repository }
301+ * @return {scope }
295302 */
296- repository . prototype . each = function ( cb ) {
297- for ( var i = 0 ; i < this . db . indexes . length ; i ++ ) {
298- var entry = this . db . indexes [ i ] ;
299- if ( ! e )
300- if ( entry && 'file' in entry . index ) {
301- var files = filesIndex . index . file ;
302- for ( var name in files ) {
303- var nodes = files [ name ] ;
304- if ( nodes . length !== 1 ) {
305- for ( var i = 0 ; i < nodes . length ; i ++ ) {
306- cb ( this . db . get ( nodes [ i ] ) , name ) ;
307- }
308- } else {
309- cb ( this . db . get ( nodes [ 0 ] ) , name ) ;
310- }
311- }
312- }
313- }
314- var filesIndex = this . db . getIndex ( 'file' ) ;
315- if ( filesIndex && 'file' in filesIndex . index ) {
316-
303+ repository . prototype . getScope = function ( filename , offset ) {
304+ var file = this . getFile ( filename ) ;
305+ if ( file ) {
306+ return file . getScope ( offset ) ;
307+ } else {
308+ return null ;
317309 }
318- return this ;
319310} ;
320311
321312/**
322- * Gets the scope for the specified offset
313+ * Retrieves a file object
323314 * @public
324- * @return {scope }
315+ * @param {String } filename The filename to retrieve
316+ * @return {file|null } Returns the file if exists, or null if not defined
325317 */
326- repository . prototype . scope = function ( filename , offset ) {
327- if (
328- this . files . hasOwnProperty ( filename ) &&
329- this . files [ filename ] instanceof file
330- ) {
331- return this . files [ filename ] . getScope ( offset ) ;
332- } else {
333- return null ;
334- }
318+ repository . prototype . getFile = function ( filename ) {
319+ var items = this . db . search ( {
320+ file : filename
321+ } ) ;
322+ if ( items && items . length > 0 ) {
323+ return this . db . get ( items [ 0 ] ) ;
324+ } else {
325+ return null ;
326+ }
335327} ;
336328
337329/**
@@ -340,53 +332,38 @@ repository.prototype.scope = function(filename, offset) {
340332 * @param {String } filename The filename to retrieve
341333 * @return {file|null } Returns the file if exists, or null if not defined
342334 */
343- repository . prototype . get = function ( filename ) {
344- if (
345- this . files . hasOwnProperty ( filename ) &&
346- this . files [ filename ] instanceof file
347- ) {
348- return this . files [ filename ] ;
349- } else {
350- return null ;
351- }
335+ repository . prototype . hasFile = function ( filename ) {
336+ var items = this . db . search ( {
337+ file : filename
338+ } ) ;
339+ return ( items && items . length > 0 ) ;
352340} ;
353341
354342
355343/**
356- * Gets/Sets the files repository
344+ * Iterate over each file
357345 * @public
358- * @param {object } data Sets the specified data
359- * @return {repository|object } Retrieves the cache (if data not set)
346+ * @param {function } cb A closure : `function(file, name)`
347+ * @return {repository }
360348 */
361- repository . prototype . cache = function ( data ) {
362- if ( typeof data !== 'undefined' ) {
363- // sets the data
364- this . files = { } ;
365- if ( data ) {
366- this . directory = data . directory ;
367- // creating files from structure
368- for ( var name in data . files ) {
369- this . files [ name ] = file . import ( this , data [ name ] ) ;
370- }
371- // rebuild object links
372- for ( var name in this . files ) {
373- this . files [ name ] . refresh ( ) ;
374- }
349+ repository . prototype . eachFile = function ( cb ) {
350+ return this . each ( 'file' , cb ) ;
351+ } ;
352+
353+ /**
354+ * Removes a file
355+ * @public
356+ * @return {repository }
357+ */
358+ repository . prototype . removeFile = function ( filename ) {
359+ var items = this . db . search ( {
360+ file : filename
361+ } ) ;
362+ for ( var i = 0 ; i < items . length ; i ++ ) {
363+ var item = this . db . get ( items [ i ] ) ;
364+ item . delete ( ) ;
375365 }
376366 return this ;
377- } else {
378- // gets the data
379- var result = {
380- directory : this . directory ,
381- files : { }
382- } ;
383- for ( var name in this . files ) {
384- if ( this . files [ name ] instanceof file ) {
385- result . files [ name ] = this . files [ name ] . export ( ) ;
386- }
387- }
388- return result ;
389- }
390367} ;
391368
392369/**
@@ -397,12 +374,11 @@ repository.prototype.cache = function(data) {
397374 * @return {repository }
398375 */
399376repository . prototype . rename = function ( oldName , newName ) {
400- if ( this . files . hasOwnProperty ( oldName ) ) {
401- this . files [ newName ] = this . files [ oldName ] ;
402- this . files [ newName ] . name = newName ;
403- delete this . files [ oldName ] ;
404- }
405- return this ;
377+ var file = this . getFile ( oldName ) ;
378+ if ( file ) {
379+ file . setName ( newName ) ;
380+ }
381+ return this ;
406382} ;
407383
408384
0 commit comments