Module: Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs
- Defined in:
- lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb,
lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/options.rb,
lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/base_translator.rb,
lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/line_matching_translator.rb,
lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/human_readable_translator.rb
Defined Under Namespace
Classes: BaseRBIFormat, BaseTranslator, HumanReadableRBIFormat, HumanReadableTranslator, LineMatchedRBIFormat, LineMatchingTranslator, Options
Class Method Summary
collapse
Class Method Details
.contains_rbs_syntax?(source) ⇒ Boolean
23
24
25
|
# File 'lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb', line 23
def contains_rbs_syntax?(source)
Sigils.contains_valid_sigil?(source) && source.match?(RBS_REWRITE_PATTERN)
end
|
.rewrite_if_needed(ruby_contents, file:, max_line_length: nil, overloads_strategy: :translate_all, erase_generic_types: false) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb', line 33
def rewrite_if_needed(
ruby_contents,
file:,
max_line_length: nil,
overloads_strategy: :translate_all,
erase_generic_types: false
)
return ruby_contents unless contains_rbs_syntax?(ruby_contents)
options = Options.new(
overloads_strategy:,
erase_generic_types:,
output_format: HumanReadableRBIFormat.new(
max_line_length:,
),
)
HumanReadableTranslator.new(ruby_contents, file:, options:).rewrite
end
|