Class: RBS::Trace::File
- Inherits:
-
Object
- Object
- RBS::Trace::File
- Defined in:
- lib/rbs/trace/file.rb
Instance Method Summary collapse
- #definitions ⇒ Object
-
#initialize(path) ⇒ File
constructor
A new instance of File.
- #rewrite ⇒ Object
- #with_rbs ⇒ Object
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
7 8 9 |
# File 'lib/rbs/trace/file.rb', line 7 def initialize(path) @path = path end |
Instance Method Details
#definitions ⇒ Object
12 13 14 |
# File 'lib/rbs/trace/file.rb', line 12 def definitions @definitions ||= {} end |
#rewrite ⇒ Object
32 33 34 |
# File 'lib/rbs/trace/file.rb', line 32 def rewrite ::File.write(@path, with_rbs) end |
#with_rbs ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbs/trace/file.rb', line 17 def with_rbs lines = ::File.readlines(@path) reverse_definitions.each do |d| next if skip_insert?(lines, d) current = d.lineno - 1 indent = lines[current]&.index("def") next unless indent lines.insert(current, d.rbs_comment(indent)) end lines.join end |