mj 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45d956a04733940240dd116cbd23f2bce4f7489d98954b6eebf4bef7ad650265
4
- data.tar.gz: bfd4982a65d4794f54c662fb62aed6952f35af192708984462aa286522a273df
3
+ metadata.gz: 69dc7451d088acc2d1a698e89db77361de5cdf2bb07bb137b8e63ddc224f6fc2
4
+ data.tar.gz: 7f1ac63a2d0b9e44845242bbf77f1154a0f14da3ba2a2a361b9dc90015a67904
5
5
  SHA512:
6
- metadata.gz: 3f7d3cbda48c13aa55f08da78e2d072c7c70322c2d53fd6048e68885acda47b969bf36634c4e41d8fcd98f809821fcd0ab6c3f8a0e8b5d2be35d1bbca4c3e141
7
- data.tar.gz: 3e51c76e04d0dafed9c49ec6a548dbc6647727cde8fe930e74cff81eca818a67d8bf9b657717be1b55f9979eb29f814dfdd533c8b919492ffe188d9fcc9cd036
6
+ metadata.gz: 34c4108ff9d1bb29b9efa6051c5bf7399ac93fa7bb543cb3fcddfbbeabbd7be27fc19c8b66e088a56be329fd1291893c5a768699e74aaaa4d0c16ccdf4a9ac66
7
+ data.tar.gz: cc60732174983f0616a47a7735ab34229234676fea0a6e472adc639bfad107823c95b0f3498e2246ec7dccb2a3e40d23a290fd430ec417db5e98f3e7e0c6482f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mj (0.3.0)
4
+ mj (0.4.0)
5
5
  thor (~> 1.2.1)
6
6
 
7
7
  GEM
@@ -41,6 +41,10 @@ module Mj
41
41
  to_s.start_with?(*args)
42
42
  end
43
43
 
44
+ def end_with?(*args)
45
+ to_s.end_with?(*args)
46
+ end
47
+
44
48
  def without_prefix(prefix)
45
49
  sub(/^#{prefix}/, "")
46
50
  end
@@ -5,19 +5,23 @@ module Mj
5
5
  module Resolvers
6
6
  class Base
7
7
  def resolve(file)
8
- [].tap do |alternatives|
8
+ [].tap do |candidates|
9
9
  if apply_to?(file)
10
- create_alternatives(file, alternatives)
10
+ add_candidates(file, candidates)
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- def create_candidate(path, type)
18
- AlternativeFile::Candidate.new(path: path, type: type, metadata: {
19
- resolved_by: self.class.name
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 create_alternatives(file, alternatives)
20
+ def add_candidates(file, candidates)
21
21
  if file.start_with?("app/controllers")
22
- add_controller_test(file, alternatives, "spec")
23
- add_controller_test(file, alternatives, "test")
24
- add_integration_test(file, alternatives, "spec")
25
- add_integration_test(file, alternatives, "test")
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, alternatives)
29
+ resolve_controller(file, candidates)
30
30
  end
31
31
 
32
- def add_integration_test(file, alternatives, type)
32
+ def add_integration_test(file, candidates, type)
33
33
  path = file.without_prefix("app/controllers").without_suffix(".rb").trim_slashes
34
- alternative = create_candidate("#{type}/integration/#{path}_#{type}.rb", "integration_#{type}")
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, alternatives, type)
37
+ def add_controller_test(file, candidates, type)
39
38
  path = file.without_prefix("app/controllers").without_suffix(".rb").trim_slashes
40
- alternative = create_candidate("#{type}/controllers/#{path}_#{type}.rb", "controller_#{type}")
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, alternatives)
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
- alternatives.push(create_candidate(controller_path, "controller"))
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 create_alternatives(file, alternatives)
14
+ def add_candidates(file, candidates)
15
15
  ruby_file = Ruby::RubyFile.new(file)
16
- alternatives.push(create_candidate("app/#{ruby_file.class_path}.rb", "model"))
17
- alternatives.push(create_candidate("spec/#{ruby_file.class_path}_spec.rb", "spec"))
18
- alternatives.push(create_candidate("test/#{ruby_file.class_path}_test.rb", "minitest"))
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
- alternatives.push(create_candidate("lib/#{ruby_file.class_path}.rb", "lib"))
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 "alternative_file", "lists alternative files"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mj
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.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