Sha256: 5615900793d0120b9632e4939daaefa6e52022aa6db4df3be6c7b7117f8e8429

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 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 current_recordings
                     current_recordings << new_call
                    else
                     [new_call]
                    end
        end

        def current_recordings
          @current ||= store.read
        end

        def save_recordings
          store.write(output)
        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

7 entries across 7 versions & 1 rubygems

Version Path
watchdocs-rails-0.4.4 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.4.3 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.4.2 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.4.1 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.4.0 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.3.7 lib/watchdocs/rails/recordings/recorder.rb
watchdocs-rails-0.3.6 lib/watchdocs/rails/recordings/recorder.rb