mj 0.3.0 → 0.4.0
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/current_file.rb +4 -0
- data/lib/mj/alternative_file/resolvers/base.rb +10 -6
- data/lib/mj/alternative_file/resolvers/ruby/rails_controller_resolver.rb +12 -14
- data/lib/mj/alternative_file/resolvers/ruby/rails_resolver.rb +5 -5
- data/lib/mj/alternative_file/resolvers/ruby/view_component_resolver.rb +35 -0
- data/lib/mj/alternative_file/thor_command.rb +2 -0
- data/lib/mj/cli.rb +7 -1
- data/lib/mj/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69dc7451d088acc2d1a698e89db77361de5cdf2bb07bb137b8e63ddc224f6fc2
|
4
|
+
data.tar.gz: 7f1ac63a2d0b9e44845242bbf77f1154a0f14da3ba2a2a361b9dc90015a67904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34c4108ff9d1bb29b9efa6051c5bf7399ac93fa7bb543cb3fcddfbbeabbd7be27fc19c8b66e088a56be329fd1291893c5a768699e74aaaa4d0c16ccdf4a9ac66
|
7
|
+
data.tar.gz: cc60732174983f0616a47a7735ab34229234676fea0a6e472adc639bfad107823c95b0f3498e2246ec7dccb2a3e40d23a290fd430ec417db5e98f3e7e0c6482f
|
data/Gemfile.lock
CHANGED
@@ -5,19 +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(
|
19
|
-
|
20
|
-
|
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)
|
21
25
|
end
|
22
26
|
|
23
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,14 +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
19
|
|
20
20
|
# lib files
|
21
|
-
|
21
|
+
add_candidate("lib/#{ruby_file.class_path}.rb", "lib", to: candidates)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,35 @@
|
|
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?("component.rb", "component.html.erb")
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_candidates(file, candidates)
|
15
|
+
if file.end_with?("component.rb")
|
16
|
+
return resolve_template(file, candidates)
|
17
|
+
end
|
18
|
+
|
19
|
+
resolve_component_class(file, candidates)
|
20
|
+
end
|
21
|
+
|
22
|
+
def resolve_template(file, candidates)
|
23
|
+
file_name = file.sub(/_component.rb$/, "_component.html.erb")
|
24
|
+
add_candidate(file_name, "component_template", to: candidates)
|
25
|
+
end
|
26
|
+
|
27
|
+
def resolve_component_class(file, candidates)
|
28
|
+
file_name = file.sub(/_component.html.erb$/, "_component.rb")
|
29
|
+
add_candidate(file_name, "component_class", to: candidates)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
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
|
@@ -46,6 +47,7 @@ module Mj
|
|
46
47
|
@resolvers ||= AlternativeFile::Resolver.new.tap do |resolvers|
|
47
48
|
resolvers.add(Resolvers::Ruby::RailsResolver.new)
|
48
49
|
resolvers.add(Resolvers::Ruby::RailsControllerResolver.new)
|
50
|
+
resolvers.add(Resolvers::Ruby::ViewComponentResolver.new)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
@@ -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
|