File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ local getFilePath = function ()
2+ if vim .bo .filetype == ' ruby' then
3+ return vim .api .nvim_buf_get_name (0 )
4+ end
5+ end
6+
7+ local M = {}
8+
9+ --- Returns true if the spec file was opened
10+ ---
11+ --- @param filePath string
12+ --- @param rootPath string
13+ --- @return boolean
14+ M .open_spec_from_app = function (filePath , rootPath )
15+ local regexPattern = " ^" .. rootPath .. " /app/(.*)%.rb$"
16+ local match = string.match (filePath , regexPattern )
17+ if match then
18+ print (' this is an app file' )
19+ return true
20+ end
21+ return false
22+ end
23+
24+ --- Returns true if the app file was opened
25+ ---
26+ --- @param filePath string
27+ --- @param rootPath string
28+ --- @return boolean
29+ M .open_app_from_spec = function (filePath , rootPath )
30+ -- TODO: replace spec with a configuration
31+ local regexPattern = " ^" .. rootPath .. " /" .. " test" .. " /(.*)_test%.rb$"
32+ local match = string.match (filePath , regexPattern )
33+ if match then
34+ return true
35+ end
36+ return false
37+ end
38+
39+ M .toggle = function ()
40+ local filePath = getFilePath ()
41+ local rootPath = vim .loop .cwd ()
42+ if (filePath and rootPath ) then
43+ local didOpenSpec = M .open_spec_from_app (filePath , rootPath )
44+ if not didOpenSpec then
45+ M .open_app_from_spec (filePath , rootPath )
46+ end
47+ end
48+ end
49+
50+ return M
Original file line number Diff line number Diff line change 1+ local config = require (' rails-rspec-toggle.config' )
2+ local actions = require (' rails-rspec-toggle.actions' )
3+
4+ local M = {}
5+
6+ M .setup = config .setup
7+ M .toggle = actions .toggle
8+
9+ return M
You can’t perform that action at this time.
0 commit comments