mj 0.5.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +68 -1
- data/lib/mj/alternative_file/resolvers/ruby/rails_controller_resolver.rb +33 -1
- data/lib/mj/alternative_file/resolvers/ruby/rails_resolver.rb +3 -0
- data/lib/mj/alternative_file/resolvers/ruby/ruby_file.rb +2 -1
- data/lib/mj/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 683483a53bb0ecac42edc0a0f5f51e8cb14a2cd47af192caddfaf5b8317cdfd8
|
4
|
+
data.tar.gz: eff84fc6a46cb4a000340ba32cadd1ab9edf84bdbb3c8b2d0745fe935ed8c025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e1b4dd41ebec30aabbc7ed605a9b0b0407a2803305e41f52c07a3e326b4111b186d07de57aba6d15843aa211f6a4c630fd591dd015c1a1e8d2577aee0a7540
|
7
|
+
data.tar.gz: 93afecccc6e7ab89277acb49a444936bf37ffa2c54409556beeb107ac67f9d35c1e149ec6a0d026dbb4e844ce4278c69d21cb948ab565436118fae4b7305a4fd
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,9 +25,76 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```bash
|
28
|
-
mj
|
28
|
+
mj help
|
29
29
|
```
|
30
30
|
|
31
|
+
### Alternative file
|
32
|
+
|
33
|
+
Examples:
|
34
|
+
|
35
|
+
```
|
36
|
+
$ mj alternative_file list app/components/attribute_component.rb
|
37
|
+
app/components/attribute_component.html.erb
|
38
|
+
app/components/attribute_component.rb
|
39
|
+
lib/components/attribute_component.rb
|
40
|
+
spec/components/attribute_component_spec.rb
|
41
|
+
test/components/attribute_component_test.rb
|
42
|
+
|
43
|
+
$ mj alternative_file list app/components/attribute_component.rb --exists
|
44
|
+
app/components/attribute_component.html.erb
|
45
|
+
app/components/attribute_component.rb
|
46
|
+
spec/components/attribute_component_spec.rb
|
47
|
+
|
48
|
+
$ mj alternative_file list app/components/attribute_component.rb --types=spec
|
49
|
+
spec/components/attribute_component_spec.rb
|
50
|
+
|
51
|
+
$ mj alternative_file next app/components/attribute_component.rb
|
52
|
+
lib/components/attribute_component.rb
|
53
|
+
|
54
|
+
$ mj alternative_file prev app/components/attribute_component.rb
|
55
|
+
app/components/attribute_component.html.erb
|
56
|
+
```
|
57
|
+
|
58
|
+
Why? Because you can integrate that command with your IDE/Text Editor. For instance, here's my [neovim integration](https://github.com/mjacobus/dotfiles/blob/d8ceda659dc9b587ab22b05fc15eac2fa5b477d7/neovim/.config/nvim/init.lua#L31-L63):
|
59
|
+
|
60
|
+
```lua
|
61
|
+
vimp.nnoremap('<leader>ak', function()
|
62
|
+
open_mj_alternative_file('next', '--exists')
|
63
|
+
end)
|
64
|
+
|
65
|
+
vimp.nnoremap('<leader>aj', function()
|
66
|
+
open_mj_alternative_file('prev', '--exists')
|
67
|
+
end)
|
68
|
+
|
69
|
+
function open_mj_alternative_file(subcommand, options)
|
70
|
+
file_path = vim.fn.expand('%')
|
71
|
+
files = mj_alternative_file(file_path, subcommand, options)
|
72
|
+
files = vim.split(files, ' ')
|
73
|
+
file = files[1]
|
74
|
+
|
75
|
+
|
76
|
+
if file ~= '' then
|
77
|
+
vim.api.nvim_command('e ' .. file)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
function mj_alternative_file(file, subcommand, options)
|
82
|
+
local cmd = 'mj alternative_file ' .. subcommand .. ' ' .. file .. ' ' .. options
|
83
|
+
return execute_command(cmd)
|
84
|
+
end
|
85
|
+
|
86
|
+
function execute_command(cmd)
|
87
|
+
print("cmd: " .. cmd)
|
88
|
+
local f = io.popen(cmd)
|
89
|
+
local s = f:read('*a')
|
90
|
+
f:close()
|
91
|
+
return s
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
This way I can use `<leader>a{direction}`, where `k` is `next`, and `j` is `previous` alternative file.
|
96
|
+
|
97
|
+
|
31
98
|
## Development
|
32
99
|
|
33
100
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -4,6 +4,7 @@ module Mj
|
|
4
4
|
module AlternativeFile
|
5
5
|
module Resolvers
|
6
6
|
module Ruby
|
7
|
+
# rubocop:disable Metrics/MethodLength
|
7
8
|
class RailsControllerResolver < Resolvers::Base
|
8
9
|
private
|
9
10
|
|
@@ -13,7 +14,11 @@ module Mj
|
|
13
14
|
"spec/integration",
|
14
15
|
"test/integration",
|
15
16
|
"test/controllers",
|
16
|
-
"spec/controllers"
|
17
|
+
"spec/controllers",
|
18
|
+
"spec/requests",
|
19
|
+
"test/requests",
|
20
|
+
"spec/system",
|
21
|
+
"test/system"
|
17
22
|
)
|
18
23
|
end
|
19
24
|
|
@@ -23,27 +28,53 @@ module Mj
|
|
23
28
|
add_controller_test(file, candidates, "test")
|
24
29
|
add_integration_test(file, candidates, "spec")
|
25
30
|
add_integration_test(file, candidates, "test")
|
31
|
+
add_request_test(file, candidates, "spec")
|
32
|
+
add_request_test(file, candidates, "test")
|
33
|
+
add_system_test(file, candidates, "spec")
|
34
|
+
add_system_test(file, candidates, "test")
|
26
35
|
return
|
27
36
|
end
|
28
37
|
|
29
38
|
resolve_controller(file, candidates)
|
30
39
|
end
|
40
|
+
# rubocop:enable Metrics/MethodLength
|
31
41
|
|
32
42
|
def add_integration_test(file, candidates, type)
|
33
43
|
path = file.without_prefix("app/controllers").without_suffix(".rb").trim_slashes
|
34
44
|
add_candidate("#{type}/integration/#{path}_#{type}.rb", "integration_#{type}", to: candidates)
|
35
45
|
end
|
36
46
|
|
47
|
+
def add_request_test(file, candidates, type)
|
48
|
+
path = file.without_prefix("app/controllers").sub("_controller", "").without_suffix(".rb").trim_slashes
|
49
|
+
add_candidate("#{type}/requests/#{path}_#{type}.rb", "request_#{type}", to: candidates)
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_system_test(file, candidates, type)
|
53
|
+
path = file.without_prefix("app/controllers").sub("_controller", "").without_suffix(".rb").trim_slashes
|
54
|
+
add_candidate("#{type}/system/#{path}_#{type}.rb", "system_#{type}", to: candidates)
|
55
|
+
end
|
56
|
+
|
37
57
|
def add_controller_test(file, candidates, type)
|
38
58
|
path = file.without_prefix("app/controllers").without_suffix(".rb").trim_slashes
|
39
59
|
add_candidate("#{type}/controllers/#{path}_#{type}.rb", "controller_#{type}", to: candidates)
|
40
60
|
end
|
41
61
|
|
62
|
+
# rubocop:disable Metrics/MethodLength
|
42
63
|
def resolve_controller(file, candidates)
|
64
|
+
# requests|system tests don't usually have "request_{type}.rb" suffix
|
65
|
+
if file.start_with?(%r{(test|spec)/(system|request)})
|
66
|
+
file = file.sub("_spec.rb", "_controller_spec.rb")
|
67
|
+
.sub("_test.rb", "_controller_test.rb")
|
68
|
+
end
|
69
|
+
|
43
70
|
controller_path = file.sub("test/integration", "app/controllers")
|
44
71
|
.sub("spec/integration", "app/controllers")
|
45
72
|
.sub("spec/controllers", "app/controllers")
|
46
73
|
.sub("test/controllers", "app/controllers")
|
74
|
+
.sub("test/requests", "app/controllers")
|
75
|
+
.sub("test/system", "app/controllers")
|
76
|
+
.sub("spec/requests", "app/controllers")
|
77
|
+
.sub("spec/system", "app/controllers")
|
47
78
|
.sub("_spec.rb", ".rb")
|
48
79
|
.sub("_test.rb", ".rb")
|
49
80
|
.to_s
|
@@ -51,6 +82,7 @@ module Mj
|
|
51
82
|
add_candidate(controller_path, "controller", to: candidates)
|
52
83
|
end
|
53
84
|
end
|
85
|
+
# rubocop:enable Metrics/MethodLength
|
54
86
|
end
|
55
87
|
end
|
56
88
|
end
|
@@ -19,6 +19,9 @@ module Mj
|
|
19
19
|
|
20
20
|
# lib files
|
21
21
|
add_candidate("lib/#{ruby_file.class_path}.rb", "lib", to: candidates)
|
22
|
+
add_candidate("#{ruby_file.class_path}.rb", "lib", to: candidates)
|
23
|
+
add_candidate("spec/lib/#{ruby_file.class_path}_spec.rb", :spec, to: candidates)
|
24
|
+
add_candidate("test/lib/#{ruby_file.class_path}_test.rb", :minitest, to: candidates)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -7,9 +7,10 @@ module Mj
|
|
7
7
|
class RubyFile < AlternativeFile::CurrentFile
|
8
8
|
def class_path
|
9
9
|
path_without_extension
|
10
|
+
.without_prefix("spec")
|
11
|
+
.without_prefix("test")
|
10
12
|
.without_prefix("app")
|
11
13
|
.without_prefix("lib")
|
12
|
-
.without_prefix("spec")
|
13
14
|
.without_suffix("_spec")
|
14
15
|
.without_suffix("_test")
|
15
16
|
.trim_slashes
|
data/lib/mj/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
|
-
rubygems_version: 3.2.
|
88
|
+
rubygems_version: 3.2.33
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: My personal CLI
|