Sha256: 5f2fd183cd3173882389c6cf257b0d7d9e447365297532d756880a0e7008fc1b

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module YARDSorbet
  module Handlers
    # Handle `enums` calls, registering enum values as constants
    class EnumsHandler < YARD::Handlers::Ruby::Base
      extend T::Sig

      handles method_call(:enums)
      namespace_only

      sig { void }
      def process
        statement.traverse do |node|
          if const_assign_node?(node)
            register YARD::CodeObjects::ConstantObject.new(namespace, node.first.source) do |obj|
              obj.docstring = node.docstring
              obj.source = node
              obj.value = node.last.source
            end
          end
        end
      end

      private

      sig { params(node: YARD::Parser::Ruby::AstNode).returns(T::Boolean) }
      def const_assign_node?(node) = node.type == :assign && node[0][0].type == :const
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yard-sorbet-0.9.0 lib/yard-sorbet/handlers/enums_handler.rb