-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuffer-switcher.coffee
38 lines (29 loc) · 994 Bytes
/
buffer-switcher.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
_ = require "underscore"
PathFinder = require "./path-finder"
module.exports =
class BufferSwitcher
constructor: (@finder, @editor, opts = {}) ->
@currentPath = @editor.getPath()
@splitEnabled = opts.split
switch: ->
if @inRubyTestFile()
@switchToSourceFile()
else if @inRubyFile()
@switchToTestFile()
switchToTestFile: ->
testPath = @finder.findTestPath(@currentPath)
@switchToFile(testPath, "right") if testPath
switchToSourceFile: ->
sourcePath = @finder.findSourcePath(@currentPath)
@switchToFile(sourcePath, "left") if sourcePath
inRubyFile: ->
@currentPath.endsWith(".rb")
inRubyTestFile: ->
@currentPath.endsWith("_spec.rb") || @currentPath.endsWith("_test.rb")
switchToFile: (filepath, splitDirection) ->
base_options = searchAllPanes: true
if @splitEnabled
options = _(base_options).extend({split: splitDirection})
else
options = base_options
atom.workspace.open(filepath, options)