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 +4 -4
- data/exe/factory_trace +11 -4
- data/lib/factory_trace/readers/trace_reader.rb +13 -7
- data/lib/factory_trace/version.rb +1 -1
- data/lib/factory_trace/writers/report_writer.rb +1 -1
- data/lib/factory_trace/writers/trace_writer.rb +3 -10
- data/lib/factory_trace/writers/writer.rb +4 -0
- data/lib/factory_trace.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9150973821d1c8196bf9dc7ba0ccbaa9c5e81cc397fed0613f2b0e0086104ec7
|
|
4
|
+
data.tar.gz: cbbf862a0a4aa1d3a436329dd4e2d2f94c2c700a1f5e0a07da5b08395f4fa89e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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(
|
|
40
|
-
used: parse_collection(
|
|
45
|
+
defined: parse_collection(defined),
|
|
46
|
+
used: parse_collection(used)
|
|
41
47
|
}
|
|
42
48
|
end
|
|
43
49
|
|
|
@@ -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 [
|
|
7
|
-
# @param [
|
|
8
|
-
def write(defined, used
|
|
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
|
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,
|
|
65
|
-
|
|
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.
|
|
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-
|
|
11
|
+
date: 2026-03-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: factory_bot
|