Sha256: 83d8cba37dd4fefd18f8567fefd5de2f66f77ee0f22faa24618fd7d93a70f71f

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

module Watchdocs
  module Rails
    module Store
      module JsonFileStore
        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
            Watchdocs::Rails.configuration.temp_directory
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
watchdocs-rails-0.2.0 lib/watchdocs/rails/store/file_store.rb
watchdocs-rails-0.1.4 lib/watchdocs/rails/store/file_store.rb
watchdocs-rails-0.1.3 lib/watchdocs/rails/store/file_store.rb
watchdocs-rails-0.1.2 lib/watchdocs/rails/store/file_store.rb
watchdocs-rails-0.1.1 lib/watchdocs/rails/store/file_store.rb
watchdocs-rails-0.1.0 lib/watchdocs/rails/store/file_store.rb