Class: RubyLsp::RbsRails::FileWriter
- Inherits:
-
Object
- Object
- RubyLsp::RbsRails::FileWriter
- Defined in:
- lib/ruby_lsp/rbs_rails/file_writer.rb
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
-
#path ⇒ Object
readonly
: Pathname.
Instance Method Summary collapse
-
#initialize(path) ⇒ FileWriter
constructor
A new instance of FileWriter.
-
#write(content) ⇒ Object
: void.
Constructor Details
#initialize(path) ⇒ FileWriter
Returns a new instance of FileWriter.
13 14 15 |
# File 'lib/ruby_lsp/rbs_rails/file_writer.rb', line 13 def initialize(path) #: void @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
: Pathname
10 11 12 |
# File 'lib/ruby_lsp/rbs_rails/file_writer.rb', line 10 def path @path end |
Instance Method Details
#write(content) ⇒ Object
: void
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_lsp/rbs_rails/file_writer.rb', line 17 def write(content) #: void original_content = begin path.read rescue StandardError nil end return unless original_content != content path.write(content) end |