From: dsc Date: Fri, 13 Apr 2012 14:12:43 +0000 (-0700) Subject: Search for datasource by id. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=8de6600c53cd65ea2a9238738469dc8a533b49c8;p=limn.git Search for datasource by id. --- diff --git a/lib/server/controllers/datasource.co b/lib/server/controllers/datasource.co index 1f89863..fb07e6a 100644 --- a/lib/server/controllers/datasource.co +++ b/lib/server/controllers/datasource.co @@ -33,24 +33,30 @@ class DataSourceController extends Controller * Auto-load :id for related requests. */ autoload: (id, cb) -> - file = @toFile id - parser = JSON.parse + files = findit.sync @dataDir + pattern = new RegExp "#id\.(json|ya?ml)$", "i" + file = _.find files, -> pattern.test it - yamlFile = file.replace /\.json$/i, '.yaml' - if exists yamlFile - file = yamlFile + unless file + console.error "Unable to find DataSource for '#id'!" + return cb new Error "Unable to find DataSource for '#id'!" + + if _.endsWith file, "#id.json" + parser = JSON.parse + if _.endsWith file, "#id.yaml" parser = yaml.load err, data <- fs.readFile file, 'utf8' if 'ENOENT' is err?.code - return cb null, {} + console.error "Unable to find DataSource for '#id'!" + return cb new Error "Unable to find DataSource for '#id'!" if err - console.error "DataSourceController.autoload(#id, #{typeof cb}) -->\nerr" + console.error "DataSourceController.autoload(#id, #{typeof cb}) -->\n", err return cb err try cb null, parser data catch err - console.error "DataSourceController.autoload(#id, #{typeof cb}) -->\nerr" + console.error "DataSourceController.autoload(#id, #{typeof cb}) -->\n", err cb err /**