Class: RuboCop::Gradual::LockFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/gradual/lock_file.rb

Overview

LockFile class handles reading and writing of lock file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LockFile

Returns a new instance of LockFile.



13
14
15
# File 'lib/rubocop/gradual/lock_file.rb', line 13

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/rubocop/gradual/lock_file.rb', line 11

def path
  @path
end

Instance Method Details

#deleteObject



23
24
25
26
27
# File 'lib/rubocop/gradual/lock_file.rb', line 23

def delete
  return unless File.exist?(path)

  File.delete(path)
end

#diff(new_results) ⇒ Object



33
34
35
# File 'lib/rubocop/gradual/lock_file.rb', line 33

def diff(new_results)
  Diffy::Diff.new(Serializer.serialize(new_results), content, context: 0)
end

#read_resultsObject



17
18
19
20
21
# File 'lib/rubocop/gradual/lock_file.rb', line 17

def read_results
  return unless File.exist?(path)

  Serializer.deserialize(content)
end

#write_results(results) ⇒ Object



29
30
31
# File 'lib/rubocop/gradual/lock_file.rb', line 29

def write_results(results)
  File.write(path, Serializer.serialize(results), encoding: Encoding::UTF_8)
end