factory_trace 3.0.0 → 3.0.1

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: bd70e8ea6fe8ffb3e815147ea925478d36f4d298b9bbbd5b359b7d5e900d5265
4
- data.tar.gz: e838d1f5525179c4fba7fa6daba3baf7ab8b23d27e981076069c3a4d33268472
3
+ metadata.gz: 9150973821d1c8196bf9dc7ba0ccbaa9c5e81cc397fed0613f2b0e0086104ec7
4
+ data.tar.gz: cbbf862a0a4aa1d3a436329dd4e2d2f94c2c700a1f5e0a07da5b08395f4fa89e
5
5
  SHA512:
6
- metadata.gz: 0a0b4c5d0b471d570a4ab18567feed01559f861363779e4ba5010e8eb1b1a75a159d3affe54b0742da8c1909095df14cee0ec45eb7fbefcf3e594b8a58140037
7
- data.tar.gz: 54b1804ed50d4ba0f327e9f18d100ad9c95c39c7ce6a373ed846aa5bbf8c6a9e7f5b42560db21b7922927aa135574a8f6d1acef6b39179b56bc911ba00dba151
6
+ metadata.gz: c12b5e6ee4de364e37c99a01c363931c35f6d5f32af1a9525e9ed990c11209c38473f1a9809eb2bc980237cb069cbffb017f3c44c50bb33f5b41b90645f46037
7
+ data.tar.gz: 245cc1ad516ff4a706f6f32fa6c96f2bf8d55b4ec032e9ebe10ca835f02bd06b501f94a5b5b9c742c2962d56c6c3e3eddfe55fa42e3e6d95376b545e2693ed6f
data/exe/factory_trace CHANGED
@@ -7,9 +7,16 @@ require "factory_trace"
7
7
  fail "You should pass at least one file with traced information.\nYou can generate it using only_trace mode." if ARGV.empty?
8
8
 
9
9
  config = FactoryTrace.configuration
10
- hash = FactoryTrace::Readers::TraceReader.read_from_files(*ARGV)
11
- reports = FactoryTrace::Processors::FindUnused.call(hash[:defined], hash[:used])
12
- code = (reports.any? { |report| report[:code] == :unused && !report.key?(:value) }) ? 1 : 0
10
+ writer = FactoryTrace::Writers::ReportWriter.new(config.out, config)
11
+ code = 0
12
+
13
+ %i[factory_bot fixtures].each do |kind|
14
+ result = FactoryTrace::Readers::TraceReader.read_from_files(kind, *ARGV)
15
+ reports = FactoryTrace::Processors::FindUnused.call(result[:defined], result[:used])
16
+ if reports.any? { |report| report[:code] == :unused && !report.key?(:value) }
17
+ code = 1
18
+ end
19
+ writer.write(reports, kind: kind)
20
+ end
13
21
 
14
- FactoryTrace::Writers::ReportWriter.new(config.out, config).write(reports)
15
22
  exit(code)
@@ -3,20 +3,20 @@
3
3
  module FactoryTrace
4
4
  module Readers
5
5
  class TraceReader
6
- attr_reader :io, :configuration
6
+ attr_reader :io, :configuration, :kind
7
7
 
8
8
  # Read the data from files and merge it
9
9
  #
10
10
  # @return [Hash<Symbol, FactoryTrace::Structures::Collection>]
11
- def self.read_from_files(*file_names, configuration: Configuration.new)
11
+ def self.read_from_files(kind, *file_names, configuration: Configuration.new)
12
12
  result = {defined: FactoryTrace::Structures::Collection.new, used: FactoryTrace::Structures::Collection.new}
13
13
 
14
14
  file_names.each do |file_name|
15
15
  File.open(file_name, "r") do |file|
16
- data = new(file, configuration: configuration).read
16
+ data = new(kind, file, configuration: configuration).read
17
17
 
18
18
  [:defined, :used].each do |key|
19
- result[key].merge!(data[key])
19
+ result[key].merge!(data[key]) unless data.empty?
20
20
  end
21
21
  end
22
22
  end
@@ -24,7 +24,8 @@ module FactoryTrace
24
24
  result
25
25
  end
26
26
 
27
- def initialize(io, configuration: Configuration.new)
27
+ def initialize(kind, io, configuration: Configuration.new)
28
+ @kind = kind
28
29
  @io = io
29
30
  @configuration = configuration
30
31
  end
@@ -35,9 +36,14 @@ module FactoryTrace
35
36
  def read
36
37
  hash = JSON.parse(io.read)
37
38
 
39
+ defined = hash["defined"][kind.to_s]
40
+ used = hash["used"][kind.to_s]
41
+
42
+ return {} if defined.nil? || used.nil?
43
+
38
44
  {
39
- defined: parse_collection(hash["defined"]),
40
- used: parse_collection(hash["used"])
45
+ defined: parse_collection(defined),
46
+ used: parse_collection(used)
41
47
  }
42
48
  end
43
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FactoryTrace
4
- VERSION = "3.0.0"
4
+ VERSION = "3.0.1"
5
5
  end
@@ -18,7 +18,7 @@ module FactoryTrace
18
18
  # @param [Array<Hash>] results
19
19
  # @param [Symbol] kind - :factory (default) or :fixture
20
20
  def write(results, kind:)
21
- io.puts("")
21
+ io.puts("") unless file?
22
22
 
23
23
  total_color = (results.any? { |result| result[:code] == :unused && !result.key?(:value) }) ? :red : :green
24
24
 
@@ -3,16 +3,9 @@
3
3
  module FactoryTrace
4
4
  module Writers
5
5
  class TraceWriter < Writer
6
- # @param [FactoryTrace::Structures::Collection] defined
7
- # @param [FactoryTrace::Structures::Collection] used
8
- def write(defined, used, kind:)
9
- io.puts("")
10
- text =
11
- case kind
12
- when :factory_bot then "FactoryBot"
13
- when :fixtures then "Fixtures"
14
- end
15
- io.puts("#{text} definitions and usages:")
6
+ # @param [Hash] defined
7
+ # @param [Hash] used
8
+ def write(defined, used)
16
9
  io.puts(JSON.pretty_generate(defined: defined.to_h, used: used.to_h))
17
10
  end
18
11
  end
@@ -9,6 +9,10 @@ module FactoryTrace
9
9
  @io = io
10
10
  @configuration = configuration
11
11
  end
12
+
13
+ def file?
14
+ io.is_a?(File)
15
+ end
12
16
  end
13
17
  end
14
18
  end
data/lib/factory_trace.rb CHANGED
@@ -61,8 +61,14 @@ module FactoryTrace
61
61
  writer.write(Processors::FindUnused.call(defined_fixtures, used_fixtures), kind: :fixtures) if fixtures?
62
62
  elsif configuration.mode?(:trace_only)
63
63
  writer = Writers::TraceWriter.new(configuration.out, configuration)
64
- writer.write(defined, used, kind: :factory_bot) if factory_bot?
65
- writer.write(defined_fixtures, used_fixtures, kind: :fixtures) if fixtures?
64
+ writer.write(mix(defined_fixtures, defined), mix(used_fixtures, used))
65
+ end
66
+ end
67
+
68
+ def mix(fixtures, factory_bot)
69
+ {}.tap do |result|
70
+ result[:fixtures] = fixtures.to_h if fixtures?
71
+ result[:factory_bot] = factory_bot.to_h if factory_bot?
66
72
  end
67
73
  end
68
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - djezzzl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-03-18 00:00:00.000000000 Z
11
+ date: 2026-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot