Class: RbsRails::Util::FileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_rails/util/file_writer.rb,
sig/rbs_rails/util/file_writer.rbs

Overview

To avoid unnecessary type reloading by type checkers and other utilities, FileWriter modifies the target file only if its content has been changed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileWriter

Returns a new instance of FileWriter.

Parameters:

  • path (Pathname)


9
10
11
# File 'lib/rbs_rails/util/file_writer.rb', line 9

def initialize(path) #: void
  @path = path
end

Instance Attribute Details

#pathPathname (readonly)

: Pathname

Returns:

  • (Pathname)


6
7
8
# File 'lib/rbs_rails/util/file_writer.rb', line 6

def path
  @path
end

Instance Method Details

#write(content) ⇒ void

This method returns an undefined value.

: void

Parameters:

  • content (Object)


13
14
15
16
17
18
19
# File 'lib/rbs_rails/util/file_writer.rb', line 13

def write(content) #: void
  original_content = path.read rescue nil

  if original_content != content
    path.write(content)
  end
end