Sha256: 81181dd5e15977a10294c1bf91580716e6a450540c7478ae0a74ff27b3ae5b54

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'net/http'

require 'netrecording/version'
require 'netrecording/http'
require 'netrecording/http_header'
require 'fakeweb'

module Netrecording
  @@records = []
  @@recording = false
  @@configured = false

  def self.records
    @@records
  end

  def self.start_recording!
    _configure
    @@recording = true
  end

  def self.stop_recording!
    @@recording = false
  end

  def self.recording?
    !! @@recording
  end

  def self.save!(file_path = nil)
    unless file_path
      file_path = File.join(Rails.root, 'tmp', 'netrecording', Time.current.strftime("%Y-%m-%d_%H%M%S.yml"))
      FileUtils.mkdir_p(File.dirname file_path) unless File.exist?(File.dirname file_path)
    end

    File.open(file_path, 'w') do |fp|
      fp.puts @@records.to_yaml
    end
    @@records = []

    file_path
  end

  def self.clear_records!
    @@records = []
  end

  def self._configure
    return if @@configured
    Net::HTTP.extend(Netrecording::NetHTTP)
    Net::HTTPHeader.extend(Netrecording::NetHTTPHeader)
    @@configured = true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
netrecording-0.1.1 lib/netrecording.rb