class YARDSorbet::Handlers::StructPropHandler
Handles all `const`/`prop` calls, creating accessor methods, and compiles them for later usage at the class level in creating a constructor
Public Instance Methods
process()
click to toggle source
# File lib/yard-sorbet/handlers/struct_prop_handler.rb, line 15 def process name = statement.parameters.first.last.last.source prop = make_prop(name) update_state(prop) object = YARD::CodeObjects::MethodObject.new(namespace, name, scope) decorate_object(object, prop) register_attrs(object, name) end
Private Instance Methods
decorate_object(object, prop)
click to toggle source
# File lib/yard-sorbet/handlers/struct_prop_handler.rb, line 28 def decorate_object(object, prop) object.source = prop.source # TODO: this should use `+` to delimit the attribute name when markdown is disabled reader_docstring = prop.doc.empty? ? "Returns the value of attribute `#{prop.prop_name}`." : prop.doc docstring = YARD::DocstringParser.new.parse(reader_docstring).to_docstring docstring.add_tag(YARD::Tags::Tag.new(:return, '', prop.types)) object.docstring = docstring.to_raw end
default_value()
click to toggle source
# File lib/yard-sorbet/handlers/struct_prop_handler.rb, line 39 def default_value default_node = statement.traverse { |n| break n if n.type == :label && n.source == 'default:' } default_node.parent[1].source if default_node end
make_prop(name)
click to toggle source
# File lib/yard-sorbet/handlers/struct_prop_handler.rb, line 45 def make_prop(name) TStructProp.new( default: default_value, doc: statement.docstring.to_s, prop_name: name, source: statement.source, types: SigToYARD.convert(statement.parameters[1]) ) end
register_attrs(object, name)
click to toggle source
# File lib/yard-sorbet/handlers/struct_prop_handler.rb, line 58 def register_attrs(object, name) # Create the virtual method in our current scope write = statement.method_name(true) == :prop ? object : nil namespace.attributes[scope][name] ||= SymbolHash[read: object, write: write] end
update_state(prop)
click to toggle source
# File lib/yard-sorbet/handlers/struct_prop_handler.rb, line 66 def update_state(prop) extra_state.prop_docs ||= Hash.new { |h, k| h[k] = [] } extra_state.prop_docs[namespace] << prop end