module Watchdocs::Rails::Recordings

Attributes

store[R]

Public Class Methods

clear!(from_specs: true) click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 16
def clear!(from_specs: true)
  set_store(from_specs)
  clear_recordings
rescue StandardError => e
  $stderr.puts "Watchdocs Error: #{e.message}.
                Please report it to hi@watchdocs.io"
end
export(recordings = nil, from_specs: true) click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 24
def export(recordings = nil, from_specs: true)
  set_store(from_specs)
  recordings ||= current_recordings
  return unless current_recordings
  export_recorings(recordings) && clear!(from_specs: from_specs)
  $stderr.puts "Watchdocs: #{recordings.count} requests exported"
rescue StandardError => e
  $stderr.puts "Watchdocs Error: #{e.message}.
                Please report it to hi@watchdocs.io"
end
record(new_call, from_specs: true) click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 10
def record(new_call, from_specs: true)
  Recorder.new(
    from_specs: from_specs
  ).call(new_call)
end

Private Class Methods

clear_recordings() click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 41
def clear_recordings
  store.delete!
end
current_recordings() click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 37
def current_recordings
  store.read
end
export_recorings(recordings) click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 45
def export_recorings(recordings)
  Exporter.export(recordings)
end
set_store(from_specs) click to toggle source
# File lib/watchdocs/rails/recordings.rb, line 49
def set_store(from_specs)
  @store = if from_specs
             Rails::Buffer::MemoryBuffer
           else
             Rails::Buffer::FileBuffer
           end
end