mj 0.4.0 → 0.5.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/candidates.rb +4 -0
- data/lib/mj/alternative_file/commands/list_command.rb +28 -0
- data/lib/mj/alternative_file/commands/list_command_handler.rb +33 -0
- data/lib/mj/alternative_file/resolvers/ruby/view_component_resolver.rb +10 -4
- data/lib/mj/alternative_file/thor_command.rb +15 -27
- data/lib/mj/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a69d697244fdee8394820682a99fdc199ec5b1b912c2d573f4b181c541100dc3
|
4
|
+
data.tar.gz: 7ac9b8f07c95ce5af439ddbfb18cb8d0385a1e1a3815188a5016757cfac978d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19af4785f9f6441ca64ac8b721ef45db5e4b4ddff476f077b1f8430711ecad83070e643a102dd867e0d66bd7c6b9d1eb6510d37f5b58e1dbb92531b33e4025f8
|
7
|
+
data.tar.gz: fade8044f50496e2e2cf1a6d804e39fe69ae94b518faf733d489a3e17e2a48ba4af99dba3011ec647d0c3ea4d86498810f787d9d07ab5d47082636ab9c858d56
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mj
|
4
|
+
module AlternativeFile
|
5
|
+
module Commands
|
6
|
+
class ListCommand
|
7
|
+
attr_reader :file
|
8
|
+
|
9
|
+
def initialize(file, options)
|
10
|
+
@file = CurrentFile.new(file.to_s)
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def exists?
|
15
|
+
@options[:exists]
|
16
|
+
end
|
17
|
+
|
18
|
+
def types
|
19
|
+
@options[:types].to_s.split(",")
|
20
|
+
end
|
21
|
+
|
22
|
+
def debug?
|
23
|
+
@options[:debug]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mj
|
4
|
+
module AlternativeFile
|
5
|
+
module Commands
|
6
|
+
class ListCommandHandler
|
7
|
+
def initialize(resolvers:)
|
8
|
+
@resolvers = resolvers
|
9
|
+
end
|
10
|
+
|
11
|
+
# rubocop:disable Metrics/MethodLength
|
12
|
+
def handle(command)
|
13
|
+
candidates = @resolvers.resolve(command.file)
|
14
|
+
|
15
|
+
if command.types.any?
|
16
|
+
candidates = candidates.of_types(command.types)
|
17
|
+
end
|
18
|
+
|
19
|
+
if command.exists?
|
20
|
+
candidates = candidates.existing
|
21
|
+
end
|
22
|
+
|
23
|
+
unless command.debug?
|
24
|
+
candidates = candidates.unique
|
25
|
+
end
|
26
|
+
|
27
|
+
candidates.sorted_by_path
|
28
|
+
end
|
29
|
+
# rubocop:enable Metrics/MethodLength
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -8,11 +8,16 @@ module Mj
|
|
8
8
|
private
|
9
9
|
|
10
10
|
def apply_to?(file)
|
11
|
-
file.end_with?(
|
11
|
+
file.end_with?(
|
12
|
+
"component.rb",
|
13
|
+
"component.html.erb",
|
14
|
+
"component_test.rb",
|
15
|
+
"component_spec.rb"
|
16
|
+
)
|
12
17
|
end
|
13
18
|
|
14
19
|
def add_candidates(file, candidates)
|
15
|
-
if file.
|
20
|
+
if file.extension == "rb"
|
16
21
|
return resolve_template(file, candidates)
|
17
22
|
end
|
18
23
|
|
@@ -20,8 +25,9 @@ module Mj
|
|
20
25
|
end
|
21
26
|
|
22
27
|
def resolve_template(file, candidates)
|
23
|
-
|
24
|
-
|
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)
|
25
31
|
end
|
26
32
|
|
27
33
|
def resolve_component_class(file, candidates)
|
@@ -10,6 +10,8 @@ require_relative "resolvers/ruby/rails_resolver"
|
|
10
10
|
require_relative "resolvers/ruby/rails_controller_resolver"
|
11
11
|
require_relative "resolvers/ruby/view_component_resolver"
|
12
12
|
require_relative "resolvers/ruby/ruby_file"
|
13
|
+
require_relative "commands/list_command_handler"
|
14
|
+
require_relative "commands/list_command"
|
13
15
|
|
14
16
|
module Mj
|
15
17
|
module AlternativeFile
|
@@ -19,8 +21,10 @@ module Mj
|
|
19
21
|
option :exists, type: :boolean, banner: "files that exist", aliases: :e
|
20
22
|
option :debug, type: :boolean, banner: "print debug information", aliases: :d
|
21
23
|
def list(reference_file)
|
22
|
-
|
23
|
-
|
24
|
+
handler = Commands::ListCommandHandler.new(resolvers: self.class.resolvers)
|
25
|
+
command = Commands::ListCommand.new(reference_file, options)
|
26
|
+
candidates = handler.handle(command)
|
27
|
+
print_candidates(candidates)
|
24
28
|
end
|
25
29
|
|
26
30
|
desc "next <reference-file>", "Next alternative file"
|
@@ -28,8 +32,10 @@ module Mj
|
|
28
32
|
option :exists, type: :boolean, banner: "files that exist", aliases: :e
|
29
33
|
option :debug, type: :boolean, banner: "print debug information", aliases: :d
|
30
34
|
def next(reference_file)
|
31
|
-
|
32
|
-
|
35
|
+
handler = Commands::ListCommandHandler.new(resolvers: self.class.resolvers)
|
36
|
+
command = Commands::ListCommand.new(reference_file, options)
|
37
|
+
candidates = handler.handle(command)
|
38
|
+
candidate = candidates.after(command.file)
|
33
39
|
print_candidates([candidate].compact)
|
34
40
|
end
|
35
41
|
|
@@ -38,8 +44,10 @@ module Mj
|
|
38
44
|
option :exists, type: :boolean, banner: "files that exist", aliases: :e
|
39
45
|
option :debug, type: :boolean, banner: "print debug information", aliases: :d
|
40
46
|
def prev(reference_file)
|
41
|
-
|
42
|
-
|
47
|
+
handler = Commands::ListCommandHandler.new(resolvers: self.class.resolvers)
|
48
|
+
command = Commands::ListCommand.new(reference_file, options)
|
49
|
+
candidates = handler.handle(command)
|
50
|
+
candidate = candidates.before(command.file)
|
43
51
|
print_candidates([candidate].compact)
|
44
52
|
end
|
45
53
|
|
@@ -54,28 +62,8 @@ module Mj
|
|
54
62
|
private
|
55
63
|
|
56
64
|
def print_candidates(candidates)
|
57
|
-
$stdout.puts candidates.map { |i| i.to_s(debug: options[:debug]) }.join("
|
65
|
+
$stdout.puts candidates.map { |i| i.to_s(debug: options[:debug]) }.join("\n")
|
58
66
|
end
|
59
|
-
|
60
|
-
# rubocop:disable Metrics/MethodLength
|
61
|
-
def resolve(file)
|
62
|
-
candidates = self.class.resolvers.resolve(file)
|
63
|
-
|
64
|
-
if options[:types]
|
65
|
-
candidates = candidates.of_types(options[:types].to_s.split(","))
|
66
|
-
end
|
67
|
-
|
68
|
-
if options[:exists]
|
69
|
-
candidates = candidates.existing
|
70
|
-
end
|
71
|
-
|
72
|
-
unless options[:debug]
|
73
|
-
candidates = candidates.unique
|
74
|
-
end
|
75
|
-
|
76
|
-
candidates
|
77
|
-
end
|
78
|
-
# rubocop:enable Metrics/MethodLength
|
79
67
|
end
|
80
68
|
end
|
81
69
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
@@ -47,6 +47,8 @@ files:
|
|
47
47
|
- lib/mj.rb
|
48
48
|
- lib/mj/alternative_file/candidate.rb
|
49
49
|
- lib/mj/alternative_file/candidates.rb
|
50
|
+
- lib/mj/alternative_file/commands/list_command.rb
|
51
|
+
- lib/mj/alternative_file/commands/list_command_handler.rb
|
50
52
|
- lib/mj/alternative_file/current_file.rb
|
51
53
|
- lib/mj/alternative_file/resolver.rb
|
52
54
|
- lib/mj/alternative_file/resolvers/base.rb
|