mj 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1315dc125dadf7c6af6dfdaba6b81c52afd1aea322676a050d01ff6b3af6cd12
4
- data.tar.gz: 975b749f8c67d2e9380c6b4df17b457e9e88f04ebbb3e74539b27b9816cb17c2
3
+ metadata.gz: 45d956a04733940240dd116cbd23f2bce4f7489d98954b6eebf4bef7ad650265
4
+ data.tar.gz: bfd4982a65d4794f54c662fb62aed6952f35af192708984462aa286522a273df
5
5
  SHA512:
6
- metadata.gz: 7dc77ebcfe8f3b8b02972b027cba9a820f3efade191fd925ed53d25ad3500eba4ce17054028fe828575a23b12696205cb8933dd2a26bb2d81648d2dd7355302c
7
- data.tar.gz: 63b69114fa66a7ccfdbe81f3d4e10a3d8bf873adef015a76e7f7e460e2df1ab630f949f14b6d5e7ff0bd031f43192f2e813fa06878cc547e12f8b44705554af6
6
+ metadata.gz: 3f7d3cbda48c13aa55f08da78e2d072c7c70322c2d53fd6048e68885acda47b969bf36634c4e41d8fcd98f809821fcd0ab6c3f8a0e8b5d2be35d1bbca4c3e141
7
+ data.tar.gz: 3e51c76e04d0dafed9c49ec6a548dbc6647727cde8fe930e74cff81eca818a67d8bf9b657717be1b55f9979eb29f814dfdd533c8b919492ffe188d9fcc9cd036
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mj (0.2.0)
4
+ mj (0.3.0)
5
5
  thor (~> 1.2.1)
6
6
 
7
7
  GEM
@@ -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
@@ -15,7 +15,9 @@ module Mj
15
15
  private
16
16
 
17
17
  def create_candidate(path, type)
18
- AlternativeFile::Candidate.new(path: path, type: type)
18
+ AlternativeFile::Candidate.new(path: path, type: type, metadata: {
19
+ resolved_by: self.class.name
20
+ })
19
21
  end
20
22
 
21
23
  def apply_to?(_file)
@@ -16,6 +16,9 @@ module Mj
16
16
  alternatives.push(create_candidate("app/#{ruby_file.class_path}.rb", "model"))
17
17
  alternatives.push(create_candidate("spec/#{ruby_file.class_path}_spec.rb", "spec"))
18
18
  alternatives.push(create_candidate("test/#{ruby_file.class_path}_test.rb", "minitest"))
19
+
20
+ # lib files
21
+ alternatives.push(create_candidate("lib/#{ruby_file.class_path}.rb", "lib"))
19
22
  end
20
23
  end
21
24
  end
@@ -8,6 +8,7 @@ module Mj
8
8
  def class_path
9
9
  path_without_extension
10
10
  .without_prefix("app")
11
+ .without_prefix("lib")
11
12
  .without_prefix("spec")
12
13
  .without_suffix("_spec")
13
14
  .without_suffix("_test")
@@ -16,6 +16,7 @@ module Mj
16
16
  desc "list <reference-file>", "List all alternative files"
17
17
  option :types, type: :string, banner: "<comma-separated-types>", aliases: :t
18
18
  option :exists, type: :boolean, banner: "files that exist", aliases: :e
19
+ option :debug, type: :boolean, banner: "print debug information", aliases: :d
19
20
  def list(reference_file)
20
21
  file = CurrentFile.new(reference_file)
21
22
  print_candidates(resolve(file))
@@ -24,6 +25,7 @@ module Mj
24
25
  desc "next <reference-file>", "Next alternative file"
25
26
  option :types, type: :string, banner: "<comma-separated-types>", aliases: :t
26
27
  option :exists, type: :boolean, banner: "files that exist", aliases: :e
28
+ option :debug, type: :boolean, banner: "print debug information", aliases: :d
27
29
  def next(reference_file)
28
30
  file = CurrentFile.new(reference_file)
29
31
  candidate = resolve(file).after(file)
@@ -33,6 +35,7 @@ module Mj
33
35
  desc "prev <reference-file>", "Previous alternative file"
34
36
  option :types, type: :string, banner: "<comma-separated-types>", aliases: :t
35
37
  option :exists, type: :boolean, banner: "files that exist", aliases: :e
38
+ option :debug, type: :boolean, banner: "print debug information", aliases: :d
36
39
  def prev(reference_file)
37
40
  file = CurrentFile.new(reference_file)
38
41
  candidate = resolve(file).before(file)
@@ -49,9 +52,10 @@ module Mj
49
52
  private
50
53
 
51
54
  def print_candidates(candidates)
52
- $stdout.puts candidates.map(&:path).join(" ")
55
+ $stdout.puts candidates.map { |i| i.to_s(debug: options[:debug]) }.join(" ")
53
56
  end
54
57
 
58
+ # rubocop:disable Metrics/MethodLength
55
59
  def resolve(file)
56
60
  candidates = self.class.resolvers.resolve(file)
57
61
 
@@ -63,8 +67,13 @@ module Mj
63
67
  candidates = candidates.existing
64
68
  end
65
69
 
66
- candidates.unique
70
+ unless options[:debug]
71
+ candidates = candidates.unique
72
+ end
73
+
74
+ candidates
67
75
  end
76
+ # rubocop:enable Metrics/MethodLength
68
77
  end
69
78
  end
70
79
  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.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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.2.0
4
+ version: 0.3.0
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-13 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor