Class: Spoom::Cli::Srb::Assertions

Inherits:
Thor
  • Object
show all
Includes:
Helper
Defined in:
lib/spoom/cli/srb/assertions.rb

Constant Summary

Constants included from Helper

Helper::HIGHLIGHT_COLOR

Instance Method Summary collapse

Methods included from Helper

#blue, #collect_files, #color?, #colorize, #context, #context_requiring_sorbet!, #cyan, #exec_path, #gray, #green, #highlight, #red, #say, #say_error, #say_warning, #yellow

Methods included from Spoom::Colorize

#set_color

Instance Method Details

#translate(*paths) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/spoom/cli/srb/assertions.rb', line 18

def translate(*paths)
  from = options[:from]
  to = options[:to]
  files = collect_files(paths)

  say("Translating type assertions from `#{from}` to `#{to}` " \
    "in `#{files.size}` file#{files.size == 1 ? "" : "s"}...\n\n")

  transformed_files = transform_files(files) do |file, contents|
    Spoom::Sorbet::Translate.sorbet_assertions_to_rbs_comments(
      contents,
      file: file,
      translate_t_let: options[:translate_t_let],
      translate_t_cast: options[:translate_t_cast],
      translate_t_bind: options[:translate_t_bind],
      translate_t_must: options[:translate_t_must],
      translate_t_unsafe: options[:translate_t_unsafe],
    )
  end

  say("Translated type assertions in `#{transformed_files}` file#{transformed_files == 1 ? "" : "s"}.")
end