Sha256: fc7b79e150bd007a6d1787b99ded68900b6732a2a0d93b74af567d65b74bac88

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module Watchdocs
  module Rails
    module Buffer
      module FileBuffer
        class StorageError < StandardError; end

        class << self
          def write(content)
            File.write(path_to_file, content.to_json)
            path_to_file
          rescue StandardError => e
            raise StorageError, e
          end

          def read
            file = File.open(path_to_file, 'r')
            JSON.parse(file.read)
          rescue JSON::ParserError
            []
          rescue StandardError => e
            raise StorageError, e
          ensure
            file.close
          end

          def delete!
            File.delete(path_to_file)
          rescue StandardError => e
            raise StorageError, e
          end

          def exists?
            File.exist?(path_to_file)
          end

          private

          def path_to_file
            "#{temp_local_path}/reqests.json"
          end

          def temp_local_path
            Rails.configuration.temp_directory
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
watchdocs-rails-0.4.3 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.4.2 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.4.1 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.4.0 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.3.7 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.3.6 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.3.5 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.3.4 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.3.3 lib/watchdocs/rails/buffer/file_buffer.rb
watchdocs-rails-0.3.2 lib/watchdocs/rails/buffer/file_buffer.rb