Class: RbsRails::Util::FileWriter
- Inherits:
-
Object
- Object
- RbsRails::Util::FileWriter
- 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
-
#path ⇒ Pathname
readonly
: Pathname.
Instance Method Summary collapse
-
#initialize(path) ⇒ FileWriter
constructor
A new instance of FileWriter.
-
#write(content) ⇒ void
: void.
Constructor Details
#initialize(path) ⇒ FileWriter
Returns a new instance of FileWriter.
9 10 11 |
# File 'lib/rbs_rails/util/file_writer.rb', line 9 def initialize(path) #: void @path = path end |
Instance Attribute Details
#path ⇒ Pathname (readonly)
: 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
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 |