Class: RailsProof::ReviewStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_proof/review_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:) ⇒ ReviewStore

Returns a new instance of ReviewStore.



12
13
14
# File 'lib/rails_proof/review_store.rb', line 12

def initialize(root:)
  @root = Pathname.new(root)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/rails_proof/review_store.rb', line 10

def root
  @root
end

Instance Method Details

#outstanding_findings(target_path:, test_file_path:) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rails_proof/review_store.rb', line 70

def outstanding_findings(
  target_path:,
  test_file_path:
)
  fingerprint = target_fingerprint(target_path)

  return [] unless fingerprint

  review_paths.filter_map do |path|
    record = read_record(path)

    next unless record
    next unless record["status"] == "needs_review"
    next unless record["target_path"] == target_path
    next unless record["test_file_path"] == test_file_path
    next unless record["target_fingerprint"] == fingerprint

    record
  end
end

#save(concern:, test_output:, test_file_path:, test_class_name:, target_path: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rails_proof/review_store.rb', line 16

def save(
  concern:,
  test_output:,
  test_file_path:,
  test_class_name:,
  target_path: nil
)
  review_directory.mkpath

  timestamp = Time.now.utc.iso8601
  fingerprint = target_fingerprint(target_path)

  existing_path = find_existing_review(
    concern: concern,
    target_path: target_path,
    test_file_path: test_file_path,
    target_fingerprint: fingerprint
  )

  if existing_path
    update_existing_review(
      path: existing_path,
      concern: concern,
      test_output: test_output,
      timestamp: timestamp
    )

    return existing_path
  end

  path = review_directory.join(
    review_filename(
      test_class_name: test_class_name,
      name: concern_name(concern)
    )
  )

  path.write(
    JSON.pretty_generate(
      review_record(
        concern: concern,
        test_output: test_output,
        test_file_path: test_file_path,
        test_class_name: test_class_name,
        target_path: target_path,
        target_fingerprint: fingerprint,
        timestamp: timestamp
      )
    ) + "\n"
  )

  path
end