Sha256: 4f42f4744a73bcad585d83e85d16eae7a14aef56e24224c64afe5e47a0f15f2d

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

module Watchdocs
  module Rails
    module Recordings
      class Recorder
        attr_reader :store, :output, :from_specs

        def initialize(from_specs: true)
          @from_specs = from_specs
          set_store
        end

        def call(new_call)
          record_new(new_call)
          save_recordings
          send_recordings if buffer_full?
        end

        private

        def record_new(new_call)
          @output = if recordings_any?
                     current_recordings << new_call
                    else
                     [new_call]
                    end
        end

        def current_recordings
          @current ||= store.read
        end

        def save_recordings
          store.write(output)
        end

        def recordings_any?
          store.exists?
        end

        def send_recordings
          Recordings.export(output, from_specs: from_specs)
        end

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

        def buffer_full?
          current_recordings.count > buffer_size
        end

        def buffer_size
          Rails.configuration.buffer_size
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
watchdocs-rails-0.11.2 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.11.1 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.11.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.10.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.9.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.8.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.7.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.6.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.5.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.4.6 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.4.5 lib/watchdocs/rails/recordings/recorder.rb