Class: Orthoses::YARD::YARD2RBS
- Inherits:
-
Object
- Object
- Orthoses::YARD::YARD2RBS
- Defined in:
- lib/orthoses/yard/yard2rbs.rb
Instance Attribute Summary collapse
- #block ⇒ Proc readonly
- #bool ⇒ RBS::Types::Bases::Bool readonly
- #untyped ⇒ RBS::Types::Bases::Any readonly
- #void ⇒ RBS::Types::Bases::Void readonly
- #yardoc ⇒ YARD::CodeObjects::t readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(yardoc:, block:) ⇒ YARD2RBS
constructor
A new instance of YARD2RBS.
- #run ⇒ void
- #tag_types_to_rbs_type(tag_types) ⇒ RBS::Types::t
Constructor Details
#initialize(yardoc:, block:) ⇒ YARD2RBS
Returns a new instance of YARD2RBS.
25 26 27 28 29 30 31 32 33 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 25 def initialize(yardoc:, block:) @yardoc = yardoc @block = block # statics @untyped = ::RBS::Types::Bases::Any.new(location: nil) @void = ::RBS::Types::Bases::Void.new(location: nil) @bool = ::RBS::Types::Bases::Bool.new(location: nil) end |
Instance Attribute Details
#block ⇒ Proc (readonly)
14 15 16 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 14 def block @block end |
#bool ⇒ RBS::Types::Bases::Bool (readonly)
23 24 25 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 23 def bool @bool end |
#untyped ⇒ RBS::Types::Bases::Any (readonly)
17 18 19 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 17 def untyped @untyped end |
#void ⇒ RBS::Types::Bases::Void (readonly)
20 21 22 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 20 def void @void end |
#yardoc ⇒ YARD::CodeObjects::t (readonly)
11 12 13 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 11 def yardoc @yardoc end |
Class Method Details
.run(yardoc:, &block) ⇒ Object
5 6 7 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 5 def run(yardoc:, &block) new(yardoc: yardoc, block: block).run end |
Instance Method Details
#run ⇒ void
This method returns an undefined value.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 36 def run Orthoses.logger.info("YARD will generate about #{yardoc.inspect}") emit(yardoc.path, yardoc.docstring.all, nil, false) yardoc.children.each do |child| case child.type when :module, :class self.class.new(yardoc: child, block: block).run end end generate_for_attributes generate_for_methods generate_for_constants generate_for_classvariable end |
#tag_types_to_rbs_type(tag_types) ⇒ RBS::Types::t
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/orthoses/yard/yard2rbs.rb', line 52 def tag_types_to_rbs_type(tag_types) return untyped if tag_types.nil? tag_types = tag_types.compact.uniq return untyped if tag_types.empty? begin types_explainers = ::YARD::Tags::TypesExplainer::Parser.parse(tag_types.join(", ")) rescue SyntaxError => e Orthoses.logger.warn("#{tag_types} in #{yardoc.inspect} cannot parse as tags. use untyped instead") Orthoses.logger.warn(" => exception message=`#{e.}`") return untyped end Utils::TypeList.new(recursive_resolve(types_explainers)).inject.tap do |rbs| Orthoses.logger.debug("#{yardoc.inspect} tag #{tag_types} => #{rbs}") end end |