Sha256: 8337b006fd70d3294c617a1578e32c43233b86800c3bb13f322527c0bd65a1c8

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

require 'watchdocs/rails/recordings/recorder'
require 'watchdocs/rails/recordings/exporter'

module Watchdocs
  module Rails
    module Recordings
      class << self
        attr_reader :store

        def record(new_call, from_specs: true)
          Recorder.new(
            from_specs: from_specs
          ).call(new_call)
        end

        def clear!(from_specs: true)
          set_store(from_specs)
          clear_recordings
        end

        def export(recordings = nil, from_specs: true)
          set_store(from_specs)
          recordings ||= current_recordings
          export_recorings(recordings) && clear!(from_specs: from_specs)
          $stderr.puts "Watchdocs: #{recordings.count} requests exported"
        end

        private

        def current_recordings
          store.read
        end

        def clear_recordings
          store.delete!
        end

        def export_recorings(recordings)
          Exporter.export(recordings)
        end

        def set_store(from_specs)
          @store = if from_specs
                     Rails::Buffer::MemoryBuffer
                   else
                     Rails::Buffer::FileBuffer
                   end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
watchdocs-rails-0.7.0 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.6.0 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.5.0 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.6 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.5 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.4 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.3 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.2 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.1 lib/watchdocs/rails/recordings.rb
watchdocs-rails-0.4.0 lib/watchdocs/rails/recordings.rb