Add Project.open, which returns a buffer for an absolute/relative path.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-05 12:02:25 -08:00
parent 5293ba7469
commit 23c3cbf85f
2 changed files with 23 additions and 0 deletions

View File

@@ -14,3 +14,16 @@ describe "Project", ->
project.getFilePaths().done (result) ->
expect(result).toEqual(expectedPaths)
describe ".open(path)", ->
absolutePath = null
beforeEach ->
absolutePath = require.resolve('fixtures/dir/a')
describe "when given an absolute path", ->
it "returns a buffer for the given path", ->
expect(project.open(absolutePath).url).toBe absolutePath
describe "when given a relative path", ->
it "returns a buffer for the given path (relative to the project root)", ->
expect(project.open('a').url).toBe absolutePath

View File

@@ -1,4 +1,5 @@
fs = require 'fs'
Buffer = require 'buffer'
module.exports =
@@ -8,3 +9,12 @@ class Project
getFilePaths: ->
fs.async.listFiles(@url, true)
open: (filePath) ->
new Buffer(@resolve(filePath))
resolve: (filePath) ->
if filePath[0] == '/'
filePath
else
fs.join(@url, filePath)