class RBI::Rewriters::AddSigTemplates
Public Class Methods
new(with_todo_comment: true)
click to toggle source
Calls superclass method
# File lib/rbi/rewriters/add_sig_templates.rb, line 10 def initialize(with_todo_comment: true) super() @with_todo_comment = with_todo_comment end
Public Instance Methods
visit(node)
click to toggle source
# File lib/rbi/rewriters/add_sig_templates.rb, line 16 def visit(node) case node when Tree visit_all(node.nodes) when Attr add_attr_sig(node) when Method add_method_sig(node) end end
Private Instance Methods
add_attr_sig(attr)
click to toggle source
# File lib/rbi/rewriters/add_sig_templates.rb, line 30 def add_attr_sig(attr) return unless attr.sigs.empty? return if attr.names.size > 1 params = [] params << SigParam.new(attr.names.first.to_s, "T.untyped") if attr.is_a?(AttrWriter) attr.sigs << Sig.new( params: params, return_type: "T.untyped" ) add_todo_comment(attr) end
add_method_sig(method)
click to toggle source
# File lib/rbi/rewriters/add_sig_templates.rb, line 45 def add_method_sig(method) return unless method.sigs.empty? method.sigs << Sig.new( params: method.params.map { |param| SigParam.new(param.name, "T.untyped") }, return_type: "T.untyped" ) add_todo_comment(method) end
add_todo_comment(node)
click to toggle source
# File lib/rbi/rewriters/add_sig_templates.rb, line 56 def add_todo_comment(node) node.comments << Comment.new("TODO: fill in signature with appropriate type information") if @with_todo_comment end