spur-common
Version:
A Node.JS library of common modules used as a base to most Node.JS applications.
33 lines (22 loc) • 895 B
text/coffeescript
module.exports = (path, Promise, fsPromise, FixtureCache, Logger)->
new class FixtureUtil
constructor:()->
= FixtureCache
setFixturesPath:()->
Logger.log "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")
Logger.log "Using file fixture: #{filePath}"
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