spur-common
Version:
Common node library that is implemented through the use of spur-ioc and bluebird promises.
31 lines (21 loc) • 844 B
text/coffeescript
module.exports = (path, Promise, fsPromise, FixtureCache, Logger)->
new class FixtureUtil
constructor:()->
= FixtureCache
setFixturesPath:()->
Logger.info "Fixtures path changed to: #{@fixturesPath}"
get:(name)=>
.getOrPromise name, ()=> (name)
readAndProcessFile:(name)=>
(name)
.then
startFileRead:(name)=>
if not
return Promise.reject(new Error("fixtures path is not defined"))
filePath = path.join(, "#{name}.json")
fsPromise
.readFileAsync(filePath, {encoding: 'utf8'})
.catch (err)->
Promise.reject(new Error("#{filePath} not found"))
processText:(text)->
JSON.parse(text) if text and text.length > 0