mj 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mj/alternative_file/candidate.rb +27 -1
- data/lib/mj/alternative_file/current_file.rb +4 -0
- data/lib/mj/alternative_file/resolvers/base.rb +10 -4
- data/lib/mj/alternative_file/resolvers/ruby/rails_controller_resolver.rb +12 -14
- data/lib/mj/alternative_file/resolvers/ruby/rails_resolver.rb +7 -4
- data/lib/mj/alternative_file/resolvers/ruby/ruby_file.rb +1 -0
- data/lib/mj/alternative_file/resolvers/ruby/view_component_resolver.rb +41 -0
- data/lib/mj/alternative_file/thor_command.rb +13 -2
- data/lib/mj/cli.rb +7 -1
- data/lib/mj/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff905fc5978244944098033bf6ecfb671f1130c336e2f77c19beefab3c927dfe
|
4
|
+
data.tar.gz: 0560a8a156cb45bc2e8c459b021e721118e304abf55e92d25039cd9c9277ee24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b20134878fb83b50a0d9dda518dfc81500af893f522616605835e1ee2f6d78bbe824a9302d07131926d799bf308ee463efbfa9a0b4d37dce793fd2ab614c91d8
|
7
|
+
data.tar.gz: 30f12048aa54fa5070895859a99f0ffdd66bf35962d82e98952fc889b8a23afd9f4b650a89bea6645f28434210b173d90460196ab20a72f93fe68368cc50d87d
|
data/Gemfile.lock
CHANGED
@@ -6,9 +6,10 @@ module Mj
|
|
6
6
|
attr_reader :path
|
7
7
|
attr_reader :type
|
8
8
|
|
9
|
-
def initialize(path:, type:)
|
9
|
+
def initialize(path:, type:, metadata: {})
|
10
10
|
@path = path
|
11
11
|
@type = type
|
12
|
+
@metadata = metadata || {}
|
12
13
|
end
|
13
14
|
|
14
15
|
def exist?
|
@@ -22,6 +23,31 @@ module Mj
|
|
22
23
|
|
23
24
|
other.path == path && other.type == type
|
24
25
|
end
|
26
|
+
|
27
|
+
def to_s(debug: false)
|
28
|
+
parts = [path]
|
29
|
+
|
30
|
+
if debug
|
31
|
+
parts.push("(#{metadata})")
|
32
|
+
end
|
33
|
+
|
34
|
+
parts.join
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def metadata
|
40
|
+
data = {
|
41
|
+
type: type,
|
42
|
+
exists: exist?
|
43
|
+
}
|
44
|
+
|
45
|
+
@metadata.keys.sort.each do |key|
|
46
|
+
data[key] = @metadata[key]
|
47
|
+
end
|
48
|
+
|
49
|
+
data.map { |k, v| "#{k}:#{v}" }.join(",")
|
50
|
+
end
|
25
51
|
end
|
26
52
|
end
|
27
53
|
end
|
@@ -5,17 +5,23 @@ module Mj
|
|
5
5
|
module Resolvers
|
6
6
|
class Base
|
7
7
|
def resolve(file)
|
8
|
-
[].tap do |
|
8
|
+
[].tap do |candidates|
|
9
9
|
if apply_to?(file)
|
10
|
-
|
10
|
+
add_candidates(file, candidates)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def
|
18
|
-
AlternativeFile::Candidate.new(
|
17
|
+
def add_candidate(path, type, to:)
|
18
|
+
candidate = AlternativeFile::Candidate.new(
|
19
|
+
path: path.to_s,
|
20
|
+
type: type.to_s,
|
21
|
+
metadata: { resolved_by: self.class.name }
|
22
|
+
)
|
23
|
+
|
24
|
+
to.push(candidate)
|
19
25
|
end
|
20
26
|
|
21
27
|
def apply_to?(_file)
|
@@ -17,31 +17,29 @@ module Mj
|
|
17
17
|
)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def add_candidates(file, candidates)
|
21
21
|
if file.start_with?("app/controllers")
|
22
|
-
add_controller_test(file,
|
23
|
-
add_controller_test(file,
|
24
|
-
add_integration_test(file,
|
25
|
-
add_integration_test(file,
|
22
|
+
add_controller_test(file, candidates, "spec")
|
23
|
+
add_controller_test(file, candidates, "test")
|
24
|
+
add_integration_test(file, candidates, "spec")
|
25
|
+
add_integration_test(file, candidates, "test")
|
26
26
|
return
|
27
27
|
end
|
28
28
|
|
29
|
-
resolve_controller(file,
|
29
|
+
resolve_controller(file, candidates)
|
30
30
|
end
|
31
31
|
|
32
|
-
def add_integration_test(file,
|
32
|
+
def add_integration_test(file, candidates, type)
|
33
33
|
path = file.without_prefix("app/controllers").without_suffix(".rb").trim_slashes
|
34
|
-
|
35
|
-
alternatives.push(alternative)
|
34
|
+
add_candidate("#{type}/integration/#{path}_#{type}.rb", "integration_#{type}", to: candidates)
|
36
35
|
end
|
37
36
|
|
38
|
-
def add_controller_test(file,
|
37
|
+
def add_controller_test(file, candidates, type)
|
39
38
|
path = file.without_prefix("app/controllers").without_suffix(".rb").trim_slashes
|
40
|
-
|
41
|
-
alternatives.push(alternative)
|
39
|
+
add_candidate("#{type}/controllers/#{path}_#{type}.rb", "controller_#{type}", to: candidates)
|
42
40
|
end
|
43
41
|
|
44
|
-
def resolve_controller(file,
|
42
|
+
def resolve_controller(file, candidates)
|
45
43
|
controller_path = file.sub("test/integration", "app/controllers")
|
46
44
|
.sub("spec/integration", "app/controllers")
|
47
45
|
.sub("spec/controllers", "app/controllers")
|
@@ -50,7 +48,7 @@ module Mj
|
|
50
48
|
.sub("_test.rb", ".rb")
|
51
49
|
.to_s
|
52
50
|
|
53
|
-
|
51
|
+
add_candidate(controller_path, "controller", to: candidates)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
@@ -11,11 +11,14 @@ module Mj
|
|
11
11
|
file.extension == "rb"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def add_candidates(file, candidates)
|
15
15
|
ruby_file = Ruby::RubyFile.new(file)
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
add_candidate("app/#{ruby_file.class_path}.rb", :model, to: candidates)
|
17
|
+
add_candidate("spec/#{ruby_file.class_path}_spec.rb", :spec, to: candidates)
|
18
|
+
add_candidate("test/#{ruby_file.class_path}_test.rb", :minitest, to: candidates)
|
19
|
+
|
20
|
+
# lib files
|
21
|
+
add_candidate("lib/#{ruby_file.class_path}.rb", "lib", to: candidates)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mj
|
4
|
+
module AlternativeFile
|
5
|
+
module Resolvers
|
6
|
+
module Ruby
|
7
|
+
class ViewComponentResolver < Resolvers::Base
|
8
|
+
private
|
9
|
+
|
10
|
+
def apply_to?(file)
|
11
|
+
file.end_with?(
|
12
|
+
"component.rb",
|
13
|
+
"component.html.erb",
|
14
|
+
"component_test.rb",
|
15
|
+
"component_spec.rb"
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_candidates(file, candidates)
|
20
|
+
if file.extension == "rb"
|
21
|
+
return resolve_template(file, candidates)
|
22
|
+
end
|
23
|
+
|
24
|
+
resolve_component_class(file, candidates)
|
25
|
+
end
|
26
|
+
|
27
|
+
def resolve_template(file, candidates)
|
28
|
+
file = file.sub(/_component(_test|_spec)?.rb$/, "_component.html.erb")
|
29
|
+
file = file.sub(/^(spec|test)/, "app")
|
30
|
+
add_candidate(file, "component_template", to: candidates)
|
31
|
+
end
|
32
|
+
|
33
|
+
def resolve_component_class(file, candidates)
|
34
|
+
file_name = file.sub(/_component.html.erb$/, "_component.rb")
|
35
|
+
add_candidate(file_name, "component_class", to: candidates)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -8,6 +8,7 @@ require_relative "resolver"
|
|
8
8
|
require_relative "resolvers/base"
|
9
9
|
require_relative "resolvers/ruby/rails_resolver"
|
10
10
|
require_relative "resolvers/ruby/rails_controller_resolver"
|
11
|
+
require_relative "resolvers/ruby/view_component_resolver"
|
11
12
|
require_relative "resolvers/ruby/ruby_file"
|
12
13
|
|
13
14
|
module Mj
|
@@ -16,6 +17,7 @@ module Mj
|
|
16
17
|
desc "list <reference-file>", "List all alternative files"
|
17
18
|
option :types, type: :string, banner: "<comma-separated-types>", aliases: :t
|
18
19
|
option :exists, type: :boolean, banner: "files that exist", aliases: :e
|
20
|
+
option :debug, type: :boolean, banner: "print debug information", aliases: :d
|
19
21
|
def list(reference_file)
|
20
22
|
file = CurrentFile.new(reference_file)
|
21
23
|
print_candidates(resolve(file))
|
@@ -24,6 +26,7 @@ module Mj
|
|
24
26
|
desc "next <reference-file>", "Next alternative file"
|
25
27
|
option :types, type: :string, banner: "<comma-separated-types>", aliases: :t
|
26
28
|
option :exists, type: :boolean, banner: "files that exist", aliases: :e
|
29
|
+
option :debug, type: :boolean, banner: "print debug information", aliases: :d
|
27
30
|
def next(reference_file)
|
28
31
|
file = CurrentFile.new(reference_file)
|
29
32
|
candidate = resolve(file).after(file)
|
@@ -33,6 +36,7 @@ module Mj
|
|
33
36
|
desc "prev <reference-file>", "Previous alternative file"
|
34
37
|
option :types, type: :string, banner: "<comma-separated-types>", aliases: :t
|
35
38
|
option :exists, type: :boolean, banner: "files that exist", aliases: :e
|
39
|
+
option :debug, type: :boolean, banner: "print debug information", aliases: :d
|
36
40
|
def prev(reference_file)
|
37
41
|
file = CurrentFile.new(reference_file)
|
38
42
|
candidate = resolve(file).before(file)
|
@@ -43,15 +47,17 @@ module Mj
|
|
43
47
|
@resolvers ||= AlternativeFile::Resolver.new.tap do |resolvers|
|
44
48
|
resolvers.add(Resolvers::Ruby::RailsResolver.new)
|
45
49
|
resolvers.add(Resolvers::Ruby::RailsControllerResolver.new)
|
50
|
+
resolvers.add(Resolvers::Ruby::ViewComponentResolver.new)
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
54
|
private
|
50
55
|
|
51
56
|
def print_candidates(candidates)
|
52
|
-
$stdout.puts candidates.map(
|
57
|
+
$stdout.puts candidates.map { |i| i.to_s(debug: options[:debug]) }.join(" ")
|
53
58
|
end
|
54
59
|
|
60
|
+
# rubocop:disable Metrics/MethodLength
|
55
61
|
def resolve(file)
|
56
62
|
candidates = self.class.resolvers.resolve(file)
|
57
63
|
|
@@ -63,8 +69,13 @@ module Mj
|
|
63
69
|
candidates = candidates.existing
|
64
70
|
end
|
65
71
|
|
66
|
-
|
72
|
+
unless options[:debug]
|
73
|
+
candidates = candidates.unique
|
74
|
+
end
|
75
|
+
|
76
|
+
candidates
|
67
77
|
end
|
78
|
+
# rubocop:enable Metrics/MethodLength
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
data/lib/mj/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "thor"
|
4
|
+
require_relative "version"
|
4
5
|
require_relative "alternative_file/thor_command"
|
5
6
|
|
6
7
|
module Mj
|
@@ -9,7 +10,12 @@ module Mj
|
|
9
10
|
true
|
10
11
|
end
|
11
12
|
|
12
|
-
desc "
|
13
|
+
desc "version", "Prints the version"
|
14
|
+
def version
|
15
|
+
puts Mj::VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "alternative_file", "Lists alternative files"
|
13
19
|
subcommand "alternative_file", AlternativeFile::ThorCommand
|
14
20
|
end
|
15
21
|
end
|
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.
|
4
|
+
version: 0.4.1
|
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-03-
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/mj/alternative_file/resolvers/ruby/rails_controller_resolver.rb
|
54
54
|
- lib/mj/alternative_file/resolvers/ruby/rails_resolver.rb
|
55
55
|
- lib/mj/alternative_file/resolvers/ruby/ruby_file.rb
|
56
|
+
- lib/mj/alternative_file/resolvers/ruby/view_component_resolver.rb
|
56
57
|
- lib/mj/alternative_file/thor_command.rb
|
57
58
|
- lib/mj/cli.rb
|
58
59
|
- lib/mj/version.rb
|