Class: Jiminy::Recording::ProsopiteExt::TmpFileRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/jiminy/recording/prosopite_ext/tmp_file_recorder.rb

Instance Method Summary collapse

Instance Method Details

#record(location:, queries:) ⇒ Object

rubocop:disable Metrics/AbcSize



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jiminy/recording/prosopite_ext/tmp_file_recorder.rb', line 10

def record(location:, queries:)
  yaml_content = File.read(Jiminy.config.temp_file_location)
  array = YAML.safe_load(yaml_content)
  n_plus_one = NPlusOne.new(location: location, queries: queries)

  if filepath_ignored?(n_plus_one.file)
    Jiminy.logger.debug { "Ignoring n+1 instance #{n_plus_one}" }
    return
  end

  if location_in_array?(location, array)
    Jiminy.logger.debug { "Already reported n+1 instance #{n_plus_one}" }
    return
  end

  array << n_plus_one.to_h
  File.write(Jiminy.config.temp_file_location, array.to_yaml)
end