Module: RuboCop::Gradual::Serializer

Defined in:
lib/rubocop/gradual/serializer.rb

Overview

Serializer is a module used to serialize and deserialize RuboCop results to the lock file.

Class Method Summary collapse

Class Method Details

.deserialize(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubocop/gradual/serializer.rb', line 12

def deserialize(data)
  files = JSON.parse(data).map do |key, value|
    path, hash = key.split(":")
    raise Error, "Wrong format of the lock file: `#{key}` must include hash" if hash.nil? || hash.empty?

    issues = value.map do |line, column, length, message, issue_hash|
      { line: line, column: column, length: length, message: message, hash: issue_hash }
    end
    { path: path, hash: hash.to_i, issues: issues }
  end
  Results.new(files: files)
end

.serialize(results) ⇒ Object



8
9
10
# File 'lib/rubocop/gradual/serializer.rb', line 8

def serialize(results)
  "#{serialize_files(results.files)}\n"
end