Class: SorbetView::FileSystem::OutputManager
- Inherits:
-
Object
- Object
- SorbetView::FileSystem::OutputManager
- Extended by:
- T::Sig
- Defined in:
- lib/sorbet_view/file_system/output_manager.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #delete(template_path) ⇒ Object
-
#initialize(output_dir) ⇒ OutputManager
constructor
A new instance of OutputManager.
- #write(result) ⇒ Object
Constructor Details
#initialize(output_dir) ⇒ OutputManager
Returns a new instance of OutputManager.
13 14 15 |
# File 'lib/sorbet_view/file_system/output_manager.rb', line 13 def initialize(output_dir) @output_dir = output_dir end |
Instance Method Details
#clean ⇒ Object
42 43 44 |
# File 'lib/sorbet_view/file_system/output_manager.rb', line 42 def clean FileUtils.rm_rf(@output_dir) end |
#delete(template_path) ⇒ Object
36 37 38 39 |
# File 'lib/sorbet_view/file_system/output_manager.rb', line 36 def delete(template_path) ruby_path = File.join(@output_dir, "#{template_path}.rb") File.delete(ruby_path) if File.exist?(ruby_path) end |
#write(result) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sorbet_view/file_system/output_manager.rb', line 18 def write(result) Perf.measure('output.write') do path = result.source_map.ruby_path dir = File.dirname(path) FileUtils.mkdir_p(dir) # Only write if content changed (avoid unnecessary Watchman triggers) if File.exist?(path) existing = File.read(path) next if existing == result.ruby_source end File.write(path, result.ruby_source) end end |